blob: eedec276f5a4163c8a4c7d44d0006b3b29784a2c [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _INIT_INIT_H
18#define _INIT_INIT_H
19
Dima Zavinda04c522011-09-01 17:09:44 -070020#include <cutils/list.h>
Elliott Hughesf3cf4382015-02-03 17:12:07 -080021#include <cutils/iosched_policy.h>
Colin Crossed8a7d82010-04-19 17:05:34 -070022
Colin Cross6310a822010-04-20 14:29:05 -070023#include <sys/stat.h>
24
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080025void handle_control_message(const char *msg, const char *arg);
26
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080027struct command
28{
29 /* list of commands in an action */
30 struct listnode clist;
31
32 int (*func)(int nargs, char **args);
Riley Andrews24a3b782014-06-26 13:56:01 -070033
34 int line;
35 const char *filename;
36
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080037 int nargs;
38 char *args[1];
39};
Riley Andrews24a3b782014-06-26 13:56:01 -070040
Badhri Jagan Sridharan0b415122014-10-10 23:19:06 -070041struct trigger {
42 struct listnode nlist;
43 const char *name;
44};
45
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080046struct action {
47 /* node in list of all actions */
48 struct listnode alist;
49 /* node in the queue of pending actions */
50 struct listnode qlist;
51 /* node in list of actions for a trigger */
52 struct listnode tlist;
53
54 unsigned hash;
Riley Andrews24a3b782014-06-26 13:56:01 -070055
Badhri Jagan Sridharan0b415122014-10-10 23:19:06 -070056 /* list of actions which triggers the commands*/
57 struct listnode triggers;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080058 struct listnode commands;
59 struct command *current;
60};
61
Badhri Jagan Sridharan0b415122014-10-10 23:19:06 -070062void build_triggers_string(char *name_str, int length, struct action *cur_action);
63
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080064struct socketinfo {
65 struct socketinfo *next;
66 const char *name;
67 const char *type;
68 uid_t uid;
69 gid_t gid;
70 int perm;
Stephen Smalley8348d272013-05-13 12:37:04 -040071 const char *socketcon;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080072};
73
74struct svcenvinfo {
75 struct svcenvinfo *next;
76 const char *name;
77 const char *value;
78};
79
80#define SVC_DISABLED 0x01 /* do not autostart with class */
81#define SVC_ONESHOT 0x02 /* do not restart on exit */
82#define SVC_RUNNING 0x04 /* currently active */
83#define SVC_RESTARTING 0x08 /* waiting to restart */
84#define SVC_CONSOLE 0x10 /* requires console */
85#define SVC_CRITICAL 0x20 /* will reboot into recovery if keeps crashing */
Ken Sumrall752923c2010-12-03 16:33:31 -080086#define SVC_RESET 0x40 /* Use when stopping a process, but not disabling
87 so it can be restarted with its class */
Ken Sumralla2864802011-10-26 16:56:00 -070088#define SVC_RC_DISABLED 0x80 /* Remember if the disabled flag was set in the rc script */
Mike Kasickb54f39f2012-01-25 23:48:46 -050089#define SVC_RESTART 0x100 /* Use to safely restart (stop, wait, start) a service */
JP Abgrall3beec7e2014-05-02 21:14:29 -070090#define SVC_DISABLED_START 0x200 /* a start was requested but it was disabled at the time */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080091
Nick Pelly830abe02010-03-23 20:37:40 -070092#define NR_SVC_SUPP_GIDS 12 /* twelve supplementary groups */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080093
Colin Crossebc6ff12010-04-13 19:52:01 -070094#define COMMAND_RETRY_TIMEOUT 5
95
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080096struct service {
97 /* list of all services */
98 struct listnode slist;
99
100 const char *name;
101 const char *classname;
102
103 unsigned flags;
104 pid_t pid;
105 time_t time_started; /* time of last start */
106 time_t time_crashed; /* first crash within inspection window */
107 int nr_crashed; /* number of times crashed within window */
108
109 uid_t uid;
110 gid_t gid;
111 gid_t supp_gids[NR_SVC_SUPP_GIDS];
112 size_t nr_supp_gids;
113
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500114 char *seclabel;
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500115
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800116 struct socketinfo *sockets;
117 struct svcenvinfo *envvars;
118
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800119 struct action onrestart; /* Actions to execute on restart. */
120
121 /* keycodes for triggering this service via /dev/keychord */
122 int *keycodes;
123 int nkeycodes;
124 int keychord_id;
San Mehatc83cd872009-05-14 14:54:22 -0700125
Elliott Hughesf3cf4382015-02-03 17:12:07 -0800126 IoSchedClass ioprio_class;
San Mehat4e221f02010-02-25 14:19:50 -0800127 int ioprio_pri;
128
San Mehatc83cd872009-05-14 14:54:22 -0700129 int nargs;
130 /* "MUST BE AT THE END OF THE STRUCT" */
131 char *args[1];
132}; /* ^-------'args' MUST be at the end of this struct! */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800133
Colin Cross9c5366b2010-04-13 19:48:59 -0700134void notify_service_state(const char *name, const char *state);
135
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800136struct service *service_find_by_name(const char *name);
137struct service *service_find_by_pid(pid_t pid);
138struct service *service_find_by_keychord(int keychord_id);
139void service_for_each(void (*func)(struct service *svc));
140void service_for_each_class(const char *classname,
141 void (*func)(struct service *svc));
142void service_for_each_flags(unsigned matchflags,
143 void (*func)(struct service *svc));
144void service_stop(struct service *svc);
Ken Sumrall752923c2010-12-03 16:33:31 -0800145void service_reset(struct service *svc);
Mike Kasickb54f39f2012-01-25 23:48:46 -0500146void service_restart(struct service *svc);
San Mehatf24e2522009-05-19 13:30:46 -0700147void service_start(struct service *svc, const char *dynamic_args);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800148void property_changed(const char *name, const char *value);
149
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500150extern struct selabel_handle *sehandle;
rpcraig63207cd2012-08-09 10:05:49 -0400151extern struct selabel_handle *sehandle_prop;
Stephen Smalleyae6f3d72012-05-01 15:02:53 -0400152extern int selinux_reload_policy(void);
San Mehat429721c2014-09-23 07:48:47 -0700153void zap_stdio(void);
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500154
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800155#endif /* _INIT_INIT_H */