通过property_set(“ctl.start”, service_xx);
来启动init.rc中的service是一个很方便方法来调用某个可执行程序或某个脚本程序
service service_xx /system/bin/xx
disabled
oneshot
但在非AID_ROOT、AID_SYSTEM 用户的进程中调用ctl.start ctl.stop会碰到权限问题:
system/core/init/property_service.c
[cpp] view plain copy
/*
- White list of UID that are allowed to start/stop services.
- Currently there are no user apps that require.
*/
struct {
const char *service;
unsigned int uid;
unsigned int gid;
} control_perms[] = {
{ “dumpstate”,AID_SHELL, AID_LOG },
{NULL, 0, 0 }
};
/*
-
Checks permissions for starting/stoping system services.
-
AID_SYSTEM and AID_ROOT are always allowed.
-
Returns 1 if uid allowed, 0 otherwise.
*/
static int check_control_perms(const char *name, int uid, int gid) {
int i;