Service xxx does not have a SELinux domain defined

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/l460133921/article/details/72891678

为了完成公司项目的一个需求,需要添加一个binder服务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文件:

  • 修改seplicy/file_contexts文件,添加以下内容:
  • /system/bin/xxx     u:object_r:xxx_exec:s0

  • 新增xxx.te文件,并在其中添加如下内容:
  • 需要为新增的进程增加域、执行权限
    type xxx, domain;
    type xxx_exec, exec_type, file_type;
    然后启用这个域
    init_daemon_domain(xxx)

  • 验证,原则上修改SELinux的问题需要全编译,为了节省时间可以使用以下方法调试
    1. 编译bootimage
    2. 烧录bootimage
    3. 执行adb remount
    4. 执行adb shell restorecon system/bin/xxx
    5. 重启手机,查看kernel log中是否成功启动xxx服务

    猜你喜欢

    转载自blog.csdn.net/l460133921/article/details/72891678