ITPub博客

首页 > > > Service xxx does not have a SELinux domain defined

Service xxx does not have a SELinux domain defined

作者:dapan 时间:2018-11-07 09:11:00 0 删除 编辑

为了完成公司项目的一个需求,需要添加一个shell脚本服务xxx,并且设置成开机自启动。于是我在init.rc中添加了如下代码行:

service xxx /system/bin/xxx
    class main
    user root

编译boot后烧到手机,发现服务xxx无法启动,kernel log中有如下提示:

[ 20.076354s][pid:1,cpu7,init]init: Service xxx does not have a SELinux domain defined.


该提示说明没有定义SELinux domain,导致服务xxx无法自启动。为了解决这个问题我们按如下方式修改或添加sepolicy文件:


1、修改seplicy/file_contexts文件,添加以下内容:

/system/bin/xxx u:object_r:xxx_exec:s0

因为是shell脚本,所以这里编写的时候,要写上对应的sh全名

diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts
index 3e7c610..8ac09f9 100755
--- a/sepolicy/file_contexts
+++ b/sepolicy/file_contexts
@@ -65,6 +65,8 @@
 
 #for evergrande_start service
 /system/bin/evergrande_start.sh   u:object_r:evergrande_start_exec:s0
+#for factory check data file system
+/system/bin/factory_c.sh          u:object_r:factory_c_exec:s0
 
 #hdmi

2、新增xxx.te文件,并在其中添加如下内容:

需要为新增的进程增加域、执行权限

type xxx, domain;
type xxx_exec, exec_type, file_type;

然后启用这个域

init_daemon_domain(xxx)


验证,原则上修改SELinux的问题需要全编译,为了节省时间可以使用以下方法调试

  • 编译bootimage
  • 烧录bootimage
  • 执行adb remount
  • 执行adb shell restorecon system/bin/xxx
  • 重启手机,查看kernel log中是否成功启动xxx服务


注意!!上面的restorecon一直要执行,要不就全烧系统,不然selinux权限不生效,切记


参考:

Android5.1 在init.rc 中添加自己的服务

原文作者:;如有侵权,请联系管理员删除。

请登录后发表评论 登录
全部评论

注册时间:2020-08-07

  • 博文量
    4504
  • 访问量
    87098