简体   繁体   English

从android init.rc执行静态程序

[英]executing static program from android init.rc

I want to start a custom program in the init process. 我想在init进程中启动一个自定义程序。 I compiled this program statically that run fine from my booted up android stock ROM. 我静态地编译了这个程序,从我启动的android stock ROM中运行良好。

From the android init.rc docs I read that the exec command is what I need. 从android init.rc文档我读到exec命令是我需要的。
BTW all I can see in dmesg is that my program exit with code -1 (I can't return that). 顺便说一句,我在dmesg中看到的是我的程序以代码-1退出(我无法返回)。

init.rc snippet: init.rc片段:

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

All I see in dmesg is this: 我在dmesg看到的就是:

<4>[    6.336816] launching test
<6>[    6.336902] init: command 'write' r=0
<6>[    6.337115] init: command 'exec' r=-1

Here you are the executable source code: http://pastebin.com/Hym1APWx 在这里,您是可执行的源代码: http//pastebin.com/Hym1APWx


UPDATE UPDATE

I tried to statically compile and run this program: 我试图静态编译并运行这个程序:

int main(){return 0; }

But the result is always command 'exec' r=-1 . 但结果总是command 'exec' r=-1 Maybe user uselen are right, maybe I cannot run executables from /data in the early-boot phase. 也许用户uselen是对的,也许我不能在早期启动阶段从/data运行可执行文件。

As christian said, it looks like exec isn't even implemented. 正如克里斯蒂安所说,看起来exec甚至没有实现。 I'm beginning to think that a lot of features documented for init.rc aren't implemented. 我开始认为init.rc记录的很多功能都没有实现。 Here's a way you can get your program to launch however. 这是您可以启动程序的方法。

Instead of running this as an "exec" command, set this up as a service instead. 而不是将其作为“exec”命令运行,而是将其设置为服务。

In your init.rc, or another file included by it: 在您的init.rc或其中包含的其他文件中:

service my_service /data/test
    class main
    oneshot 

If it's in class main, and not disabled, it should run after /data is mounted. 如果它在类main中,而不是禁用,它应该在/ data挂载后运行。

I had the same issue today. 我今天遇到了同样的问题。 In my case the solution was simple: The exec function wasn't implemented yet and contained just a return -1 . 在我的例子中,解决方案很简单: exec函数尚未实现,只包含一个return -1 You should take a look at builtin.c and search for do_exec() . 你应该看看builtin.c并搜索do_exec() This code is executed when init.rc contains an exec statement. init.rc包含exec语句时,将执行此代码。

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

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