需要添加一个服务xxx,并且设置成开机自启动。于是我在 init.rc 中添加了如下代码行:
--- a/conf/init.rc
+++ b/conf/init.rc
@@ -6,6 +6,8 @@ on early-init
on init
+ start watchdogd
+
# See storage config details at http://source.android.com/tech/storage/
mkdir /storage/sdcard 0000 root root
mkdir /storage/usb1 0000 root root
@@ -584,6 +586,10 @@ on property:meizu.wifi.test=stop
stop wifi_test_mode
####wifi test end
+# Set watchdog timer to 30 seconds and pet it every 10 seconds to get a 20 second margin
+service watchdogd /sbin/watchdogd 10 20
+ class core
+
# on userdebug and eng builds, enable kgdb on the serial console
on property:ro.debuggable=1
write /sys/module/kgdboc/parameters/kgdboc ttyFIQ1
编译 boot.img 后烧到手机,发现服务 watchdogd 无法启动,logcat 未发现异常,kernel log 中有如下提示:
1] init: Service watchdogd does not have a SELinux domain defined.
该提示说明没有定义 SELinux domain,导致服务 watchdogd 无法自启动。为了解决这个问题我们按如下方式修改或添加 sepolicy 文件:
修改 system/seplicy/file_contexts 文件,添加以下内容:
/sbin/watchdogd u:object_r:watchdogd_exec:s0
新增 watchdogd.te 文件(本来就有),并在其中添加如下内容:
需要为新增的进程增加域、执行权限
type watchdogd, domain;
type watchdogd_exec, exec_type, file_type;
然后启用这个域
init_daemon_domain(watchdogd)
验证,原则上修改 SELinux的 问题需要全编译。 发现还是不行。需要加上:
seclabel u:r:watchdogd:s0
# Set watchdog timer to 30 seconds and pet it every 10 seconds to get a 20 second margin
service watchdogd /sbin/watchdogd 10 20
class core
seclabel u:r:watchdogd:s0