【问题标题】:How to create a service in /init.rc?如何在 /init.rc 中创建服务?
【发布时间】:2019-04-03 01:12:31
【问题描述】:

按照this post 中给出的示例,我将这些行添加到/init.rc:

on property:dev.bootcomplete=1
    start boot_handler

service boot_handler /system/bin/bc_handler.sh
    class main
    user root
    group root
    disabled
    oneshot

还有这个/system/bin/bc_handler.sh:

#!/system/bin/sh
echo hi > /data/local/hi.txt

我正在为模拟器构建 Android 8.0。当系统启动时,我可以看到脚本没有运行,并且在日志中看到了这条消息:

[  217.280853] init: service boot_handler does not have a SELinux domain defined

我尝试将我的服务更改为如下所示:

service boot_handler /system/bin/sh /system/bin/bc_handler.sh
    class main
    user root
    group root
    disabled
    oneshot
    seclabel u:r:shell:s0

现在错误是

init: Service 'boot_handler' (pid 1729) killed by signal 1

是否有关于如何在 SELinux 下向 Android 添加新服务的文档?或有关如何在 Android 上禁用 SELinux 的文档?我已经用谷歌搜索了几个小时,我发现的所有信息似乎都已经过时了。

【问题讨论】:

    标签: android android-source selinux


    【解决方案1】:

    您可以通过在您的运行平台上设置许可模式来禁用 SELinux

    在permissive模式下,selinux只会转储警告信息

    默认情况下,它处于强制模式,任何违反 SELinux 的行为都将被拒绝。


    要添加服务,您应该在file_context中添加文件上下文,并为您的服务编写一个.te文件

    Here 是一个基本示例,您可以深入了解有关 SELinux 的更多信息

    【讨论】:

    • 我的问题是我无法在 Oreo 下将 SELinux 设置为 permissive。据称,您可以通过编辑正确的 BoardConfig.mk 文件在引导命令行参数中设置它,但我永远无法让它工作。我最终将我的服务设置为在启动过程中启动得相当晚,然后我会在我的服务启动之前手动设置并设置许可模式。
    • 您可以检查是否有任何构建选项来启用许可模式;或者尽可能在引导加载程序中设置许可模式。
    猜你喜欢
    • 2014-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    相关资源
    最近更新 更多