tycho-kirchner / shournal

Log shell-commands and used files. Snapshot executed scripts. Fully automatic.
GNU General Public License v3.0
173 stars 9 forks source link

Android/bionic support #5

Open tathastu871 opened 2 years ago

tathastu871 commented 2 years ago

if possible patch use of backtrace and prevent using execinfo.h needed Trying to compile and include shournal in termux official repo

tycho-kirchner commented 2 years ago

Hi. This should be possible, but would you mind telling me what exactly your platform is? (; execinfo.h seems to be part of (g)libc on Linux, so I guess it should be available.

tathastu871 commented 2 years ago

Hi. This should be possible, but would you mind telling me what exactly your platform is? (; execinfo.h seems to be part of (g)libc on Linux, so I guess it should be available.

Termux aarch64 on bionic(android)

Wrapping the execinfo.h in

#ifndef __ANDROID__ 
#include <execinfo.h>
#endif 

is current workaround being used for other packages that were built. But in shournal it was producing unidentified/undefined backtrace functions.

Hence developers of termux recommened to patch program to not use execinfo.h and backtrace related functions.

tathastu871 commented 2 years ago

Since smartphones are faster than laptops nowadays with octa core most people use termux as desktop linux replacement.

Linux applications can either be used directly on termux by compiling them as aarch64 and linking with bionic. Or inside proot distros like ubuntu-termux, arch-termux as arm64 binaries.

Hence having shournal on termux is quite beneficial

tathastu871 commented 2 years ago

See this patch https://wiki.termux.com/images/9/9d/OF_5.0_termux.patch all execinfo and backtrace and related functions are enclosed within #ifndef __ANDROID__ .. #endif

tycho-kirchner commented 2 years ago

Wow. Haven't considered porting shournal to Android yet. Just checked: at least fanotify seems to be available in bionic: ./libc/kernel/uapi/linux/fanotify.h. I suspect this is only the tip of the iceberg of compilation problems (did you check?), so if the port is within scope I'd perform that as a common patch series. Would you like to support?

tathastu871 commented 2 years ago

on termux gcc toolchain has many problems. although gcc 9,10,11 are available. Hence all packages are built using clang as CC Missing execinfo.h workaround: src/common/util/util.cpp Around line 211 is function that uses backtrace and execinfo.h enclose it entirely with if endif as shown above. this seems to supress error.

Next error missing stdio_filebuf.h

tycho-kirchner commented 2 years ago

stdio_filebuf.h and referencing functions parseGenericKeyValFile, parseRealUidOf can be removed, they are not used.

tathastu871 commented 2 years ago
/data/data/com.termux/files/home/home/shournal/shournal/src/common/stdiocpp.cpp:20:73: error: member access into incomplete type 'const FILE' (aka 'const __sFILE')
/data/data/com.termux/files/home/home/shournal/shournal/src/common/stdiocpp.cpp:81:12: error: no member named 'fgetc_unlocked' in the global namespace; did you mean simply 'fgetc_unlocked'?
/data/data/com.termux/files/home/home/shournal/shournal/src/common/stdiocpp.cpp:87:28: error: no member named 'fwrite_unlocked' in the global namespace; did you mean simply 'fwrite_unlocked'?
/data/data/com.termux/files/home/home/shournal/shournal/src/common/stdiocpp.cpp:107:12: error: no member named 'fread_unlocked' in the global namespace; did you mean simply 'fread_unlocked'?
4 errors generated.
tycho-kirchner commented 2 years ago

Those are simple. Use the locked ones instead (without _unlocked-suffix) (#ifndef __ANDROID__). I'm setting up an Android VM, so later I'll be able to test myself as well.

tycho-kirchner commented 2 years ago

Before digging further into this, could you please check the following points:

tathastu871 commented 2 years ago

Another tool named fsmon with fanotify and inotify backends is properly working on termux.

tycho-kirchner commented 2 years ago

Another tool named fsmon with fanotify and inotify backends is properly working on termux.

Did you check? Reading this

* inotify (linux / android)
* fanotify (linux > 2.6.36 / android with custom kernel)

implies that while inotify works out of the box, fanotify requires a custom kernel (whatever that means).

See also this SO post.

tathastu871 commented 2 years ago

Another tool named fsmon with fanotify and inotify backends is properly working on termux.

Did you check? Reading this

* inotify (linux / android)
* fanotify (linux > 2.6.36 / android with custom kernel)

implies that while inotify works out of the box, fanotify requires a custom kernel (whatever that means).

Root is required

tycho-kirchner commented 2 years ago

@tathastu871 I just check in my Android x86 virtual machine:

$ zgrep -i fanotify /proc/config.gz
# CONFIG_FANOTIFY is not set

Does your kernel include fanotify support? Otherwise I guess instead of compiling a custom kernel it may be more feasible to rather use shournal's kernel module if and only if the kernel was compiled with CONFIG_TRACEPOINTS=y and CONFIG_FTRACE=y. Is that the case on your machine?

tathastu871 commented 2 years ago

Well my phone is not easily rootable so i cant test it. maybe termux developers can

tycho-kirchner commented 2 years ago

The termux developers can't test whether your phone's kernel supports these features, it may be a vendor-specific compile time option (;

Let's conclude:

shournal requires a rooted phone and most likely a custom kernel or the installation of shournal's kernel module. I don't know the peculiarities of compiling and using a kernel module on Android yet, e.g. does an equivalent to DKMS exist and is module signing mandatory? Among other questions.

These requirements are not trivial, rooting the device can already be a painful process and I'm not sure whether the next installation steps in order to run shournal can be simplified.