am 53d504f0: Merge "init support for cgroups."
* commit '53d504f00dea232601e1290c8255274afb0f4256': init support for cgroups.
This commit is contained in:
commit
f5a7ba9eed
5 changed files with 71 additions and 40 deletions
|
|
@ -288,6 +288,16 @@ void service_start(struct service *svc, const char *dynamic_args)
|
||||||
freecon(scon);
|
freecon(scon);
|
||||||
scon = NULL;
|
scon = NULL;
|
||||||
|
|
||||||
|
if (svc->writepid_files_) {
|
||||||
|
std::string pid_str = android::base::StringPrintf("%d", pid);
|
||||||
|
for (auto& file : *svc->writepid_files_) {
|
||||||
|
if (!android::base::WriteStringToFile(pid_str, file)) {
|
||||||
|
ERROR("couldn't write %s to %s: %s\n",
|
||||||
|
pid_str.c_str(), file.c_str(), strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (svc->ioprio_class != IoSchedClass_NONE) {
|
if (svc->ioprio_class != IoSchedClass_NONE) {
|
||||||
if (android_set_ioprio(getpid(), svc->ioprio_class, svc->ioprio_pri)) {
|
if (android_set_ioprio(getpid(), svc->ioprio_class, svc->ioprio_pri)) {
|
||||||
ERROR("Failed to set pid %d ioprio = %d,%d: %s\n",
|
ERROR("Failed to set pid %d ioprio = %d,%d: %s\n",
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <cutils/list.h>
|
#include <cutils/list.h>
|
||||||
#include <cutils/iosched_policy.h>
|
#include <cutils/iosched_policy.h>
|
||||||
|
|
||||||
|
|
@ -116,6 +119,8 @@ struct service {
|
||||||
|
|
||||||
struct action onrestart; /* Actions to execute on restart. */
|
struct action onrestart; /* Actions to execute on restart. */
|
||||||
|
|
||||||
|
std::vector<std::string>* writepid_files_;
|
||||||
|
|
||||||
/* keycodes for triggering this service via /dev/keychord */
|
/* keycodes for triggering this service via /dev/keychord */
|
||||||
int *keycodes;
|
int *keycodes;
|
||||||
int nkeycodes;
|
int nkeycodes;
|
||||||
|
|
|
||||||
|
|
@ -206,6 +206,7 @@ static int lookup_keyword(const char *s)
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
if (!strcmp(s, "rite")) return K_write;
|
if (!strcmp(s, "rite")) return K_write;
|
||||||
|
if (!strcmp(s, "ritepid")) return K_writepid;
|
||||||
if (!strcmp(s, "ait")) return K_wait;
|
if (!strcmp(s, "ait")) return K_wait;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -924,6 +925,16 @@ static void parse_line_service(struct parse_state *state, int nargs, char **args
|
||||||
svc->seclabel = args[1];
|
svc->seclabel = args[1];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case K_writepid:
|
||||||
|
if (nargs < 2) {
|
||||||
|
parse_error(state, "writepid option requires at least one filename\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
svc->writepid_files_ = new std::vector<std::string>;
|
||||||
|
for (int i = 1; i < nargs; ++i) {
|
||||||
|
svc->writepid_files_->push_back(args[i]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
parse_error(state, "invalid option '%s'\n", args[0]);
|
parse_error(state, "invalid option '%s'\n", args[0]);
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,15 @@ int do_wait(int nargs, char **args);
|
||||||
enum {
|
enum {
|
||||||
K_UNKNOWN,
|
K_UNKNOWN,
|
||||||
#endif
|
#endif
|
||||||
|
KEYWORD(bootchart_init, COMMAND, 0, do_bootchart_init)
|
||||||
|
KEYWORD(chmod, COMMAND, 2, do_chmod)
|
||||||
|
KEYWORD(chown, COMMAND, 2, do_chown)
|
||||||
KEYWORD(class, OPTION, 0, 0)
|
KEYWORD(class, OPTION, 0, 0)
|
||||||
|
KEYWORD(class_reset, COMMAND, 1, do_class_reset)
|
||||||
KEYWORD(class_start, COMMAND, 1, do_class_start)
|
KEYWORD(class_start, COMMAND, 1, do_class_start)
|
||||||
KEYWORD(class_stop, COMMAND, 1, do_class_stop)
|
KEYWORD(class_stop, COMMAND, 1, do_class_stop)
|
||||||
KEYWORD(class_reset, COMMAND, 1, do_class_reset)
|
|
||||||
KEYWORD(console, OPTION, 0, 0)
|
KEYWORD(console, OPTION, 0, 0)
|
||||||
|
KEYWORD(copy, COMMAND, 2, do_copy)
|
||||||
KEYWORD(critical, OPTION, 0, 0)
|
KEYWORD(critical, OPTION, 0, 0)
|
||||||
KEYWORD(disabled, OPTION, 0, 0)
|
KEYWORD(disabled, OPTION, 0, 0)
|
||||||
KEYWORD(domainname, COMMAND, 1, do_domainname)
|
KEYWORD(domainname, COMMAND, 1, do_domainname)
|
||||||
|
|
@ -57,16 +61,20 @@ enum {
|
||||||
KEYWORD(group, OPTION, 0, 0)
|
KEYWORD(group, OPTION, 0, 0)
|
||||||
KEYWORD(hostname, COMMAND, 1, do_hostname)
|
KEYWORD(hostname, COMMAND, 1, do_hostname)
|
||||||
KEYWORD(ifup, COMMAND, 1, do_ifup)
|
KEYWORD(ifup, COMMAND, 1, do_ifup)
|
||||||
|
KEYWORD(import, SECTION, 1, 0)
|
||||||
KEYWORD(insmod, COMMAND, 1, do_insmod)
|
KEYWORD(insmod, COMMAND, 1, do_insmod)
|
||||||
KEYWORD(installkey, COMMAND, 1, do_installkey)
|
KEYWORD(installkey, COMMAND, 1, do_installkey)
|
||||||
KEYWORD(import, SECTION, 1, 0)
|
KEYWORD(ioprio, OPTION, 0, 0)
|
||||||
KEYWORD(keycodes, OPTION, 0, 0)
|
KEYWORD(keycodes, OPTION, 0, 0)
|
||||||
|
KEYWORD(load_all_props, COMMAND, 0, do_load_all_props)
|
||||||
|
KEYWORD(load_persist_props, COMMAND, 0, do_load_persist_props)
|
||||||
|
KEYWORD(loglevel, COMMAND, 1, do_loglevel)
|
||||||
KEYWORD(mkdir, COMMAND, 1, do_mkdir)
|
KEYWORD(mkdir, COMMAND, 1, do_mkdir)
|
||||||
KEYWORD(mount_all, COMMAND, 1, do_mount_all)
|
KEYWORD(mount_all, COMMAND, 1, do_mount_all)
|
||||||
KEYWORD(mount, COMMAND, 3, do_mount)
|
KEYWORD(mount, COMMAND, 3, do_mount)
|
||||||
KEYWORD(on, SECTION, 0, 0)
|
|
||||||
KEYWORD(oneshot, OPTION, 0, 0)
|
KEYWORD(oneshot, OPTION, 0, 0)
|
||||||
KEYWORD(onrestart, OPTION, 0, 0)
|
KEYWORD(onrestart, OPTION, 0, 0)
|
||||||
|
KEYWORD(on, SECTION, 0, 0)
|
||||||
KEYWORD(powerctl, COMMAND, 1, do_powerctl)
|
KEYWORD(powerctl, COMMAND, 1, do_powerctl)
|
||||||
KEYWORD(restart, COMMAND, 1, do_restart)
|
KEYWORD(restart, COMMAND, 1, do_restart)
|
||||||
KEYWORD(restorecon, COMMAND, 1, do_restorecon)
|
KEYWORD(restorecon, COMMAND, 1, do_restorecon)
|
||||||
|
|
@ -82,22 +90,15 @@ enum {
|
||||||
KEYWORD(start, COMMAND, 1, do_start)
|
KEYWORD(start, COMMAND, 1, do_start)
|
||||||
KEYWORD(stop, COMMAND, 1, do_stop)
|
KEYWORD(stop, COMMAND, 1, do_stop)
|
||||||
KEYWORD(swapon_all, COMMAND, 1, do_swapon_all)
|
KEYWORD(swapon_all, COMMAND, 1, do_swapon_all)
|
||||||
KEYWORD(trigger, COMMAND, 1, do_trigger)
|
|
||||||
KEYWORD(symlink, COMMAND, 1, do_symlink)
|
KEYWORD(symlink, COMMAND, 1, do_symlink)
|
||||||
KEYWORD(sysclktz, COMMAND, 1, do_sysclktz)
|
KEYWORD(sysclktz, COMMAND, 1, do_sysclktz)
|
||||||
|
KEYWORD(trigger, COMMAND, 1, do_trigger)
|
||||||
KEYWORD(user, OPTION, 0, 0)
|
KEYWORD(user, OPTION, 0, 0)
|
||||||
KEYWORD(verity_load_state, COMMAND, 0, do_verity_load_state)
|
KEYWORD(verity_load_state, COMMAND, 0, do_verity_load_state)
|
||||||
KEYWORD(verity_update_state, COMMAND, 0, do_verity_update_state)
|
KEYWORD(verity_update_state, COMMAND, 0, do_verity_update_state)
|
||||||
KEYWORD(wait, COMMAND, 1, do_wait)
|
KEYWORD(wait, COMMAND, 1, do_wait)
|
||||||
KEYWORD(write, COMMAND, 2, do_write)
|
KEYWORD(write, COMMAND, 2, do_write)
|
||||||
KEYWORD(copy, COMMAND, 2, do_copy)
|
KEYWORD(writepid, OPTION, 0, 0)
|
||||||
KEYWORD(chown, COMMAND, 2, do_chown)
|
|
||||||
KEYWORD(chmod, COMMAND, 2, do_chmod)
|
|
||||||
KEYWORD(loglevel, COMMAND, 1, do_loglevel)
|
|
||||||
KEYWORD(load_persist_props, COMMAND, 0, do_load_persist_props)
|
|
||||||
KEYWORD(load_all_props, COMMAND, 0, do_load_all_props)
|
|
||||||
KEYWORD(ioprio, OPTION, 0, 0)
|
|
||||||
KEYWORD(bootchart_init, COMMAND, 0, do_bootchart_init)
|
|
||||||
#ifdef __MAKE_KEYWORD_ENUM__
|
#ifdef __MAKE_KEYWORD_ENUM__
|
||||||
KEYWORD_COUNT,
|
KEYWORD_COUNT,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -60,36 +60,36 @@ Options are modifiers to services. They affect how and when init
|
||||||
runs the service.
|
runs the service.
|
||||||
|
|
||||||
critical
|
critical
|
||||||
This is a device-critical service. If it exits more than four times in
|
This is a device-critical service. If it exits more than four times in
|
||||||
four minutes, the device will reboot into recovery mode.
|
four minutes, the device will reboot into recovery mode.
|
||||||
|
|
||||||
disabled
|
disabled
|
||||||
This service will not automatically start with its class.
|
This service will not automatically start with its class.
|
||||||
It must be explicitly started by name.
|
It must be explicitly started by name.
|
||||||
|
|
||||||
setenv <name> <value>
|
setenv <name> <value>
|
||||||
Set the environment variable <name> to <value> in the launched process.
|
Set the environment variable <name> to <value> in the launched process.
|
||||||
|
|
||||||
socket <name> <type> <perm> [ <user> [ <group> [ <seclabel> ] ] ]
|
socket <name> <type> <perm> [ <user> [ <group> [ <seclabel> ] ] ]
|
||||||
Create a unix domain socket named /dev/socket/<name> and pass
|
Create a unix domain socket named /dev/socket/<name> and pass
|
||||||
its fd to the launched process. <type> must be "dgram", "stream" or "seqpacket".
|
its fd to the launched process. <type> must be "dgram", "stream" or "seqpacket".
|
||||||
User and group default to 0.
|
User and group default to 0.
|
||||||
'seclabel' is the SELinux security context for the socket.
|
'seclabel' is the SELinux security context for the socket.
|
||||||
It defaults to the service security context, as specified by seclabel or
|
It defaults to the service security context, as specified by seclabel or
|
||||||
computed based on the service executable file security context.
|
computed based on the service executable file security context.
|
||||||
|
|
||||||
user <username>
|
user <username>
|
||||||
Change to username before exec'ing this service.
|
Change to username before exec'ing this service.
|
||||||
Currently defaults to root. (??? probably should default to nobody)
|
Currently defaults to root. (??? probably should default to nobody)
|
||||||
Currently, if your process requires linux capabilities then you cannot use
|
Currently, if your process requires linux capabilities then you cannot use
|
||||||
this command. You must instead request the capabilities in-process while
|
this command. You must instead request the capabilities in-process while
|
||||||
still root, and then drop to your desired uid.
|
still root, and then drop to your desired uid.
|
||||||
|
|
||||||
group <groupname> [ <groupname> ]*
|
group <groupname> [ <groupname> ]*
|
||||||
Change to groupname before exec'ing this service. Additional
|
Change to groupname before exec'ing this service. Additional
|
||||||
groupnames beyond the (required) first one are used to set the
|
groupnames beyond the (required) first one are used to set the
|
||||||
supplemental groups of the process (via setgroups()).
|
supplemental groups of the process (via setgroups()).
|
||||||
Currently defaults to root. (??? probably should default to nobody)
|
Currently defaults to root. (??? probably should default to nobody)
|
||||||
|
|
||||||
seclabel <seclabel>
|
seclabel <seclabel>
|
||||||
Change to 'seclabel' before exec'ing this service.
|
Change to 'seclabel' before exec'ing this service.
|
||||||
|
|
@ -99,22 +99,26 @@ seclabel <seclabel>
|
||||||
If not specified and no transition is defined in policy, defaults to the init context.
|
If not specified and no transition is defined in policy, defaults to the init context.
|
||||||
|
|
||||||
oneshot
|
oneshot
|
||||||
Do not restart the service when it exits.
|
Do not restart the service when it exits.
|
||||||
|
|
||||||
class <name>
|
class <name>
|
||||||
Specify a class name for the service. All services in a
|
Specify a class name for the service. All services in a
|
||||||
named class may be started or stopped together. A service
|
named class may be started or stopped together. A service
|
||||||
is in the class "default" if one is not specified via the
|
is in the class "default" if one is not specified via the
|
||||||
class option.
|
class option.
|
||||||
|
|
||||||
onrestart
|
onrestart
|
||||||
Execute a Command (see below) when service restarts.
|
Execute a Command (see below) when service restarts.
|
||||||
|
|
||||||
|
writepid <file...>
|
||||||
|
Write the child's pid to the given files when it forks. Meant for
|
||||||
|
cgroup/cpuset usage.
|
||||||
|
|
||||||
|
|
||||||
Triggers
|
Triggers
|
||||||
--------
|
--------
|
||||||
Triggers are strings which can be used to match certain kinds
|
Triggers are strings which can be used to match certain kinds
|
||||||
of events and used to cause an action to occur.
|
of events and used to cause an action to occur.
|
||||||
|
|
||||||
boot
|
boot
|
||||||
This is the first trigger that will occur when init starts
|
This is the first trigger that will occur when init starts
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue