| 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> | 
|  | 21 |  | 
| Dima Zavin | da04c52 | 2011-09-01 17:09:44 -0700 | [diff] [blame] | 22 | #include <cutils/list.h> | 
| Elliott Hughes | f3cf438 | 2015-02-03 17:12:07 -0800 | [diff] [blame] | 23 | #include <cutils/iosched_policy.h> | 
| Colin Cross | ed8a7d8 | 2010-04-19 17:05:34 -0700 | [diff] [blame] | 24 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 25 | struct command | 
|  | 26 | { | 
|  | 27 | /* list of commands in an action */ | 
|  | 28 | struct listnode clist; | 
|  | 29 |  | 
|  | 30 | int (*func)(int nargs, char **args); | 
| Riley Andrews | 24a3b78 | 2014-06-26 13:56:01 -0700 | [diff] [blame] | 31 |  | 
|  | 32 | int line; | 
|  | 33 | const char *filename; | 
|  | 34 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 35 | int nargs; | 
|  | 36 | char *args[1]; | 
|  | 37 | }; | 
| Riley Andrews | 24a3b78 | 2014-06-26 13:56:01 -0700 | [diff] [blame] | 38 |  | 
| Badhri Jagan Sridharan | 0b41512 | 2014-10-10 23:19:06 -0700 | [diff] [blame] | 39 | struct trigger { | 
|  | 40 | struct listnode nlist; | 
|  | 41 | const char *name; | 
|  | 42 | }; | 
|  | 43 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 44 | struct action { | 
|  | 45 | /* node in list of all actions */ | 
|  | 46 | struct listnode alist; | 
|  | 47 | /* node in the queue of pending actions */ | 
|  | 48 | struct listnode qlist; | 
|  | 49 | /* node in list of actions for a trigger */ | 
|  | 50 | struct listnode tlist; | 
|  | 51 |  | 
|  | 52 | unsigned hash; | 
| Riley Andrews | 24a3b78 | 2014-06-26 13:56:01 -0700 | [diff] [blame] | 53 |  | 
| Badhri Jagan Sridharan | 0b41512 | 2014-10-10 23:19:06 -0700 | [diff] [blame] | 54 | /* list of actions which triggers the commands*/ | 
|  | 55 | struct listnode triggers; | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 56 | struct listnode commands; | 
|  | 57 | struct command *current; | 
|  | 58 | }; | 
|  | 59 |  | 
|  | 60 | struct socketinfo { | 
|  | 61 | struct socketinfo *next; | 
|  | 62 | const char *name; | 
|  | 63 | const char *type; | 
|  | 64 | uid_t uid; | 
|  | 65 | gid_t gid; | 
|  | 66 | int perm; | 
| Stephen Smalley | 8348d27 | 2013-05-13 12:37:04 -0400 | [diff] [blame] | 67 | const char *socketcon; | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 68 | }; | 
|  | 69 |  | 
|  | 70 | struct svcenvinfo { | 
|  | 71 | struct svcenvinfo *next; | 
|  | 72 | const char *name; | 
|  | 73 | const char *value; | 
|  | 74 | }; | 
|  | 75 |  | 
| Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 76 | #define SVC_DISABLED       0x001  // do not autostart with class | 
|  | 77 | #define SVC_ONESHOT        0x002  // do not restart on exit | 
|  | 78 | #define SVC_RUNNING        0x004  // currently active | 
|  | 79 | #define SVC_RESTARTING     0x008  // waiting to restart | 
|  | 80 | #define SVC_CONSOLE        0x010  // requires console | 
|  | 81 | #define SVC_CRITICAL       0x020  // will reboot into recovery if keeps crashing | 
|  | 82 | #define SVC_RESET          0x040  // Use when stopping a process, but not disabling so it can be restarted with its class. | 
|  | 83 | #define SVC_RC_DISABLED    0x080  // Remember if the disabled flag was set in the rc script. | 
|  | 84 | #define SVC_RESTART        0x100  // Use to safely restart (stop, wait, start) a service. | 
|  | 85 | #define SVC_DISABLED_START 0x200  // A start was requested but it was disabled at the time. | 
|  | 86 | #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] | 87 |  | 
| Nick Pelly | 830abe0 | 2010-03-23 20:37:40 -0700 | [diff] [blame] | 88 | #define NR_SVC_SUPP_GIDS 12    /* twelve supplementary groups */ | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 89 |  | 
| Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 90 | #define COMMAND_RETRY_TIMEOUT 5 | 
|  | 91 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 92 | struct service { | 
| Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 93 | void NotifyStateChange(const char* new_state); | 
|  | 94 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 95 | /* list of all services */ | 
|  | 96 | struct listnode slist; | 
|  | 97 |  | 
| Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 98 | char *name; | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 99 | const char *classname; | 
|  | 100 |  | 
|  | 101 | unsigned flags; | 
|  | 102 | pid_t pid; | 
|  | 103 | time_t time_started;    /* time of last start */ | 
|  | 104 | time_t time_crashed;    /* first crash within inspection window */ | 
|  | 105 | int nr_crashed;         /* number of times crashed within window */ | 
| Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 106 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 107 | uid_t uid; | 
|  | 108 | gid_t gid; | 
|  | 109 | gid_t supp_gids[NR_SVC_SUPP_GIDS]; | 
|  | 110 | size_t nr_supp_gids; | 
|  | 111 |  | 
| Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 112 | const char* seclabel; | 
| Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 113 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 114 | struct socketinfo *sockets; | 
|  | 115 | struct svcenvinfo *envvars; | 
|  | 116 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 117 | struct action onrestart;  /* Actions to execute on restart. */ | 
| Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 118 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 119 | /* keycodes for triggering this service via /dev/keychord */ | 
|  | 120 | int *keycodes; | 
|  | 121 | int nkeycodes; | 
|  | 122 | int keychord_id; | 
| San Mehat | c83cd87 | 2009-05-14 14:54:22 -0700 | [diff] [blame] | 123 |  | 
| Elliott Hughes | f3cf438 | 2015-02-03 17:12:07 -0800 | [diff] [blame] | 124 | IoSchedClass ioprio_class; | 
| San Mehat | 4e221f0 | 2010-02-25 14:19:50 -0800 | [diff] [blame] | 125 | int ioprio_pri; | 
|  | 126 |  | 
| San Mehat | c83cd87 | 2009-05-14 14:54:22 -0700 | [diff] [blame] | 127 | int nargs; | 
|  | 128 | /* "MUST BE AT THE END OF THE STRUCT" */ | 
|  | 129 | char *args[1]; | 
|  | 130 | }; /*     ^-------'args' MUST be at the end of this struct! */ | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 131 |  | 
| Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 132 | extern bool waiting_for_exec; | 
|  | 133 | extern struct selabel_handle *sehandle; | 
|  | 134 | extern struct selabel_handle *sehandle_prop; | 
|  | 135 |  | 
|  | 136 | void build_triggers_string(char *name_str, int length, struct action *cur_action); | 
|  | 137 |  | 
|  | 138 | void handle_control_message(const char *msg, const char *arg); | 
| Colin Cross | 9c5366b | 2010-04-13 19:48:59 -0700 | [diff] [blame] | 139 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 140 | struct service *service_find_by_name(const char *name); | 
|  | 141 | struct service *service_find_by_pid(pid_t pid); | 
|  | 142 | struct service *service_find_by_keychord(int keychord_id); | 
|  | 143 | void service_for_each(void (*func)(struct service *svc)); | 
|  | 144 | void service_for_each_class(const char *classname, | 
|  | 145 | void (*func)(struct service *svc)); | 
|  | 146 | void service_for_each_flags(unsigned matchflags, | 
|  | 147 | void (*func)(struct service *svc)); | 
|  | 148 | void service_stop(struct service *svc); | 
| Ken Sumrall | 752923c | 2010-12-03 16:33:31 -0800 | [diff] [blame] | 149 | void service_reset(struct service *svc); | 
| Mike Kasick | b54f39f | 2012-01-25 23:48:46 -0500 | [diff] [blame] | 150 | void service_restart(struct service *svc); | 
| San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 151 | 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] | 152 | void property_changed(const char *name, const char *value); | 
|  | 153 |  | 
| Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 154 | int selinux_reload_policy(void); | 
|  | 155 |  | 
| San Mehat | 429721c | 2014-09-23 07:48:47 -0700 | [diff] [blame] | 156 | void zap_stdio(void); | 
| Stephen Smalley | e46f9d5 | 2012-01-13 08:48:47 -0500 | [diff] [blame] | 157 |  | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 158 | #endif	/* _INIT_INIT_H */ |