user672033
user672033

Reputation:

How do I view debug output from a shell script started in init.rc in Android?

I've created a shell script, test.sh, which runs as a service in Android's init.rc. The script runs, but if I try to echo anything, I see no output in the console. I can write debug output from init.rc using:

write /dev/kmsg "running test script"

But if I do an

echo "test output"

from within test.sh I see nothing in the console or in logcat.

Any ideas?

Thanks

Marlon

Edit: Here's the script I'm testing with:

#!/system/bin/sh 
echo "Testing!"

And the relevant lines in init.rc:

chown system system /data/test.sh
chmod 0774 /data/test.sh

# Periodic service test
service periodic_test /data/test.sh
class main

Upvotes: 3

Views: 4204

Answers (1)

Shmil The Cat
Shmil The Cat

Reputation: 4668

Android init "framework" forks the process specified services within the init.xxx.rc files when their stdout is redirected to /dev/null so you won't see your debug prints on the console.

Please note console and logcat are orthogonal, echo "bla" won't be reflected in logcat even in plain shell scripts not invoked by the init process.

Possible tracing approaches is as you did for the dmesg or using native code (to be called from the script) which interfaces w/ logcat

Upvotes: 1

Related Questions