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 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 20 | void handle_control_message(const char *msg, const char *arg); |
| 21 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 22 | void log_init(void); |
| 23 | void log_set_level(int level); |
| 24 | void log_close(void); |
Dima Zavin | 770354d | 2009-05-05 18:33:07 -0700 | [diff] [blame] | 25 | void log_write(int level, const char *fmt, ...) |
| 26 | __attribute__ ((format(printf, 2, 3))); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 35 | struct 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 | |
| 53 | void list_init(struct listnode *list); |
| 54 | void list_add_tail(struct listnode *list, struct listnode *item); |
| 55 | void 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 | |
| 61 | struct 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 | |
| 71 | struct 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 | |
| 86 | struct 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 | |
| 95 | struct 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 | |
Nick Pelly | 830abe0 | 2010-03-23 20:37:40 -0700 | [diff] [blame] | 108 | #define NR_SVC_SUPP_GIDS 12 /* twelve supplementary groups */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 109 | |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 110 | #define SVC_MAXARGS 64 |
| 111 | |
Colin Cross | ebc6ff1 | 2010-04-13 19:52:01 -0700 | [diff] [blame] | 112 | #define COMMAND_RETRY_TIMEOUT 5 |
| 113 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 114 | struct service { |
| 115 | /* list of all services */ |
| 116 | struct listnode slist; |
| 117 | |
| 118 | const char *name; |
| 119 | const char *classname; |
| 120 | |
| 121 | unsigned flags; |
| 122 | pid_t pid; |
| 123 | time_t time_started; /* time of last start */ |
| 124 | time_t time_crashed; /* first crash within inspection window */ |
| 125 | int nr_crashed; /* number of times crashed within window */ |
| 126 | |
| 127 | uid_t uid; |
| 128 | gid_t gid; |
| 129 | gid_t supp_gids[NR_SVC_SUPP_GIDS]; |
| 130 | size_t nr_supp_gids; |
| 131 | |
| 132 | struct socketinfo *sockets; |
| 133 | struct svcenvinfo *envvars; |
| 134 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 135 | struct action onrestart; /* Actions to execute on restart. */ |
| 136 | |
| 137 | /* keycodes for triggering this service via /dev/keychord */ |
| 138 | int *keycodes; |
| 139 | int nkeycodes; |
| 140 | int keychord_id; |
San Mehat | c83cd87 | 2009-05-14 14:54:22 -0700 | [diff] [blame] | 141 | |
San Mehat | 4e221f0 | 2010-02-25 14:19:50 -0800 | [diff] [blame] | 142 | int ioprio_class; |
| 143 | int ioprio_pri; |
| 144 | |
San Mehat | c83cd87 | 2009-05-14 14:54:22 -0700 | [diff] [blame] | 145 | int nargs; |
| 146 | /* "MUST BE AT THE END OF THE STRUCT" */ |
| 147 | char *args[1]; |
| 148 | }; /* ^-------'args' MUST be at the end of this struct! */ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 149 | |
| 150 | int parse_config_file(const char *fn); |
| 151 | |
Colin Cross | 9c5366b | 2010-04-13 19:48:59 -0700 | [diff] [blame] | 152 | void notify_service_state(const char *name, const char *state); |
| 153 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 154 | struct service *service_find_by_name(const char *name); |
| 155 | struct service *service_find_by_pid(pid_t pid); |
| 156 | struct service *service_find_by_keychord(int keychord_id); |
| 157 | void service_for_each(void (*func)(struct service *svc)); |
| 158 | void service_for_each_class(const char *classname, |
| 159 | void (*func)(struct service *svc)); |
| 160 | void service_for_each_flags(unsigned matchflags, |
| 161 | void (*func)(struct service *svc)); |
| 162 | void service_stop(struct service *svc); |
San Mehat | f24e252 | 2009-05-19 13:30:46 -0700 | [diff] [blame] | 163 | 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] | 164 | void property_changed(const char *name, const char *value); |
| 165 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 166 | #define INIT_IMAGE_FILE "/initlogo.rle" |
| 167 | |
| 168 | int load_565rle_image( char *file_name ); |
| 169 | |
| 170 | #endif /* _INIT_INIT_H */ |