通过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
只有uid == AID_SYSTEM || uid == AID_ROOT
或符合 control_perms[] = {
{ "dumpstate",AID_SHELL, AID_LOG },
{NULL, 0, 0 }
}; 的uid进程才有权限star/stop services
因此,如果我们碰到了权限问题,根据log提示,在/system/core/include/private/android_filesystem_config.h
中查到进程定义,添加到control_perms[]列表
比如,uid ==AID_WIFI的某个程序需要权限启动service_xx
control_perms[] = {
{ "dumpstate",AID_SHELL, AID_LOG },
+ { "service_xx",AID_WIFI, AID_WIFI},
{NULL, 0, 0 }
};