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