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