init.h revision 3899e9fc01cf608f19f716749c54cc5c4d17e766
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 20void handle_control_message(const char *msg, const char *arg); 21 22void log_init(void); 23void log_set_level(int level); 24void log_close(void); 25void log_write(int level, const char *fmt, ...) 26 __attribute__ ((format(printf, 2, 3))); 27 28#define ERROR(x...) log_write(3, "<3>init: " x) 29#define NOTICE(x...) log_write(5, "<5>init: " x) 30#define INFO(x...) log_write(6, "<6>init: " x) 31 32#define LOG_DEFAULT_LEVEL 3 /* messages <= this level are logged */ 33#define LOG_UEVENTS 0 /* log uevent messages if 1. verbose */ 34 35struct listnode 36{ 37 struct listnode *next; 38 struct listnode *prev; 39}; 40 41#define node_to_item(node, container, member) \ 42 (container *) (((char*) (node)) - offsetof(container, member)) 43 44#define list_declare(name) \ 45 struct listnode name = { \ 46 .next = &name, \ 47 .prev = &name, \ 48 } 49 50#define list_for_each(node, list) \ 51 for (node = (list)->next; node != (list); node = node->next) 52 53void list_init(struct listnode *list); 54void list_add_tail(struct listnode *list, struct listnode *item); 55void list_remove(struct listnode *item); 56 57#define list_empty(list) ((list) == (list)->next) 58#define list_head(list) ((list)->next) 59#define list_tail(list) ((list)->prev) 60 61struct command 62{ 63 /* list of commands in an action */ 64 struct listnode clist; 65 66 int (*func)(int nargs, char **args); 67 int nargs; 68 char *args[1]; 69}; 70 71struct action { 72 /* node in list of all actions */ 73 struct listnode alist; 74 /* node in the queue of pending actions */ 75 struct listnode qlist; 76 /* node in list of actions for a trigger */ 77 struct listnode tlist; 78 79 unsigned hash; 80 const char *name; 81 82 struct listnode commands; 83 struct command *current; 84}; 85 86struct socketinfo { 87 struct socketinfo *next; 88 const char *name; 89 const char *type; 90 uid_t uid; 91 gid_t gid; 92 int perm; 93}; 94 95struct svcenvinfo { 96 struct svcenvinfo *next; 97 const char *name; 98 const char *value; 99}; 100 101#define SVC_DISABLED 0x01 /* do not autostart with class */ 102#define SVC_ONESHOT 0x02 /* do not restart on exit */ 103#define SVC_RUNNING 0x04 /* currently active */ 104#define SVC_RESTARTING 0x08 /* waiting to restart */ 105#define SVC_CONSOLE 0x10 /* requires console */ 106#define SVC_CRITICAL 0x20 /* will reboot into recovery if keeps crashing */ 107 108#define NR_SVC_SUPP_GIDS 12 /* twelve supplementary groups */ 109 110#define SVC_MAXARGS 64 111 112struct service { 113 /* list of all services */ 114 struct listnode slist; 115 116 const char *name; 117 const char *classname; 118 119 unsigned flags; 120 pid_t pid; 121 time_t time_started; /* time of last start */ 122 time_t time_crashed; /* first crash within inspection window */ 123 int nr_crashed; /* number of times crashed within window */ 124 125 uid_t uid; 126 gid_t gid; 127 gid_t supp_gids[NR_SVC_SUPP_GIDS]; 128 size_t nr_supp_gids; 129 130 struct socketinfo *sockets; 131 struct svcenvinfo *envvars; 132 133 struct action onrestart; /* Actions to execute on restart. */ 134 135 /* keycodes for triggering this service via /dev/keychord */ 136 int *keycodes; 137 int nkeycodes; 138 int keychord_id; 139 140 int ioprio_class; 141 int ioprio_pri; 142 143 int nargs; 144 /* "MUST BE AT THE END OF THE STRUCT" */ 145 char *args[1]; 146}; /* ^-------'args' MUST be at the end of this struct! */ 147 148int parse_config_file(const char *fn); 149 150void notify_service_state(const char *name, const char *state); 151 152struct service *service_find_by_name(const char *name); 153struct service *service_find_by_pid(pid_t pid); 154struct service *service_find_by_keychord(int keychord_id); 155void service_for_each(void (*func)(struct service *svc)); 156void service_for_each_class(const char *classname, 157 void (*func)(struct service *svc)); 158void service_for_each_flags(unsigned matchflags, 159 void (*func)(struct service *svc)); 160void service_stop(struct service *svc); 161void service_start(struct service *svc, const char *dynamic_args); 162void property_changed(const char *name, const char *value); 163 164#define INIT_IMAGE_FILE "/initlogo.rle" 165 166int load_565rle_image( char *file_name ); 167 168#endif /* _INIT_INIT_H */ 169