Problem about running script in init.rc

1,031 views
Skip to first unread message

yf...@mobvoi.com

unread,
Jan 4, 2017, 12:04:02 AM1/4/17
to android-platform
For some reasons I need to run a script whenever system property is changed, so I write code like this in init.rc:

on property:persist.sys.proptest=*
    start mytest

service mytest /system/bin/sh /system/etc/mytest.sh ${persist.sys.proptest}
    class main
    user system
    oneshot
    group system
    disabled

but it didn't work, my script get the "${persist.sys.proptest}" string instead of the value of the persist.sys.proptest. I check all the *.rc file and find out that access ${persist.sys.proptest} in service statement seems not working, so I changed code like this:

on property:persist.sys.proptest=*
    /system/bin/sh /system/etc/mytest.sh ${persist.sys.proptest}

this time my script didn't get called at all. But when I checked init.fugu.rc, this code seems works:

on property:init.post_fs_data.bootreason=*
    # Create dump dir and collect dumps. (use the same location as in init.rc)
    mkdir /data/dontpanic 0750 root log

    copy /proc/emmc_ipanic_console /data/dontpanic/ipanic_console
    chown root log /data/dontpanic/ipanic_console
    chmod 0640 /data/dontpanic/ipanic_console

    copy /proc/emmc_ipanic_threads /data/dontpanic/ipanic_threads
    chown root log /data/dontpanic/ipanic_threads
    chmod 0640 /data/dontpanic/ipanic_threads

    copy /proc/emmc_ipanic_gbuffer /data/dontpanic/ipanic_gbuffer
    chown root log /data/dontpanic/ipanic_gbuffer
    chmod 0640 /data/dontpanic/ipanic_gbuffer

    # Clear panic partition
    write /proc/emmc_ipanic_header 1

so what's wrong with my code? Is the mkdir/chown/copy not the real shell command at all? If then, how could I pass the value of persist.sys.proptest to my script?

Chih-Wei Huang

unread,
Jan 16, 2017, 11:39:09 AM1/16/17
to android-platform
The problem is init.rc is not a shell script.
Each command in init.rc must be an init built-in command.
Apparently /system/bin/sh is not.

Use 'exec' to run an external command, like

  exec -- /system/bin/sh ...

Whether if${persist.sys.proptest} is expanded is another problem.
It depends on each built-in command.
You need to read init's code to understand what would be expanded.
In this case, exec won't expand its arguments.

But since you're writing a script, why bother with it?
Just use 'getprop' to read the property in your script.

yf...@mobvoi.com於 2017年1月4日星期三 UTC+8下午1時04分02秒寫道:

Yafei Liu

unread,
Jan 17, 2017, 1:38:01 PM1/17/17
to android-...@googlegroups.com
Thanks for replying, as you say the ${persist.sys.proptest} indeed not a problem, but the exec seems save my life.

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-platform+unsubscribe@googlegroups.com.
To post to this group, send email to android-platform@googlegroups.com.
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages