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