2009-03-04 04:32:55 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INIT_INIT_H
|
|
|
|
#define _INIT_INIT_H
|
|
|
|
|
2011-09-02 02:09:44 +02:00
|
|
|
#include <cutils/list.h>
|
2015-02-04 02:12:07 +01:00
|
|
|
#include <cutils/iosched_policy.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2010-04-20 23:29:05 +02:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2010-04-20 02:05:34 +02:00
|
|
|
void handle_control_message(const char *msg, const char *arg);
|
2009-03-04 04:32:55 +01:00
|
|
|
|
|
|
|
struct command
|
|
|
|
{
|
|
|
|
/* list of commands in an action */
|
|
|
|
struct listnode clist;
|
|
|
|
|
|
|
|
int (*func)(int nargs, char **args);
|
2014-06-26 22:56:01 +02:00
|
|
|
|
|
|
|
int line;
|
|
|
|
const char *filename;
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
int nargs;
|
|
|
|
char *args[1];
|
|
|
|
};
|
2014-06-26 22:56:01 +02:00
|
|
|
|
2014-10-11 08:19:06 +02:00
|
|
|
struct trigger {
|
|
|
|
struct listnode nlist;
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
struct action {
|
|
|
|
/* node in list of all actions */
|
|
|
|
struct listnode alist;
|
|
|
|
/* node in the queue of pending actions */
|
|
|
|
struct listnode qlist;
|
|
|
|
/* node in list of actions for a trigger */
|
|
|
|
struct listnode tlist;
|
|
|
|
|
|
|
|
unsigned hash;
|
2014-06-26 22:56:01 +02:00
|
|
|
|
2014-10-11 08:19:06 +02:00
|
|
|
/* list of actions which triggers the commands*/
|
|
|
|
struct listnode triggers;
|
2009-03-04 04:32:55 +01:00
|
|
|
struct listnode commands;
|
|
|
|
struct command *current;
|
|
|
|
};
|
|
|
|
|
2014-10-11 08:19:06 +02:00
|
|
|
void build_triggers_string(char *name_str, int length, struct action *cur_action);
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
struct socketinfo {
|
|
|
|
struct socketinfo *next;
|
|
|
|
const char *name;
|
|
|
|
const char *type;
|
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
|
|
|
int perm;
|
2013-05-13 18:37:04 +02:00
|
|
|
const char *socketcon;
|
2009-03-04 04:32:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct svcenvinfo {
|
|
|
|
struct svcenvinfo *next;
|
|
|
|
const char *name;
|
|
|
|
const char *value;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SVC_DISABLED 0x01 /* do not autostart with class */
|
|
|
|
#define SVC_ONESHOT 0x02 /* do not restart on exit */
|
|
|
|
#define SVC_RUNNING 0x04 /* currently active */
|
|
|
|
#define SVC_RESTARTING 0x08 /* waiting to restart */
|
|
|
|
#define SVC_CONSOLE 0x10 /* requires console */
|
|
|
|
#define SVC_CRITICAL 0x20 /* will reboot into recovery if keeps crashing */
|
2010-12-04 01:33:31 +01:00
|
|
|
#define SVC_RESET 0x40 /* Use when stopping a process, but not disabling
|
|
|
|
so it can be restarted with its class */
|
2011-10-27 01:56:00 +02:00
|
|
|
#define SVC_RC_DISABLED 0x80 /* Remember if the disabled flag was set in the rc script */
|
2012-01-26 05:48:46 +01:00
|
|
|
#define SVC_RESTART 0x100 /* Use to safely restart (stop, wait, start) a service */
|
2014-05-03 06:14:29 +02:00
|
|
|
#define SVC_DISABLED_START 0x200 /* a start was requested but it was disabled at the time */
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2010-03-24 04:37:40 +01:00
|
|
|
#define NR_SVC_SUPP_GIDS 12 /* twelve supplementary groups */
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2010-04-14 04:52:01 +02:00
|
|
|
#define COMMAND_RETRY_TIMEOUT 5
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
struct service {
|
|
|
|
/* list of all services */
|
|
|
|
struct listnode slist;
|
|
|
|
|
|
|
|
const char *name;
|
|
|
|
const char *classname;
|
|
|
|
|
|
|
|
unsigned flags;
|
|
|
|
pid_t pid;
|
|
|
|
time_t time_started; /* time of last start */
|
|
|
|
time_t time_crashed; /* first crash within inspection window */
|
|
|
|
int nr_crashed; /* number of times crashed within window */
|
|
|
|
|
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
|
|
|
gid_t supp_gids[NR_SVC_SUPP_GIDS];
|
|
|
|
size_t nr_supp_gids;
|
|
|
|
|
2012-01-13 14:48:47 +01:00
|
|
|
char *seclabel;
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
struct socketinfo *sockets;
|
|
|
|
struct svcenvinfo *envvars;
|
|
|
|
|
|
|
|
struct action onrestart; /* Actions to execute on restart. */
|
|
|
|
|
|
|
|
/* keycodes for triggering this service via /dev/keychord */
|
|
|
|
int *keycodes;
|
|
|
|
int nkeycodes;
|
|
|
|
int keychord_id;
|
2009-05-14 23:54:22 +02:00
|
|
|
|
2015-02-04 02:12:07 +01:00
|
|
|
IoSchedClass ioprio_class;
|
2010-02-25 23:19:50 +01:00
|
|
|
int ioprio_pri;
|
|
|
|
|
2009-05-14 23:54:22 +02:00
|
|
|
int nargs;
|
|
|
|
/* "MUST BE AT THE END OF THE STRUCT" */
|
|
|
|
char *args[1];
|
|
|
|
}; /* ^-------'args' MUST be at the end of this struct! */
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2010-04-14 04:48:59 +02:00
|
|
|
void notify_service_state(const char *name, const char *state);
|
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
struct service *service_find_by_name(const char *name);
|
|
|
|
struct service *service_find_by_pid(pid_t pid);
|
|
|
|
struct service *service_find_by_keychord(int keychord_id);
|
|
|
|
void service_for_each(void (*func)(struct service *svc));
|
|
|
|
void service_for_each_class(const char *classname,
|
|
|
|
void (*func)(struct service *svc));
|
|
|
|
void service_for_each_flags(unsigned matchflags,
|
|
|
|
void (*func)(struct service *svc));
|
|
|
|
void service_stop(struct service *svc);
|
2010-12-04 01:33:31 +01:00
|
|
|
void service_reset(struct service *svc);
|
2012-01-26 05:48:46 +01:00
|
|
|
void service_restart(struct service *svc);
|
2009-05-19 22:30:46 +02:00
|
|
|
void service_start(struct service *svc, const char *dynamic_args);
|
2009-03-04 04:32:55 +01:00
|
|
|
void property_changed(const char *name, const char *value);
|
|
|
|
|
2012-01-13 14:48:47 +01:00
|
|
|
extern struct selabel_handle *sehandle;
|
2012-08-09 16:05:49 +02:00
|
|
|
extern struct selabel_handle *sehandle_prop;
|
2012-05-01 21:02:53 +02:00
|
|
|
extern int selinux_reload_policy(void);
|
2014-09-23 16:48:47 +02:00
|
|
|
void zap_stdio(void);
|
2012-01-13 14:48:47 +01:00
|
|
|
|
2009-03-04 04:32:55 +01:00
|
|
|
#endif /* _INIT_INIT_H */
|