blob: 59d72c0faa5c0560338a0008d9b80997a9944274 [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
Colin Crossed8a7d82010-04-19 17:05:34 -070020#include "list.h"
21
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080022void handle_control_message(const char *msg, const char *arg);
23
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080024struct command
25{
26 /* list of commands in an action */
27 struct listnode clist;
28
29 int (*func)(int nargs, char **args);
30 int nargs;
31 char *args[1];
32};
33
34struct action {
35 /* node in list of all actions */
36 struct listnode alist;
37 /* node in the queue of pending actions */
38 struct listnode qlist;
39 /* node in list of actions for a trigger */
40 struct listnode tlist;
41
42 unsigned hash;
43 const char *name;
44
45 struct listnode commands;
46 struct command *current;
47};
48
49struct socketinfo {
50 struct socketinfo *next;
51 const char *name;
52 const char *type;
53 uid_t uid;
54 gid_t gid;
55 int perm;
56};
57
58struct svcenvinfo {
59 struct svcenvinfo *next;
60 const char *name;
61 const char *value;
62};
63
64#define SVC_DISABLED 0x01 /* do not autostart with class */
65#define SVC_ONESHOT 0x02 /* do not restart on exit */
66#define SVC_RUNNING 0x04 /* currently active */
67#define SVC_RESTARTING 0x08 /* waiting to restart */
68#define SVC_CONSOLE 0x10 /* requires console */
69#define SVC_CRITICAL 0x20 /* will reboot into recovery if keeps crashing */
70
Nick Pelly830abe02010-03-23 20:37:40 -070071#define NR_SVC_SUPP_GIDS 12 /* twelve supplementary groups */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080072
San Mehatf24e2522009-05-19 13:30:46 -070073#define SVC_MAXARGS 64
74
Colin Crossebc6ff12010-04-13 19:52:01 -070075#define COMMAND_RETRY_TIMEOUT 5
76
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080077struct service {
78 /* list of all services */
79 struct listnode slist;
80
81 const char *name;
82 const char *classname;
83
84 unsigned flags;
85 pid_t pid;
86 time_t time_started; /* time of last start */
87 time_t time_crashed; /* first crash within inspection window */
88 int nr_crashed; /* number of times crashed within window */
89
90 uid_t uid;
91 gid_t gid;
92 gid_t supp_gids[NR_SVC_SUPP_GIDS];
93 size_t nr_supp_gids;
94
95 struct socketinfo *sockets;
96 struct svcenvinfo *envvars;
97
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080098 struct action onrestart; /* Actions to execute on restart. */
99
100 /* keycodes for triggering this service via /dev/keychord */
101 int *keycodes;
102 int nkeycodes;
103 int keychord_id;
San Mehatc83cd872009-05-14 14:54:22 -0700104
San Mehat4e221f02010-02-25 14:19:50 -0800105 int ioprio_class;
106 int ioprio_pri;
107
San Mehatc83cd872009-05-14 14:54:22 -0700108 int nargs;
109 /* "MUST BE AT THE END OF THE STRUCT" */
110 char *args[1];
111}; /* ^-------'args' MUST be at the end of this struct! */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800112
113int parse_config_file(const char *fn);
114
Colin Cross9c5366b2010-04-13 19:48:59 -0700115void notify_service_state(const char *name, const char *state);
116
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800117struct service *service_find_by_name(const char *name);
118struct service *service_find_by_pid(pid_t pid);
119struct service *service_find_by_keychord(int keychord_id);
120void service_for_each(void (*func)(struct service *svc));
121void service_for_each_class(const char *classname,
122 void (*func)(struct service *svc));
123void service_for_each_flags(unsigned matchflags,
124 void (*func)(struct service *svc));
125void service_stop(struct service *svc);
San Mehatf24e2522009-05-19 13:30:46 -0700126void service_start(struct service *svc, const char *dynamic_args);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800127void property_changed(const char *name, const char *value);
128
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800129#define INIT_IMAGE_FILE "/initlogo.rle"
130
131int load_565rle_image( char *file_name );
132
133#endif /* _INIT_INIT_H */