6

I am trying to execute a daemon on boot of my Nexus 5. This is a daemon built from source in c++. But whenever I build AOSP and flash the images on my Nexus 5 device, the daemon is not running in the background. I added this code to my init.rc file: (which should make it run in the background on boot)

setenforce 0
service my_daemon /system/bin/my_daemon 
    class main     # Also tried: class core (but it didn't make a difference)
    user root
    group root
setenforce 1

The reason I use setenfonce is because of SELinux on Android 5.0 and above. The problem is that on boot, the daemon is not running on boot. I don't have any clue as to why. Any suggestions?

Redson
  • 2,098
  • 4
  • 25
  • 50
  • Did you chance this in the compressed ramdisk image packed alongside the kernel in the boot partition? Simply chaning it at runtime won't persist. Another way of asking is can you verify that your change to init.rc is there after boot, and similarly that your binary is there with all its dependencies and executable? – Chris Stratton Mar 18 '15 at 21:53
  • @ChrisStratton On boot, `my_daemon` is located in the system/bin directory in adb shell. But it is not running in the background as it is supposed to. – Redson Mar 19 '15 at 13:30

1 Answers1

3

I got the same issue with nexus 9. I added code to device/htc/flounder/init.flounder.rc but doesnt work.

service pollingclient /system/bin/sh logwrapper
    class late_start
    user root
    group root
    oneshot

on property:dev.bootcomplete=1
    start pollingclient

My quick fix is added code to start my daemon in system/core/adb/adb_auth_client.c after fdevent_add(&t->auth_fde, FDE_READ);

kill_if_exist_service("mydaemon");
system("sleep 5; mydaemon");

It works but its some kind of "quick fix". I am still investigating right solution.

update: I disable selinux by edit ./arch/arm64/configs/flounder_defconfig set CONFIG_SECURITY_SELINUX=n then recompile kernel and recompile boot.img. Wow, it works!

nguyentran
  • 458
  • 2
  • 14
  • Make sure your module name is no more than 16 characters and only alphanumeric and or "-" or "_" characters. Also make sure you are editing the correct .rc file or use LOCAL_INIT_RC variable in the build file to specify a .rc file for you module. – Chef Pharaoh Sep 29 '16 at 17:33