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