blob: 4d231030f254fc20c0bd3715e795dd835eefa1be [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>
Tom Cherryfa0c21c2015-07-23 17:53:11 -070021#include <stdlib.h>
Elliott Hughes8d82ea02015-02-06 20:15:18 -080022
Tom Cherryfa0c21c2015-07-23 17:53:11 -070023#include <list>
24#include <map>
Elliott Hughesd62f0602015-06-12 18:02:20 -070025#include <string>
26#include <vector>
27
Dima Zavinda04c522011-09-01 17:09:44 -070028#include <cutils/list.h>
Elliott Hughesf3cf4382015-02-03 17:12:07 -080029#include <cutils/iosched_policy.h>
Colin Crossed8a7d82010-04-19 17:05:34 -070030
Tom Cherryfa0c21c2015-07-23 17:53:11 -070031class Action;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080032
33struct socketinfo {
34 struct socketinfo *next;
35 const char *name;
36 const char *type;
37 uid_t uid;
38 gid_t gid;
39 int perm;
Stephen Smalley8348d272013-05-13 12:37:04 -040040 const char *socketcon;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080041};
42
43struct svcenvinfo {
44 struct svcenvinfo *next;
45 const char *name;
46 const char *value;
47};
48
Elliott Hughes8d82ea02015-02-06 20:15:18 -080049#define SVC_DISABLED 0x001 // do not autostart with class
50#define SVC_ONESHOT 0x002 // do not restart on exit
51#define SVC_RUNNING 0x004 // currently active
52#define SVC_RESTARTING 0x008 // waiting to restart
53#define SVC_CONSOLE 0x010 // requires console
54#define SVC_CRITICAL 0x020 // will reboot into recovery if keeps crashing
55#define SVC_RESET 0x040 // Use when stopping a process, but not disabling so it can be restarted with its class.
56#define SVC_RC_DISABLED 0x080 // Remember if the disabled flag was set in the rc script.
57#define SVC_RESTART 0x100 // Use to safely restart (stop, wait, start) a service.
58#define SVC_DISABLED_START 0x200 // A start was requested but it was disabled at the time.
59#define SVC_EXEC 0x400 // This synthetic service corresponds to an 'exec'.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080060
Nick Pelly830abe02010-03-23 20:37:40 -070061#define NR_SVC_SUPP_GIDS 12 /* twelve supplementary groups */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080062
Colin Crossebc6ff12010-04-13 19:52:01 -070063#define COMMAND_RETRY_TIMEOUT 5
64
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080065struct service {
Elliott Hughes8d82ea02015-02-06 20:15:18 -080066 void NotifyStateChange(const char* new_state);
67
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080068 /* list of all services */
69 struct listnode slist;
70
Elliott Hughes8d82ea02015-02-06 20:15:18 -080071 char *name;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080072 const char *classname;
73
74 unsigned flags;
75 pid_t pid;
76 time_t time_started; /* time of last start */
77 time_t time_crashed; /* first crash within inspection window */
78 int nr_crashed; /* number of times crashed within window */
Elliott Hughes8d82ea02015-02-06 20:15:18 -080079
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080080 uid_t uid;
81 gid_t gid;
82 gid_t supp_gids[NR_SVC_SUPP_GIDS];
83 size_t nr_supp_gids;
84
Elliott Hughes8d82ea02015-02-06 20:15:18 -080085 const char* seclabel;
Stephen Smalleye46f9d52012-01-13 08:48:47 -050086
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080087 struct socketinfo *sockets;
88 struct svcenvinfo *envvars;
89
Tom Cherryfa0c21c2015-07-23 17:53:11 -070090 Action* onrestart; /* Commands to execute on restart. */
Elliott Hughes8d82ea02015-02-06 20:15:18 -080091
Elliott Hughesd62f0602015-06-12 18:02:20 -070092 std::vector<std::string>* writepid_files_;
93
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080094 /* keycodes for triggering this service via /dev/keychord */
95 int *keycodes;
96 int nkeycodes;
97 int keychord_id;
San Mehatc83cd872009-05-14 14:54:22 -070098
Elliott Hughesf3cf4382015-02-03 17:12:07 -080099 IoSchedClass ioprio_class;
San Mehat4e221f02010-02-25 14:19:50 -0800100 int ioprio_pri;
101
San Mehatc83cd872009-05-14 14:54:22 -0700102 int nargs;
103 /* "MUST BE AT THE END OF THE STRUCT" */
104 char *args[1];
105}; /* ^-------'args' MUST be at the end of this struct! */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800106
Elliott Hughes8d82ea02015-02-06 20:15:18 -0800107extern bool waiting_for_exec;
108extern struct selabel_handle *sehandle;
109extern struct selabel_handle *sehandle_prop;
110
Elliott Hughes8d82ea02015-02-06 20:15:18 -0800111void handle_control_message(const char *msg, const char *arg);
Colin Cross9c5366b2010-04-13 19:48:59 -0700112
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800113struct service *service_find_by_name(const char *name);
114struct service *service_find_by_pid(pid_t pid);
115struct service *service_find_by_keychord(int keychord_id);
116void service_for_each(void (*func)(struct service *svc));
117void service_for_each_class(const char *classname,
118 void (*func)(struct service *svc));
119void service_for_each_flags(unsigned matchflags,
120 void (*func)(struct service *svc));
121void service_stop(struct service *svc);
Ken Sumrall752923c2010-12-03 16:33:31 -0800122void service_reset(struct service *svc);
Mike Kasickb54f39f2012-01-25 23:48:46 -0500123void service_restart(struct service *svc);
San Mehatf24e2522009-05-19 13:30:46 -0700124void service_start(struct service *svc, const char *dynamic_args);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800125void property_changed(const char *name, const char *value);
126
Elliott Hughes8d82ea02015-02-06 20:15:18 -0800127int selinux_reload_policy(void);
128
San Mehat429721c2014-09-23 07:48:47 -0700129void zap_stdio(void);
Stephen Smalleye46f9d52012-01-13 08:48:47 -0500130
Elliott Hughes929f4072015-04-24 21:13:44 -0700131void register_epoll_handler(int fd, void (*fn)());
132
Tom Cherryfa0c21c2015-07-23 17:53:11 -0700133#endif /* _INIT_INIT_H */