Eternity
Eternity

Reputation: 41

How to read and run conditional statement in Android init.rc

I have a requirement where I need to read an interface (say /sys/module/my_file/parameters/val) and then based on its value write some value on another interface. This has to be done in init.rc of Android filesystem.

flow would be like this

if ( read /sys/module/my_file/parameters/val == "yes") then
write /sys/devices/platform/target_file/val 100

Can anybody help me to do the same?? Is it possible??

Upvotes: 1

Views: 5055

Answers (2)

Gopinath Srinivasan
Gopinath Srinivasan

Reputation: 125

You can use init’s service concept for running a script. Below is the code sample form init script.rc file.

chmod 0750 /system/bin/myscript.sh
start script
[...]
service script /system/bin/myscript.sh
    class main
    user root
    group root
    oneshot

Upvotes: 0

Frank Meerkötter
Frank Meerkötter

Reputation: 2868

You can implement this using an exec stanza:

exec <path> [ <argument> ]*
   Fork and execute a program (<path>). This will block until
   the program completes execution. It is best to avoid exec
   as unlike the builtin commands, it runs the risk of getting
   init "stuck".

See https://github.com/android/platform_system_core/blob/master/init/readme.txt for the details.

Example: Move your code into a script (my_script.sh). Add this to your init.rc

on boot:
  ...
  exec /path/to/my_script.sh

Upvotes: 1

Related Questions