Skip to content

Commit f526a73

Browse files
lxc/log.h: use the android log instead of syslog
Use the Android log system instead of syslog Signed-off-by: DreamConnected <[email protected]>
1 parent 33a93b7 commit f526a73

File tree

5 files changed

+79
-12
lines changed

5 files changed

+79
-12
lines changed

.github/workflows/code-test.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,25 @@ jobs:
2626
run: |
2727
sed -i "s|android-ndk-r27c|$ANDROID_NDK_HOME|g" aarch64-android-api30.txt
2828
29-
meson setup build -Dprefix=/data/share -Dinit-script=sysvinit -Druntime-path=/data/local/tmp \
30-
-Dstrip=true -Dd_lto=true -Dlog-path=/data/share/var/log/lxc -Ddata-path=/data/share/lib/lxc \
31-
--localstatedir=/data/share/var -Db_pie=false -Dmemfd-rexec=false --buildtype release \
32-
-Dcapabilities=false -Dseccomp=false -Dselinux=false -Dapparmor=false -Dopenssl=false \
33-
-Ddbus=false --cross-file aarch64-android-api30.txt
34-
29+
meson setup build \
30+
-Dprefix=/data/share \
31+
-Dinit-script=sysvinit \
32+
-Druntime-path=/data/local/tmp \
33+
-Dstrip=true \
34+
-Dd_lto=true \
35+
-Db_pie=false \
36+
-Dlog-path=log/lxc \
37+
-Ddata-path=/data/share/lib/lxc \
38+
--localstatedir=/data/share/var \
39+
-Dmemfd-rexec=true \
40+
--buildtype debug \
41+
-Dcapabilities=false \
42+
-Dseccomp=false \
43+
-Dselinux=false \
44+
-Dapparmor=false \
45+
-Dopenssl=false \
46+
-Ddbus=false \
47+
-Dandroid-log=true \
48+
--cross-file aarch64-android-api30.txt
49+
3550
meson compile -C build

.github/workflows/main.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,28 @@ jobs:
5555
sed -i "s|android-ndk-r27c|$ANDROID_NDK_HOME|g" aarch64-android-api30.txt
5656
export PKG_CONFIG_PATH=/data/sysroot/lib/pkgconfig:/data/sysroot/lib64/pkgconfig:$PKG_CONFIG_PATH
5757
58-
meson setup build -Dprefix=/data/share -Dinit-script=monitd -Druntime-path=/data/local/tmp \
59-
-Dstrip=true -Dd_lto=true -Dlog-path=/data/share/var/log/lxc -Ddata-path=/data/share/lib/lxc \
60-
--localstatedir=/data/share/var -Db_pie=false -Dmemfd-rexec=false --buildtype release \
61-
-Dcapabilities=true -Dseccomp=true -Dselinux=true -Dapparmor=true -Dopenssl=true -Ddbus=false \
62-
-Ddbus=false --cross-file aarch64-android-api30.txt
63-
58+
meson setup build \
59+
-Dprefix=/data/share \
60+
-Dinit-script=monitd \
61+
-Druntime-path=/data/local/tmp \
62+
-Dstrip=true \
63+
-Dd_lto=true \
64+
-Dlog-path=log/lxc \
65+
-Ddata-path=/data/share/lib/lxc \
66+
--localstatedir=/data/share/var \
67+
-Db_pie=false \
68+
-Dmemfd-rexec=false \
69+
--buildtype release \
70+
-Dcapabilities=true \
71+
-Dseccomp=true \
72+
-Dselinux=true \
73+
-Dapparmor=true \
74+
-Dopenssl=true \
75+
-Ddbus=false \
76+
-Ddbus=false \
77+
-Dandroid-log=true \
78+
--cross-file aarch64-android-api30.txt
79+
6480
meson compile -C build
6581
sudo /usr/local/bin/ninja -C build install
6682
echo "RELEASE_TAG=$(meson introspect meson.build --projectinfo | jq -r '.version')-$(git log -1 --format=%h)" >> $GITHUB_ENV

meson.build

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ want_state_dirs = get_option('install-state-dirs')
148148
want_thread_safety = get_option('thread-safety')
149149
want_memfd_rexec = get_option('memfd-rexec')
150150
want_dbus = get_option('dbus')
151+
want_android_log = get_option('android-log')
151152

152153
# Set sysconfdir
153154
fs = import('fs')
@@ -463,6 +464,11 @@ srcconf.set10('HAVE_FMEMOPEN', have)
463464
## Android
464465
have = cc.get_id().contains('clang') and cc.has_header('android/log.h')
465466
srcconf.set10('IS_BIONIC', have)
467+
if want_android_log
468+
liblog = cc.find_library('log')
469+
liblxc_dependencies += liblog
470+
srcconf.set10('USE_ANDROID_LOG', liblog.found())
471+
endif
466472

467473
have = cc.has_function('openpty', dependencies: libutil, prefix: '#include <pty.h>')
468474
srcconf.set10('HAVE_OPENPTY', have)

meson_options.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ option('selinux', type: 'boolean', value: true,
7575
option('tests', type: 'boolean', value: false,
7676
description: 'build and install tests')
7777

78+
# not in autotools
79+
option('android-log', type: 'boolean', value: true,
80+
description: 'Use android log management')
81+
7882
# Paths
7983
# was --apparmor-cache-dir in autotools
8084
option('apparmor-cache-path', type: 'string', value: 'cache/lxc/apparmor',

src/lxc/log.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
#define LXC_LOG_PREFIX_SIZE 32
3030
#define LXC_LOG_BUFFER_SIZE 4096
3131

32+
#ifndef LXC_LOG_TAG
33+
#define LXC_LOG_TAG "lxc"
34+
#endif
35+
36+
#ifdef USE_ANDROID_LOG
37+
#include <android/log.h>
38+
#endif
39+
3240
/* predefined lxc log priorities. */
3341
enum lxc_loglevel {
3442
LXC_LOG_LEVEL_TRACE,
@@ -392,6 +400,9 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
392400
#if (defined(__GNU_LIBRARY__) || defined(__MUSL__)) && !ENABLE_COVERITY_BUILD
393401
#define SYSTRACE(format, ...) \
394402
TRACE("%m - " format, ##__VA_ARGS__)
403+
#elif IS_BIONIC && USE_ANDROID_LOG
404+
#define SYSTRACE(format, ...) \
405+
__android_log_print(ANDROID_LOG_VERBOSE, LXC_LOG_TAG, format, ##__VA_ARGS__)
395406
#else
396407
#define SYSTRACE(format, ...) \
397408
do { \
@@ -403,6 +414,9 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
403414
#if (defined(__GNU_LIBRARY__) || defined(__MUSL__)) && !ENABLE_COVERITY_BUILD
404415
#define SYSDEBUG(format, ...) \
405416
DEBUG("%m - " format, ##__VA_ARGS__)
417+
#elif IS_BIONIC && USE_ANDROID_LOG
418+
#define SYSDEBUG(format, ...) \
419+
__android_log_print(ANDROID_LOG_DEBUG, LXC_LOG_TAG, format, ##__VA_ARGS__)
406420
#else
407421
#define SYSDEBUG(format, ...) \
408422
do { \
@@ -415,6 +429,9 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
415429
#if (defined(__GNU_LIBRARY__) || defined(__MUSL__)) && !ENABLE_COVERITY_BUILD
416430
#define SYSINFO(format, ...) \
417431
INFO("%m - " format, ##__VA_ARGS__)
432+
#elif IS_BIONIC && USE_ANDROID_LOG
433+
#define SYSINFO(format, ...) \
434+
__android_log_print(ANDROID_LOG_INFO, LXC_LOG_TAG, format, ##__VA_ARGS__)
418435
#else
419436
#define SYSINFO(format, ...) \
420437
do { \
@@ -426,6 +443,9 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
426443
#if (defined(__GNU_LIBRARY__) || defined(__MUSL__)) && !ENABLE_COVERITY_BUILD
427444
#define SYSNOTICE(format, ...) \
428445
NOTICE("%m - " format, ##__VA_ARGS__)
446+
#elif IS_BIONIC && USE_ANDROID_LOG
447+
#define SYSNOTICE(format, ...) \
448+
__android_log_print(ANDROID_LOG_INFO, LXC_LOG_TAG, format, ##__VA_ARGS__)
429449
#else
430450
#define SYSNOTICE(format, ...) \
431451
do { \
@@ -437,6 +457,9 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
437457
#if (defined(__GNU_LIBRARY__) || defined(__MUSL__)) && !ENABLE_COVERITY_BUILD
438458
#define SYSWARN(format, ...) \
439459
WARN("%m - " format, ##__VA_ARGS__)
460+
#elif IS_BIONIC && USE_ANDROID_LOG
461+
#define SYSWARN(format, ...) \
462+
__android_log_print(ANDROID_LOG_WARN, LXC_LOG_TAG, format, ##__VA_ARGS__)
440463
#else
441464
#define SYSWARN(format, ...) \
442465
do { \
@@ -448,6 +471,9 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
448471
#if (defined(__GNU_LIBRARY__) || defined(__MUSL__)) && !ENABLE_COVERITY_BUILD
449472
#define SYSERROR(format, ...) \
450473
ERROR("%m - " format, ##__VA_ARGS__)
474+
#elif IS_BIONIC && USE_ANDROID_LOG
475+
#define SYSERROR(format, ...) \
476+
__android_log_print(ANDROID_LOG_ERROR, LXC_LOG_TAG, format, ##__VA_ARGS__)
451477
#else
452478
#define SYSERROR(format, ...) \
453479
do { \

0 commit comments

Comments
 (0)