简体   繁体   English

如何在/init.rc中创建服务?

[英]How to create a service in /init.rc?

Following the example given in this post , I added these lines to /init.rc: 继在给出的示例这个帖子 ,我添加了这些行/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

And this /system/bin/bc_handler.sh: 而这个/system/bin/bc_handler.sh:

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

I'm building Android 8.0 for the emulator. 我正在为模拟器构建Android 8.0。 When the system starts, I can see that the script didn't run, and this message is seen in the logs: 系统启动时,我可以看到脚本没有运行,并且在日志中可以看到此消息:

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

I tried changing my service to look like this: 我尝试将服务更改为如下形式:

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

and now the error is 现在的错误是

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

Is there any documentation on how one adds a new service to Android under SELinux? 有没有关于如何在SELinux下向Android添加新服务的文档? Or documentation on how to disable SELinux on Android? 或有关如何在Android上禁用SELinux的文档? I've been googling for hours, and all of the information I'm finding seems to be obsolete. 我已经搜寻了几个小时,发现的所有信息似乎都已过时。

You can disable SELinux by setting permissive mode on your running platform 您可以通过在运行的平台上设置许可模式来禁用SELinux。

In permissive mode, selinux will only dump warning message 在许可模式下,selinux将仅转储警告消息

By default, it's in enforcing mode , where any SELinux violation will be denied. 默认情况下,它处于强制模式 ,其中任何SELinux违规都会被拒绝。


To add a service, you should add file context in file_context, and write a .te file for your service 要添加服务,您应该在file_context中添加文件上下文,并为您的服务编写一个.te文件。

Here is a basic example and you can dig into more about SELinux 是一个基本示例,您可以深入了解SELinux。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM