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 20 #include <cutils/list.h> 21 22 #include <sys/stat.h> 23 24 void handle_control_message(const char *msg, const char *arg); 25 26 struct command 27 { 28 /* list of commands in an action */ 29 struct listnode clist; 30 31 int (*func)(int nargs, char **args); 32 int nargs; 33 char *args[1]; 34 }; 35 36 struct action { 37 /* node in list of all actions */ 38 struct listnode alist; 39 /* node in the queue of pending actions */ 40 struct listnode qlist; 41 /* node in list of actions for a trigger */ 42 struct listnode tlist; 43 44 unsigned hash; 45 const char *name; 46 47 struct listnode commands; 48 struct command *current; 49 }; 50 51 struct socketinfo { 52 struct socketinfo *next; 53 const char *name; 54 const char *type; 55 uid_t uid; 56 gid_t gid; 57 int perm; 58 }; 59 60 struct svcenvinfo { 61 struct svcenvinfo *next; 62 const char *name; 63 const char *value; 64 }; 65 66 #define SVC_DISABLED 0x01 /* do not autostart with class */ 67 #define SVC_ONESHOT 0x02 /* do not restart on exit */ 68 #define SVC_RUNNING 0x04 /* currently active */ 69 #define SVC_RESTARTING 0x08 /* waiting to restart */ 70 #define SVC_CONSOLE 0x10 /* requires console */ 71 #define SVC_CRITICAL 0x20 /* will reboot into recovery if keeps crashing */ 72 #define SVC_RESET 0x40 /* Use when stopping a process, but not disabling 73 so it can be restarted with its class */ 74 #define SVC_RC_DISABLED 0x80 /* Remember if the disabled flag was set in the rc script */ 75 #define SVC_RESTART 0x100 /* Use to safely restart (stop, wait, start) a service */ 76 77 #define NR_SVC_SUPP_GIDS 12 /* twelve supplementary groups */ 78 79 #define COMMAND_RETRY_TIMEOUT 5 80 81 struct service { 82 /* list of all services */ 83 struct listnode slist; 84 85 const char *name; 86 const char *classname; 87 88 unsigned flags; 89 pid_t pid; 90 time_t time_started; /* time of last start */ 91 time_t time_crashed; /* first crash within inspection window */ 92 int nr_crashed; /* number of times crashed within window */ 93 94 uid_t uid; 95 gid_t gid; 96 gid_t supp_gids[NR_SVC_SUPP_GIDS]; 97 size_t nr_supp_gids; 98 99 char *seclabel; 100 101 struct socketinfo *sockets; 102 struct svcenvinfo *envvars; 103 104 struct action onrestart; /* Actions to execute on restart. */ 105 106 /* keycodes for triggering this service via /dev/keychord */ 107 int *keycodes; 108 int nkeycodes; 109 int keychord_id; 110 111 int ioprio_class; 112 int ioprio_pri; 113 114 int nargs; 115 /* "MUST BE AT THE END OF THE STRUCT" */ 116 char *args[1]; 117 }; /* ^-------'args' MUST be at the end of this struct! */ 118 119 void notify_service_state(const char *name, const char *state); 120 121 struct service *service_find_by_name(const char *name); 122 struct service *service_find_by_pid(pid_t pid); 123 struct service *service_find_by_keychord(int keychord_id); 124 void service_for_each(void (*func)(struct service *svc)); 125 void service_for_each_class(const char *classname, 126 void (*func)(struct service *svc)); 127 void service_for_each_flags(unsigned matchflags, 128 void (*func)(struct service *svc)); 129 void service_stop(struct service *svc); 130 void service_reset(struct service *svc); 131 void service_restart(struct service *svc); 132 void service_start(struct service *svc, const char *dynamic_args); 133 void property_changed(const char *name, const char *value); 134 135 #define INIT_IMAGE_FILE "/initlogo.rle" 136 137 int load_565rle_image( char *file_name ); 138 139 extern struct selabel_handle *sehandle; 140 extern struct selabel_handle *sehandle_prop; 141 extern int selinux_reload_policy(void); 142 143 #endif /* _INIT_INIT_H */ 144