blob: 9d126042616420d403332b11c75631e9e3f8d42d [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
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 Projectdd7bc332009-03-03 19:32:55 -080020void handle_control_message(const char *msg, const char *arg);
21
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080022void log_init(void);
23void log_set_level(int level);
24void log_close(void);
Dima Zavin770354d2009-05-05 18:33:07 -070025void log_write(int level, const char *fmt, ...)
26 __attribute__ ((format(printf, 2, 3)));
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080027
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 Projectdd7bc332009-03-03 19:32:55 -080035struct 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
Nick Pelly830abe02010-03-23 20:37:40 -0700108#define NR_SVC_SUPP_GIDS 12 /* twelve supplementary groups */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800109
San Mehatf24e2522009-05-19 13:30:46 -0700110#define SVC_MAXARGS 64
111
Colin Crossebc6ff12010-04-13 19:52:01 -0700112#define COMMAND_RETRY_TIMEOUT 5
113
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800114struct 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 Projectdd7bc332009-03-03 19:32:55 -0800135 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 Mehatc83cd872009-05-14 14:54:22 -0700141
San Mehat4e221f02010-02-25 14:19:50 -0800142 int ioprio_class;
143 int ioprio_pri;
144
San Mehatc83cd872009-05-14 14:54:22 -0700145 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 Projectdd7bc332009-03-03 19:32:55 -0800149
150int parse_config_file(const char *fn);
151
Colin Cross9c5366b2010-04-13 19:48:59 -0700152void notify_service_state(const char *name, const char *state);
153
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800154struct service *service_find_by_name(const char *name);
155struct service *service_find_by_pid(pid_t pid);
156struct service *service_find_by_keychord(int keychord_id);
157void service_for_each(void (*func)(struct service *svc));
158void service_for_each_class(const char *classname,
159 void (*func)(struct service *svc));
160void service_for_each_flags(unsigned matchflags,
161 void (*func)(struct service *svc));
162void service_stop(struct service *svc);
San Mehatf24e2522009-05-19 13:30:46 -0700163void service_start(struct service *svc, const char *dynamic_args);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800164void property_changed(const char *name, const char *value);
165
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800166#define INIT_IMAGE_FILE "/initlogo.rle"
167
168int load_565rle_image( char *file_name );
169
170#endif /* _INIT_INIT_H */