diff options
author | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2020-05-15 12:24:36 +0100 |
---|---|---|
committer | Carsten Haitzler (Rasterman) <raster@rasterman.com> | 2020-05-18 09:36:55 +0100 |
commit | fe56edae3f5015c62e319d5e2ab2552d3533eead (patch) | |
tree | 2a1830f8efed44c0cd7759c893c3de60ff6fca55 /src/lib/eina | |
parent | f026000c1eb3967ad123c2239aeb7db3ce70dbf6 (diff) | |
download | efl-fe56edae3f5015c62e319d5e2ab2552d3533eead.tar.gz |
systemd - make libsystemd use/supprot entirely runtime "dlopened"
so i've moved all systemd and elogind support to be runtime only with
dlopen (eina_module) of libsystemd.so.0 (or libelogind.so.0 for elput)
and finding of symbols manually at runtime (if the right code paths or
env vars are set), thus remvoing the need to decide at compile time if
efl needs systemd support or not as it no longer needs systemd
headers/libs at compile time and just at runtime. this simplifies
building a bit and makes efl more adaptive to the final target system
at runtime.
Diffstat (limited to 'src/lib/eina')
-rw-r--r-- | src/lib/eina/eina_log.c | 79 | ||||
-rw-r--r-- | src/lib/eina/meson.build | 7 |
2 files changed, 58 insertions, 28 deletions
diff --git a/src/lib/eina/eina_log.c b/src/lib/eina/eina_log.c index 7c66ee0b53..4cd634bd72 100644 --- a/src/lib/eina/eina_log.c +++ b/src/lib/eina/eina_log.c @@ -29,10 +29,6 @@ #include <assert.h> #include <errno.h> -#ifdef HAVE_SYSTEMD -# include <systemd/sd-journal.h> -#endif - #ifdef _WIN32 # include <windows.h> #endif @@ -51,6 +47,7 @@ #include "eina_thread.h" #include "eina_convert.h" #include "eina_strbuf.h" +#include "eina_module.h" /* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */ #include "eina_safety_checks.h" @@ -2091,6 +2088,43 @@ eina_log_print_cb_stdout(const Eina_Log_Domain *d, #endif } +#ifdef HAVE_SYSTEMD +static Eina_Module *_libsystemd = NULL; +static Eina_Bool _libsystemd_broken = EINA_FALSE; + +static int (*_eina_sd_journal_send_with_location) (const char *file, const char *line, const char *func, const char *format, ...) = NULL; + +static void +_eina_sd_init(void) +{ + if (_libsystemd_broken) return; + _libsystemd = eina_module_new("libsystemd.so.0"); + if (_libsystemd) + { + if (!eina_module_load(_libsystemd)) + { + eina_module_free(_libsystemd); + _libsystemd = NULL; + } + } + if (!_libsystemd) + { + _libsystemd_broken = EINA_TRUE; + return; + } + _eina_sd_journal_send_with_location = + eina_module_symbol_get(_libsystemd, "sd_journal_send_with_location"); + if (!_eina_sd_journal_send_with_location) + { + _eina_sd_journal_send_with_location = NULL; + eina_module_free(_libsystemd); + _libsystemd = NULL; + _libsystemd_broken = EINA_TRUE; + } +} + +#endif + EAPI void eina_log_print_cb_journald(const Eina_Log_Domain *d, Eina_Log_Level level, @@ -2108,6 +2142,9 @@ eina_log_print_cb_journald(const Eina_Log_Domain *d, Eina_Thread cur; int r; + _eina_sd_init(); + if (!_eina_sd_journal_send_with_location) goto nosystemd; + r = asprintf(&file_prefixed, "CODE_FILE=%s", file); if (r == -1) { @@ -2134,12 +2171,12 @@ eina_log_print_cb_journald(const Eina_Log_Domain *d, #ifdef EINA_LOG_BACKTRACE if (EINA_LIKELY(level > _backtrace_level)) #endif - sd_journal_send_with_location(file_prefixed, line_str, fnc, - "PRIORITY=%i", level, - "MESSAGE=%s", message, - "EFL_DOMAIN=%s", d->domain_str, - "THREAD=%lu", cur, - NULL); + _eina_sd_journal_send_with_location(file_prefixed, line_str, fnc, + "PRIORITY=%i", level, + "MESSAGE=%s", message, + "EFL_DOMAIN=%s", d->domain_str, + "THREAD=%lu", cur, + NULL); #ifdef EINA_LOG_BACKTRACE else { @@ -2159,14 +2196,14 @@ eina_log_print_cb_journald(const Eina_Log_Domain *d, else eina_strbuf_append_printf(bts, "[%s], ", strings[i]); - sd_journal_send_with_location(file_prefixed, line_str, fnc, - "PRIORITY=%i", level, - "MESSAGE=%s", message, - "EFL_DOMAIN=%s", d->domain_str, - "THREAD=%lu", cur, - "BACKTRACE=%s", - eina_strbuf_string_get(bts), - NULL); + _eina_sd_journal_send_with_location(file_prefixed, line_str, fnc, + "PRIORITY=%i", level, + "MESSAGE=%s", message, + "EFL_DOMAIN=%s", d->domain_str, + "THREAD=%lu", cur, + "BACKTRACE=%s", + eina_strbuf_string_get(bts), + NULL); eina_strbuf_free(bts); free(strings); } @@ -2176,10 +2213,10 @@ finish: free(file_prefixed); free(line_str); free(message); - -#else - eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, data, args); + return; +nosystemd: #endif + eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, data, args); } EAPI void diff --git a/src/lib/eina/meson.build b/src/lib/eina/meson.build index 1104ae74c7..ce7cfe84f1 100644 --- a/src/lib/eina/meson.build +++ b/src/lib/eina/meson.build @@ -265,14 +265,7 @@ if default_mempool endif if get_option('systemd') == true - systemd = dependency('libsystemd') - eina_deps += systemd config_h.set('HAVE_SYSTEMD', '1') - if systemd.version().version_compare('>=209') - config_h.set('HAVE_SYSTEMD_LOGIN_209', '1') - endif -else - systemd = [] endif |