Android init.rc and exec command not working
Android initialization is managed by the file init.rc (and some other platform specific *.rc files). This file have a special syntax composed by a reduced number of commands that you can read here. One of these command, called "exec", is able, as the name suggest, to execute a single command line during initialization. Based to the help the use of this command is a bit "discouraged" since execution of external command could stop the boot process until the command is finished. However there are situation where such feature is necessary. The problem is that in some Android version this command simply doesn't work...
In my case after a lot of tests thinking I made same mistake in the syntax I discovered with surprise the exec command doesn't work simply because the code was not implemented. To verify if also your platform is affected by this "problem" check the following source file (valid for Android version 4.2.2):
my_android/system/core/init/builtins.c
Look inside the code and search for the function "do_exec". Once found if the body is like the following there is a justified reason exec command doesn't work:
int do_exec(int nargs, char **args) { return -1; }
OK, we found the reason, now simply and the following code and recompile:
int do_exec(int nargs, char **args) { const int cmd_line_max = 256; char cmd_line[cmd_line_max]; int cmd_length, i; cmd_line[0] = '\0'; cmd_length = 0; for(i = 1; i < nargs; i++) { cmd_length += (strlen(args[i]) + 2); if(cmd_length >= cmd_line_max) return -1; strcat(cmd_line, args[i]); strcat(cmd_line, " "); } return system(cmd_line); }
Now exec command should work....
Comments
Post a Comment