我想在init过程中启动一个自定义程序。我静态编译了这个程序,从我启动的android股票rom运行良好。
从androidinit.rc文档中,我了解到exec命令是我所需要的。
顺便说一句,我在dmesg中看到的是,我的程序以代码-1退出(我不能返回该代码)。
init.rc片段:

on post-fs-data
write /dev/kmsg "launching test"
exec /data/test

我在dmesg中看到的是:
<4>[    6.336816] launching test
<6>[    6.336902] init: command 'write' r=0
<6>[    6.337115] init: command 'exec' r=-1

这是可执行的源代码:http://pastebin.com/Hym1APWx
更新
我试图静态编译并运行此程序:
int main(){return 0; }

但结果总是command 'exec' r=-1。也许用户uselen是对的,也许我不能在启动早期从/data运行可执行文件。

最佳答案

正如christian所说,看起来exec甚至都没有实现。我开始认为,为init.rc记录的许多特性没有实现。不过,这里有一种方法可以让你的程序启动。
与其将其作为“exec”命令运行,不如将其设置为服务。
在in it.rc或它包含的其他文件中:

service my_service /data/test
    class main
    oneshot

如果它在类main中,并且没有被禁用,那么它应该在/data挂载之后运行。

08-18 12:16
查看更多