c++linuxandroid-ndkportingrooted-device

What are corresponding directories on Android for common Linux pathnames?


I'm porting the C++ myToll Linux application to run on Android using NDK r10d. (Note this is not an Android app with an apk, but a utility tool to run from the shell.) This is a command line interface and has no GUI and is being built as a standalone application with the NDK.

On Linuxes such as Centos 5, the tool reads and writes to the following standard directory locations:

/var/run/myTool/   (read/write)
/var/log/myTool/   (read/write)
/etc/myTool/       (read only)
/tmp/              (read-write)

The myTool is installed in /system/xbin/myTool and can run on a rooted android phone as a utility from the shell, but fails to access these same locations at runtime, even when run as root.

What would be the corresponding locations to use on an android system that the myTool will have sufficient permissions to write too and is where such files would common be expected to be found on Android? Are there any locations that can be created by root such that myTool can use them at runtime without being root?


Solution

  • Referring to the Android stackexchange answer offered by ferzco, I settled on the following solution that works on my rooted Samsung Galaxy S4:

    /var/run/myTool/  =>  /data/log/myTool/run/
    /var/log/myTool/  =>  /data/log/myTool/log/
    /etc/myTool/      =>  /etc/myTool/
    /tmp/             =>  /data/local/tmp/myTool/
    

    I used /data/log/myTool as the base for two of the directories and /data/local/tmp for a third because they were the only ones I could find that offered write permission to myTool when not su(ed) to root. I needed root to set up the myTool subdirectories during installation, but once the myTool directories are created and chmod 777 myTool as root, the user no longer needs to be root to write to those subdirectories. For the fourth, /etc/myTool, because myTool only needs to read information from /etc at runtime, I left it in the existing /etc directory since it was readable (although not writable) by the user once created and I was able to configure it as required up front as root.