Nicholas Lim
Nicholas Lim

Reputation: 137

Unable to execute daemon on boot within init.rc

I have created a daemon but is unable to run it in my Nexus 5 running on Marshmallow.

Following is the code edited in init.rc

on init
    chmod 777 /sbin/check_usb
    chown root root /sbin/check_usb

service disableadb /sbin/check_usb
    class main 
    seclabel u:r:disableadb:s0

Following is my entry edited within init.usb.rc such that when an adb connection is detected , my daemon will be executed

on property:sys.usb.config=accessory,adb && property:sys.usb.configfs=0
start disableadb

I have inserted my check_usb program under /sbin/system and granted chmod 777 access to it.

However I notice that in the dmesg | grep disableadb output, my daemon was unable to be executed with the error as follows:

init : cannot setexeccon ('u:r:disableadb:s0') Invalid argument

Upvotes: 1

Views: 4379

Answers (1)

Mahesh
Mahesh

Reputation: 11

This error might be due to sepolicy issue. Your newly added service might not have correct sepolicy configuration.

Add sepolicy rules for this. create below files.

Create directory device/xxx/.../sepolicy/check_usb

Inside, create file file_contexts

/sbin/check_usb             u:object_r:disableadb:s0

Create file: check_usb.te

# check_usb service
type check_usb, domain;
type check_usb_exec, exec_type, file_type;

init_daemon_domain(check_usb)

allow init check_usb:process transition;

Add this directory in your BoardConfig.mk

BOARD_SEPOLICY_DIRS += device/xxx/.../sepolicy/check_usb

Upvotes: 1

Related Questions