blob: c1669694b50eaaad1077f022c0538047db8f63e6 [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
Elliott Hughes8d82ea02015-02-06 20:15:18 -080020#include <sys/types.h>
21
Elliott Hughese79d0d52015-06-12 18:02:20 -070022#include <string>
23#include <vector>
24
Dima Zavinda04c522011-09-01 17:09:44 -070025#include <cutils/list.h>
Elliott Hughesf3cf4382015-02-03 17:12:07 -080026#include <cutils/iosched_policy.h>
Colin Crossed8a7d82010-04-19 17:05:34 -070027
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080028struct command
29{
30 /* list of commands in an action */
31 struct listnode clist;
32
33 int (*func)(int nargs, char **args);
Riley Andrews24a3b782014-06-26 13:56:01 -070034
35 int line;
36 const char *filename;
37
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080038 int nargs;
39 char *args[1];
40};
Riley Andrews24a3b782014-06-26 13:56:01 -070041
Badhri Jagan Sridharan0b415122014-10-10 23:19:06 -070042struct trigger {
43 struct listnode nlist;
44 const char *name;
45};
46
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080047struct action {
48 /* node in list of all actions */
49 struct listnode alist;
50 /* node in the queue of pending actions */
51 struct listnode qlist;
52 /* node in list of actions for a trigger */
53 struct listnode tlist;
54
55 unsigned hash;
Riley Andrews24a3b782014-06-26 13:56:01 -070056
Badhri Jagan Sridharan0b415122014-10-10 23:19:06 -070057 /* list of actions which triggers the commands*/
58 struct listnode triggers;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080059 struct listnode commands;
60 struct command *current;
61};
62
63struct socketinfo {
64 struct socketinfo *next;
65 const char *name;
66 const char *type;
67 uid_t uid;
68 gid_t gid;
69 int perm;
Stephen Smalley8348d272013-05-13 12:37:04 -040070 const char *socketcon;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080071};
72
73struct svcenvinfo {
74 struct svcenvinfo *next;
75 const char *name;
76 const char *value;
77};
78
Elliott Hughes8d82ea02015-02-06 20:15:18 -080079#define SVC_DISABLED 0x001 // do not autostart with class
80#define SVC_ONESHOT 0x002 // do not restart on exit
81#define SVC_RUNNING 0x004 // currently active
82#define SVC_RESTARTING 0x008 // waiting to restart
83#define SVC_CONSOLE 0x010 // requires console
84#define SVC_CRITICAL 0x020 // will reboot into recovery if keeps crashing
85#define SVC_RESET 0x040 // Use when stopping a process, but not disabling so it can be restarted with its class.
86#define SVC_RC_DISABLED 0x080 // Remember if the disabled flag was set in the rc script.
87#define SVC_RESTART 0x100 // Use to safely restart (stop, wait, start) a service.
88#define SVC_DISABLED_START 0x200 // A start was requested but it was disabled at the time.
89#define SVC_EXEC 0x400 // This synthetic service corresponds to an 'exec'.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080090
Nick Pelly830abe02010-03-23 20:37:40 -070091#define NR_SVC_SUPP_GIDS 12 /* twelve supplementary groups */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080092
Colin Crossebc6ff12010-04-13 19:52:01 -070093#define COMMAND_RETRY_TIMEOUT 5
94
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080095struct service {
Elliott Hughes8d82ea02015-02-06 20:15:18 -080096 void NotifyStateChange(const char* new_state);
97
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080098 /* list of all services */
99 struct listnode slist;
100
Elliott Hughes8d82ea02015-02-06 20:15:18 -0800101 char *name;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800102 const char *classname;
103
104 unsigned flags;
105 pid_t pid;
106 time_t time_started; /* time of last start */
107 time_t time_crashed; /* first crash within inspection window */
108 int nr_crashed; /* number of times crashed within window */
Elliott Hughes8d82ea02015-02-06 20:15:18 -0800109
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800110 uid_t uid;
111 gid_t gid;
112 gid_t supp_gids[NR_SVC_SUPP_GIDS];
113 size_t nr_supp_gids;
114
Elliott Hughes8d82ea02015-02-06 20:15:18 -0800115 const char* seclabel;
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500116
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800117 struct socketinfo *sockets;
118 struct svcenvinfo *envvars;
119
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800120 struct action onrestart; /* Actions to execute on restart. */
Elliott Hughes8d82ea02015-02-06 20:15:18 -0800121
Elliott Hughese79d0d52015-06-12 18:02:20 -0700122 std::vector<std::string>* writepid_files_;
123
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800124 /* keycodes for triggering this service via /dev/keychord */
125 int *keycodes;
126 int nkeycodes;
127 int keychord_id;
San Mehatc83cd872009-05-14 14:54:22 -0700128
Elliott Hughesf3cf4382015-02-03 17:12:07 -0800129 IoSchedClass ioprio_class;
San Mehat4e221f02010-02-25 14:19:50 -0800130 int ioprio_pri;
131
San Mehatc83cd872009-05-14 14:54:22 -0700132 int nargs;
133 /* "MUST BE AT THE END OF THE STRUCT" */
134 char *args[1];
135}; /* ^-------'args' MUST be at the end of this struct! */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800136
Elliott Hughes8d82ea02015-02-06 20:15:18 -0800137extern bool waiting_for_exec;
138extern struct selabel_handle *sehandle;
139extern struct selabel_handle *sehandle_prop;
140
141void build_triggers_string(char *name_str, int length, struct action *cur_action);
142
143void handle_control_message(const char *msg, const char *arg);
Colin Cross9c5366b2010-04-13 19:48:59 -0700144
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800145struct service *service_find_by_name(const char *name);
146struct service *service_find_by_pid(pid_t pid);
147struct service *service_find_by_keychord(int keychord_id);
148void service_for_each(void (*func)(struct service *svc));
149void service_for_each_class(const char *classname,
150 void (*func)(struct service *svc));
151void service_for_each_flags(unsigned matchflags,
152 void (*func)(struct service *svc));
153void service_stop(struct service *svc);
Ken Sumrall752923c2010-12-03 16:33:31 -0800154void service_reset(struct service *svc);
Mike Kasickb54f39f2012-01-25 23:48:46 -0500155void service_restart(struct service *svc);
San Mehatf24e2522009-05-19 13:30:46 -0700156void service_start(struct service *svc, const char *dynamic_args);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800157void property_changed(const char *name, const char *value);
158
Elliott Hughes8d82ea02015-02-06 20:15:18 -0800159int selinux_reload_policy(void);
160
San Mehat429721c2014-09-23 07:48:47 -0700161void zap_stdio(void);
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500162
Elliott Hughes929f4072015-04-24 21:13:44 -0700163void register_epoll_handler(int fd, void (*fn)());
164
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800165#endif /* _INIT_INIT_H */