The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* |
| 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 Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 20 | #include <sys/types.h> |
Tom Cherry | fa0c21c | 2015-07-23 17:53:11 -0700 | [diff] [blame^] | 21 | #include <stdlib.h> |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 22 | |
Tom Cherry | fa0c21c | 2015-07-23 17:53:11 -0700 | [diff] [blame^] | 23 | #include <list> |
| 24 | #include <map> |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 25 | #include <string> |
| 26 | #include <vector> |
| 27 | |
Dima Zavin | da04c52 | 2011-09-01 17:09:44 -0700 | [diff] [blame] | 28 | #include <cutils/list.h> |
Elliott Hughes | f3cf438 | 2015-02-03 17:12:07 -0800 | [diff] [blame] | 29 | #include <cutils/iosched_policy.h> |
Colin Cross | ed8a7d8 | 2010-04-19 17:05:34 -0700 | [diff] [blame] | 30 | |
Tom Cherry | fa0c21c | 2015-07-23 17:53:11 -0700 | [diff] [blame^] | 31 | class Action; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 32 | |
| 33 | struct 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 Smalley | 8348d27 | 2013-05-13 12:37:04 -0400 | [diff] [blame] | 40 | const char *socketcon; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | struct svcenvinfo { |
| 44 | struct svcenvinfo *next; |
| 45 | const char *name; |
| 46 | const char *value; |
| 47 | }; |
| 48 | |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 49 | #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 Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 60 | |
Nick Pelly | 830abe0 | 2010-03-23 20:37:40 -0700 | [diff] [blame] | 61 | #define NR_SVC_SUPP_GIDS 12 /* twelve supplementary groups */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 62 | |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 63 | #define COMMAND_RETRY_TIMEOUT 5 |
| 64 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 65 | struct service { |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 66 | void NotifyStateChange(const char* new_state); |
| 67 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 68 | /* list of all services */ |
| 69 | struct listnode slist; |
| 70 | |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 71 | char *name; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 72 | 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 Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 79 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 80 | uid_t uid; |
| 81 | gid_t gid; |
| 82 | gid_t supp_gids[NR_SVC_SUPP_GIDS]; |
| 83 | size_t nr_supp_gids; |
| 84 | |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 85 | const char* seclabel; |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 86 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 87 | struct socketinfo *sockets; |
| 88 | struct svcenvinfo *envvars; |
| 89 | |
Tom Cherry | fa0c21c | 2015-07-23 17:53:11 -0700 | [diff] [blame^] | 90 | Action* onrestart; /* Commands to execute on restart. */ |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 91 | |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 92 | std::vector<std::string>* writepid_files_; |
| 93 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 94 | /* keycodes for triggering this service via /dev/keychord */ |
| 95 | int *keycodes; |
| 96 | int nkeycodes; |
| 97 | int keychord_id; |
San Mehat | c83cd87 | 2009-05-14 14:54:22 -0700 | [diff] [blame] | 98 | |
Elliott Hughes | f3cf438 | 2015-02-03 17:12:07 -0800 | [diff] [blame] | 99 | IoSchedClass ioprio_class; |
San Mehat | 4e221f0 | 2010-02-25 14:19:50 -0800 | [diff] [blame] | 100 | int ioprio_pri; |
| 101 | |
San Mehat | c83cd87 | 2009-05-14 14:54:22 -0700 | [diff] [blame] | 102 | 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 Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 106 | |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 107 | extern bool waiting_for_exec; |
| 108 | extern struct selabel_handle *sehandle; |
| 109 | extern struct selabel_handle *sehandle_prop; |
| 110 | |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 111 | void handle_control_message(const char *msg, const char *arg); |
Colin Cross | 9c5366b | 2010-04-13 19:48:59 -0700 | [diff] [blame] | 112 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 113 | struct service *service_find_by_name(const char *name); |
| 114 | struct service *service_find_by_pid(pid_t pid); |
| 115 | struct service *service_find_by_keychord(int keychord_id); |
| 116 | void service_for_each(void (*func)(struct service *svc)); |
| 117 | void service_for_each_class(const char *classname, |
| 118 | void (*func)(struct service *svc)); |
| 119 | void service_for_each_flags(unsigned matchflags, |
| 120 | void (*func)(struct service *svc)); |
| 121 | void service_stop(struct service *svc); |
Ken Sumrall | 752923c | 2010-12-03 16:33:31 -0800 | [diff] [blame] | 122 | void service_reset(struct service *svc); |
Mike Kasick | b54f39f | 2012-01-25 23:48:46 -0500 | [diff] [blame] | 123 | void service_restart(struct service *svc); |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 124 | void service_start(struct service *svc, const char *dynamic_args); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 125 | void property_changed(const char *name, const char *value); |
| 126 | |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 127 | int selinux_reload_policy(void); |
| 128 | |
San Mehat | 429721c | 2014-09-23 07:48:47 -0700 | [diff] [blame] | 129 | void zap_stdio(void); |
Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 130 | |
Elliott Hughes | 929f407 | 2015-04-24 21:13:44 -0700 | [diff] [blame] | 131 | void register_epoll_handler(int fd, void (*fn)()); |
| 132 | |
Tom Cherry | fa0c21c | 2015-07-23 17:53:11 -0700 | [diff] [blame^] | 133 | #endif /* _INIT_INIT_H */ |