blob: 736b75b1aca24102bcaf03234c36e9fc1edd7681 [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>
Colin Crossed8a7d82010-04-19 17:05:34 -070021
Colin Cross6310a822010-04-20 14:29:05 -070022#include <sys/stat.h>
23
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080024void handle_control_message(const char *msg, const char *arg);
25
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080026struct command
27{
28 /* list of commands in an action */
29 struct listnode clist;
30
31 int (*func)(int nargs, char **args);
32 int nargs;
33 char *args[1];
34};
35
36struct action {
37 /* node in list of all actions */
38 struct listnode alist;
39 /* node in the queue of pending actions */
40 struct listnode qlist;
41 /* node in list of actions for a trigger */
42 struct listnode tlist;
43
44 unsigned hash;
45 const char *name;
46
47 struct listnode commands;
48 struct command *current;
49};
50
51struct socketinfo {
52 struct socketinfo *next;
53 const char *name;
54 const char *type;
55 uid_t uid;
56 gid_t gid;
57 int perm;
Stephen Smalley8348d272013-05-13 12:37:04 -040058 const char *socketcon;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080059};
60
61struct svcenvinfo {
62 struct svcenvinfo *next;
63 const char *name;
64 const char *value;
65};
66
67#define SVC_DISABLED 0x01 /* do not autostart with class */
68#define SVC_ONESHOT 0x02 /* do not restart on exit */
69#define SVC_RUNNING 0x04 /* currently active */
70#define SVC_RESTARTING 0x08 /* waiting to restart */
71#define SVC_CONSOLE 0x10 /* requires console */
72#define SVC_CRITICAL 0x20 /* will reboot into recovery if keeps crashing */
Ken Sumrall752923c2010-12-03 16:33:31 -080073#define SVC_RESET 0x40 /* Use when stopping a process, but not disabling
74 so it can be restarted with its class */
Ken Sumralla2864802011-10-26 16:56:00 -070075#define SVC_RC_DISABLED 0x80 /* Remember if the disabled flag was set in the rc script */
Mike Kasickb54f39f2012-01-25 23:48:46 -050076#define SVC_RESTART 0x100 /* Use to safely restart (stop, wait, start) a service */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080077
Nick Pelly830abe02010-03-23 20:37:40 -070078#define NR_SVC_SUPP_GIDS 12 /* twelve supplementary groups */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080079
Colin Crossebc6ff12010-04-13 19:52:01 -070080#define COMMAND_RETRY_TIMEOUT 5
81
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080082struct service {
83 /* list of all services */
84 struct listnode slist;
85
86 const char *name;
87 const char *classname;
88
89 unsigned flags;
90 pid_t pid;
91 time_t time_started; /* time of last start */
92 time_t time_crashed; /* first crash within inspection window */
93 int nr_crashed; /* number of times crashed within window */
94
95 uid_t uid;
96 gid_t gid;
97 gid_t supp_gids[NR_SVC_SUPP_GIDS];
98 size_t nr_supp_gids;
99
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500100 char *seclabel;
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500101
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800102 struct socketinfo *sockets;
103 struct svcenvinfo *envvars;
104
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800105 struct action onrestart; /* Actions to execute on restart. */
106
107 /* keycodes for triggering this service via /dev/keychord */
108 int *keycodes;
109 int nkeycodes;
110 int keychord_id;
San Mehatc83cd872009-05-14 14:54:22 -0700111
San Mehat4e221f02010-02-25 14:19:50 -0800112 int ioprio_class;
113 int ioprio_pri;
114
San Mehatc83cd872009-05-14 14:54:22 -0700115 int nargs;
116 /* "MUST BE AT THE END OF THE STRUCT" */
117 char *args[1];
118}; /* ^-------'args' MUST be at the end of this struct! */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800119
Colin Cross9c5366b2010-04-13 19:48:59 -0700120void notify_service_state(const char *name, const char *state);
121
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800122struct service *service_find_by_name(const char *name);
123struct service *service_find_by_pid(pid_t pid);
124struct service *service_find_by_keychord(int keychord_id);
125void service_for_each(void (*func)(struct service *svc));
126void service_for_each_class(const char *classname,
127 void (*func)(struct service *svc));
128void service_for_each_flags(unsigned matchflags,
129 void (*func)(struct service *svc));
130void service_stop(struct service *svc);
Ken Sumrall752923c2010-12-03 16:33:31 -0800131void service_reset(struct service *svc);
Mike Kasickb54f39f2012-01-25 23:48:46 -0500132void service_restart(struct service *svc);
San Mehatf24e2522009-05-19 13:30:46 -0700133void service_start(struct service *svc, const char *dynamic_args);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800134void property_changed(const char *name, const char *value);
135
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500136extern struct selabel_handle *sehandle;
rpcraig63207cd2012-08-09 10:05:49 -0400137extern struct selabel_handle *sehandle_prop;
Stephen Smalleyae6f3d72012-05-01 15:02:53 -0400138extern int selinux_reload_policy(void);
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500139
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800140#endif /* _INIT_INIT_H */