summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-05-15 12:24:36 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-05-18 09:36:55 +0100
commitfe56edae3f5015c62e319d5e2ab2552d3533eead (patch)
tree2a1830f8efed44c0cd7759c893c3de60ff6fca55
parentf026000c1eb3967ad123c2239aeb7db3ce70dbf6 (diff)
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.
-rw-r--r--meson_options.txt8
-rw-r--r--src/lib/ecore/ecore.c47
-rw-r--r--src/lib/ecore/ecore_main.c12
-rw-r--r--src/lib/ecore/ecore_private.h6
-rw-r--r--src/lib/ecore/meson.build4
-rw-r--r--src/lib/ecore_con/ecore_con.c67
-rw-r--r--src/lib/ecore_con/ecore_con_local.c4
-rw-r--r--src/lib/ecore_con/ecore_con_private.h7
-rw-r--r--src/lib/ecore_con/efl_net_server_fd.c6
-rw-r--r--src/lib/ecore_con/meson.build2
-rw-r--r--src/lib/ecore_drm/ecore_drm_logind.c72
-rw-r--r--src/lib/ecore_drm/ecore_drm_private.h4
-rw-r--r--src/lib/eina/eina_log.c79
-rw-r--r--src/lib/eina/meson.build7
-rw-r--r--src/lib/elput/elput_logind.c83
-rw-r--r--src/lib/elput/elput_manager.c2
-rw-r--r--src/lib/elput/elput_private.h8
-rw-r--r--src/lib/elput/meson.build6
18 files changed, 319 insertions, 105 deletions
diff --git a/meson_options.txt b/meson_options.txt
index 043957e046..0d07d396fc 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -128,7 +128,7 @@ option('gstreamer',
128option('systemd', 128option('systemd',
129 type : 'boolean', 129 type : 'boolean',
130 value : true, 130 value : true,
131 description : 'Systemd support in efl' 131 description : 'Systemd and Elogind support at runtime in efl'
132) 132)
133 133
134option('pulseaudio', 134option('pulseaudio',
@@ -334,12 +334,6 @@ option('native-arch-optimization',
334 description: 'Enable architecture native optimizations in efl' 334 description: 'Enable architecture native optimizations in efl'
335) 335)
336 336
337option('elogind',
338 type : 'boolean',
339 value : false,
340 description : 'elogind support in efl (subset of systemd)'
341)
342
343option('windows-version', 337option('windows-version',
344 type : 'combo', 338 type : 'combo',
345 choices : ['vista', 'win7', 'win8', 'win81', 'win10'], 339 choices : ['vista', 'win7', 'win8', 'win81', 'win10'],
diff --git a/src/lib/ecore/ecore.c b/src/lib/ecore/ecore.c
index 3110c5ef54..ce5bf6e62a 100644
--- a/src/lib/ecore/ecore.c
+++ b/src/lib/ecore/ecore.c
@@ -313,9 +313,7 @@ ecore_init(void)
313#ifdef HAVE_SYSTEMD 313#ifdef HAVE_SYSTEMD
314 if (getenv("WATCHDOG_USEC")) 314 if (getenv("WATCHDOG_USEC"))
315 { 315 {
316 double sec; 316 double sec = ((double) atoi(getenv("WATCHDOG_USEC"))) / 1000 / 1000;
317
318 sec = ((double) atoi(getenv("WATCHDOG_USEC"))) / 1000 / 1000;
319 317
320 _systemd_watchdog = 318 _systemd_watchdog =
321 efl_add(EFL_LOOP_TIMER_CLASS, efl_main_loop_get(), 319 efl_add(EFL_LOOP_TIMER_CLASS, efl_main_loop_get(),
@@ -326,7 +324,6 @@ ecore_init(void)
326 unsetenv("WATCHDOG_USEC"); 324 unsetenv("WATCHDOG_USEC");
327 325
328 INF("Setup systemd watchdog to : %f", sec); 326 INF("Setup systemd watchdog to : %f", sec);
329
330 _systemd_watchdog_cb(NULL, NULL); 327 _systemd_watchdog_cb(NULL, NULL);
331 } 328 }
332#endif 329#endif
@@ -962,7 +959,11 @@ _ecore_fps_debug_runtime_add(double t)
962static void 959static void
963_systemd_watchdog_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED) 960_systemd_watchdog_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
964{ 961{
965 sd_notify(0, "WATCHDOG=1"); 962 if (getenv("NOTIFY_SOCKET"))
963 {
964 _ecore_sd_init();
965 if (_ecore_sd_notify) _ecore_sd_notify(0, "WATCHDOG=1");
966 }
966} 967}
967#endif 968#endif
968 969
@@ -1122,3 +1123,39 @@ ecore_memory_state_set(Ecore_Memory_State state)
1122 _ecore_memory_state = state; 1123 _ecore_memory_state = state;
1123 ecore_event_add(ECORE_EVENT_MEMORY_STATE, NULL, NULL, NULL); 1124 ecore_event_add(ECORE_EVENT_MEMORY_STATE, NULL, NULL, NULL);
1124} 1125}
1126
1127#ifdef HAVE_SYSTEMD
1128static Eina_Module *_libsystemd = NULL;
1129static Eina_Bool _libsystemd_broken = EINA_FALSE;
1130
1131int (*_ecore_sd_notify) (int unset_environment, const char *state) = NULL;
1132
1133void
1134_ecore_sd_init(void)
1135{
1136 if (_libsystemd_broken) return;
1137 _libsystemd = eina_module_new("libsystemd.so.0");
1138 if (_libsystemd)
1139 {
1140 if (!eina_module_load(_libsystemd))
1141 {
1142 eina_module_free(_libsystemd);
1143 _libsystemd = NULL;
1144 }
1145 }
1146 if (!_libsystemd)
1147 {
1148 _libsystemd_broken = EINA_TRUE;
1149 return;
1150 }
1151 _ecore_sd_notify =
1152 eina_module_symbol_get(_libsystemd, "sd_notify");
1153 if (!_ecore_sd_notify)
1154 {
1155 _ecore_sd_notify = NULL;
1156 eina_module_free(_libsystemd);
1157 _libsystemd = NULL;
1158 _libsystemd_broken = EINA_TRUE;
1159 }
1160}
1161#endif
diff --git a/src/lib/ecore/ecore_main.c b/src/lib/ecore/ecore_main.c
index fc35331f3f..2e404a4d2d 100644
--- a/src/lib/ecore/ecore_main.c
+++ b/src/lib/ecore/ecore_main.c
@@ -20,10 +20,6 @@
20#include <fcntl.h> 20#include <fcntl.h>
21#include <sys/time.h> 21#include <sys/time.h>
22 22
23#ifdef HAVE_SYSTEMD
24# include <systemd/sd-daemon.h>
25#endif
26
27#ifdef HAVE_IEEEFP_H 23#ifdef HAVE_IEEEFP_H
28# include <ieeefp.h> // for Solaris 24# include <ieeefp.h> // for Solaris
29#endif 25#endif
@@ -1195,9 +1191,11 @@ _ecore_main_loop_begin(Eo *obj, Efl_Loop_Data *pd)
1195 pd->loop_active++; 1191 pd->loop_active++;
1196 if (obj == ML_OBJ) 1192 if (obj == ML_OBJ)
1197 { 1193 {
1198#ifdef HAVE_SYSTEMD 1194 if (getenv("NOTIFY_SOCKET"))
1199 sd_notify(0, "READY=1"); 1195 {
1200#endif 1196 _ecore_sd_init();
1197 if (_ecore_sd_notify) _ecore_sd_notify(0, "READY=1");
1198 }
1201#ifdef HAVE_LIBUV 1199#ifdef HAVE_LIBUV
1202 if (!_dl_uv_run) 1200 if (!_dl_uv_run)
1203 { 1201 {
diff --git a/src/lib/ecore/ecore_private.h b/src/lib/ecore/ecore_private.h
index 8e9b796c2c..f87e5e753f 100644
--- a/src/lib/ecore/ecore_private.h
+++ b/src/lib/ecore/ecore_private.h
@@ -511,6 +511,12 @@ extern Eina_Bool _ecore_glib_always_integrate;
511extern Ecore_Select_Function main_loop_select; 511extern Ecore_Select_Function main_loop_select;
512extern int in_main_loop; 512extern int in_main_loop;
513 513
514#ifdef HAVE_SYSTEMD
515void _ecore_sd_init(void);
516
517extern int (*_ecore_sd_notify) (int unset_environment, const char *state);
518#endif
519
514Eina_Bool ecore_mempool_init(void); 520Eina_Bool ecore_mempool_init(void);
515void ecore_mempool_shutdown(void); 521void ecore_mempool_shutdown(void);
516#define GENERIC_ALLOC_FREE_HEADER(TYPE, Type) \ 522#define GENERIC_ALLOC_FREE_HEADER(TYPE, Type) \
diff --git a/src/lib/ecore/meson.build b/src/lib/ecore/meson.build
index 34c32e753d..637761dcc4 100644
--- a/src/lib/ecore/meson.build
+++ b/src/lib/ecore/meson.build
@@ -192,10 +192,6 @@ if get_option('g-mainloop') == true
192 endif 192 endif
193endif 193endif
194 194
195if get_option('systemd') == true
196 ecore_deps += systemd
197endif
198
199ecore_lib = library('ecore', 195ecore_lib = library('ecore',
200 ecore_src, pub_eo_file_target, 196 ecore_src, pub_eo_file_target,
201 dependencies: ecore_pub_deps + [m, buildsystem, ecore_deps], 197 dependencies: ecore_pub_deps + [m, buildsystem, ecore_deps],
diff --git a/src/lib/ecore_con/ecore_con.c b/src/lib/ecore_con/ecore_con.c
index 8a4e0fb43e..dd7fc23d4b 100644
--- a/src/lib/ecore_con/ecore_con.c
+++ b/src/lib/ecore_con/ecore_con.c
@@ -34,10 +34,6 @@
34# include <sys/filio.h> 34# include <sys/filio.h>
35#endif 35#endif
36 36
37#ifdef HAVE_SYSTEMD
38# include <systemd/sd-daemon.h>
39#endif
40
41#ifdef _WIN32 37#ifdef _WIN32
42# include <ws2tcpip.h> 38# include <ws2tcpip.h>
43# include <evil_private.h> /* evil_init|shutdown */ 39# include <evil_private.h> /* evil_init|shutdown */
@@ -107,7 +103,11 @@ ecore_con_init(void)
107 EFL_NET_SOCKET_SSL_ERROR_CERTIFICATE_VERIFY_FAILED; 103 EFL_NET_SOCKET_SSL_ERROR_CERTIFICATE_VERIFY_FAILED;
108 104
109#ifdef HAVE_SYSTEMD 105#ifdef HAVE_SYSTEMD
110 sd_fd_max = sd_listen_fds(0); 106 if (getenv("LISTEN_PID") && getenv("LISTEN_FDS"))
107 {
108 _ecore_con_sd_init();
109 if (_ecore_sd_listen_fds) sd_fd_max = _ecore_sd_listen_fds(0);
110 }
111#endif 111#endif
112 112
113 eina_log_timing(_ecore_con_log_dom, 113 eina_log_timing(_ecore_con_log_dom,
@@ -389,11 +389,16 @@ efl_net_ip_port_split(char *buf, const char **p_host, const char **p_port)
389Eina_Error 389Eina_Error
390efl_net_ip_socket_activate_check(const char *address, int family, int type, Eina_Bool *listening) 390efl_net_ip_socket_activate_check(const char *address, int family, int type, Eina_Bool *listening)
391{ 391{
392 SOCKET fd = SD_LISTEN_FDS_START + sd_fd_index; 392 SOCKET fd = /*SD_LISTEN_FDS_START*/3 + sd_fd_index;
393 int r; 393 int r;
394 394
395 // check first as this will return if we're not socket activated...
396 // or systemd not found, which means the below init will not be done then
395 if (sd_fd_index >= sd_fd_max) return ENOENT; 397 if (sd_fd_index >= sd_fd_max) return ENOENT;
396 398
399 _ecore_con_sd_init();
400 if ((!_ecore_sd_is_socket_unix) || (!_ecore_sd_is_socket)) return ENOENT;
401
397 if (family == AF_UNIX) 402 if (family == AF_UNIX)
398 { 403 {
399 char buf[sizeof(struct sockaddr_un)] = ""; 404 char buf[sizeof(struct sockaddr_un)] = "";
@@ -424,7 +429,7 @@ efl_net_ip_socket_activate_check(const char *address, int family, int type, Eina
424 len = strlen(address) + 1; 429 len = strlen(address) + 1;
425 } 430 }
426 431
427 r = sd_is_socket_unix(fd, type, 0, sun_path, len); 432 r = _ecore_sd_is_socket_unix(fd, type, 0, sun_path, len);
428 if (r < 0) 433 if (r < 0)
429 { 434 {
430 ERR("socket " SOCKET_FMT " is not of family=%d, type=%d", fd, family, type); 435 ERR("socket " SOCKET_FMT " is not of family=%d, type=%d", fd, family, type);
@@ -443,7 +448,7 @@ efl_net_ip_socket_activate_check(const char *address, int family, int type, Eina
443 Eina_Error err; 448 Eina_Error err;
444 int x; 449 int x;
445 450
446 r = sd_is_socket(fd, family, type, (type == SOCK_DGRAM) ? -1 : 0); 451 r = _ecore_sd_is_socket(fd, family, type, (type == SOCK_DGRAM) ? -1 : 0);
447 if (r < 0) 452 if (r < 0)
448 { 453 {
449 ERR("socket " SOCKET_FMT " is not of family=%d, type=%d", fd, family, type); 454 ERR("socket " SOCKET_FMT " is not of family=%d, type=%d", fd, family, type);
@@ -2588,3 +2593,49 @@ ecore_con_libproxy_proxies_free(char **proxies)
2588 free(*itr); 2593 free(*itr);
2589 free(proxies); 2594 free(proxies);
2590} 2595}
2596
2597#ifdef HAVE_SYSTEMD
2598static Eina_Module *_libsystemd = NULL;
2599static Eina_Bool _libsystemd_broken = EINA_FALSE;
2600
2601int (*_ecore_sd_listen_fds) (int unset_environment) = NULL;
2602int (*_ecore_sd_is_socket_unix) (int fd, int type, int listening, const char *path, size_t length) = NULL;
2603int (*_ecore_sd_is_socket) (int fd, int family, int type, int listening) = NULL;
2604
2605void
2606_ecore_con_sd_init(void)
2607{
2608 if (_libsystemd_broken) return;
2609 _libsystemd = eina_module_new("libsystemd.so.0");
2610 if (_libsystemd)
2611 {
2612 if (!eina_module_load(_libsystemd))
2613 {
2614 eina_module_free(_libsystemd);
2615 _libsystemd = NULL;
2616 }
2617 }
2618 if (!_libsystemd)
2619 {
2620 _libsystemd_broken = EINA_TRUE;
2621 return;
2622 }
2623 _ecore_sd_listen_fds =
2624 eina_module_symbol_get(_libsystemd, "sd_listen_fds");
2625 _ecore_sd_is_socket_unix =
2626 eina_module_symbol_get(_libsystemd, "sd_is_socket_unix");
2627 _ecore_sd_is_socket =
2628 eina_module_symbol_get(_libsystemd, "sd_is_socket");
2629 if ((!_ecore_sd_listen_fds) ||
2630 (!_ecore_sd_is_socket_unix) ||
2631 (!_ecore_sd_is_socket))
2632 {
2633 _ecore_sd_listen_fds = NULL;
2634 _ecore_sd_is_socket_unix = NULL;
2635 _ecore_sd_is_socket = NULL;
2636 eina_module_free(_libsystemd);
2637 _libsystemd = NULL;
2638 _libsystemd_broken = EINA_TRUE;
2639 }
2640}
2641#endif
diff --git a/src/lib/ecore_con/ecore_con_local.c b/src/lib/ecore_con/ecore_con_local.c
index fae182e133..993487880a 100644
--- a/src/lib/ecore_con/ecore_con_local.c
+++ b/src/lib/ecore_con/ecore_con_local.c
@@ -17,10 +17,6 @@
17#endif 17#endif
18#include <libgen.h> 18#include <libgen.h>
19 19
20#ifdef HAVE_SYSTEMD
21# include <systemd/sd-daemon.h>
22#endif
23
24#ifdef _WIN32 20#ifdef _WIN32
25# include <ws2tcpip.h> 21# include <ws2tcpip.h>
26#endif 22#endif
diff --git a/src/lib/ecore_con/ecore_con_private.h b/src/lib/ecore_con/ecore_con_private.h
index 7f0c95d61d..805abbecb6 100644
--- a/src/lib/ecore_con/ecore_con_private.h
+++ b/src/lib/ecore_con/ecore_con_private.h
@@ -90,6 +90,13 @@ struct Ecore_Con_Socks_v5
90#ifdef HAVE_SYSTEMD 90#ifdef HAVE_SYSTEMD
91extern int sd_fd_index; 91extern int sd_fd_index;
92extern int sd_fd_max; 92extern int sd_fd_max;
93
94void _ecore_con_sd_init(void);
95
96extern int (*_ecore_sd_listen_fds) (int unset_environment);
97extern int (*_ecore_sd_is_socket_unix) (int fd, int type, int listening, const char *path, size_t length);
98extern int (*_ecore_sd_is_socket) (int fd, int family, int type, int listening);
99
93#endif 100#endif
94 101
95/* init must be called from main thread */ 102/* init must be called from main thread */
diff --git a/src/lib/ecore_con/efl_net_server_fd.c b/src/lib/ecore_con/efl_net_server_fd.c
index d3d61ca46f..62fef94eed 100644
--- a/src/lib/ecore_con/efl_net_server_fd.c
+++ b/src/lib/ecore_con/efl_net_server_fd.c
@@ -14,10 +14,6 @@
14# include <sys/socket.h> 14# include <sys/socket.h>
15#endif 15#endif
16 16
17#ifdef HAVE_SYSTEMD
18# include <systemd/sd-daemon.h>
19#endif
20
21#define MY_CLASS EFL_NET_SERVER_FD_CLASS 17#define MY_CLASS EFL_NET_SERVER_FD_CLASS
22 18
23typedef struct _Efl_Net_Server_Fd_Data 19typedef struct _Efl_Net_Server_Fd_Data
@@ -233,7 +229,7 @@ _efl_net_server_fd_socket_activate(Eo *o, Efl_Net_Server_Fd_Data *pd EINA_UNUSED
233 } 229 }
234 else 230 else
235 { 231 {
236 SOCKET fd = SD_LISTEN_FDS_START + sd_fd_index; 232 SOCKET fd = /*SD_LISTEN_FDS_START*/3 + sd_fd_index;
237 int family; 233 int family;
238 socklen_t len = sizeof(family); 234 socklen_t len = sizeof(family);
239 235
diff --git a/src/lib/ecore_con/meson.build b/src/lib/ecore_con/meson.build
index fc53d3210f..44faa486af 100644
--- a/src/lib/ecore_con/meson.build
+++ b/src/lib/ecore_con/meson.build
@@ -184,7 +184,7 @@ ecore_con_deps += crypto
184 184
185ecore_con_lib = library('ecore_con', 185ecore_con_lib = library('ecore_con',
186 ecore_con_src, pub_eo_file_target, 186 ecore_con_src, pub_eo_file_target,
187 dependencies: [ecore, ecore_con_deps, http_parser, eldbus, eet, systemd, buildsystem, dl], 187 dependencies: [ecore, ecore_con_deps, http_parser, eldbus, eet, buildsystem, dl],
188 include_directories : config_dir, 188 include_directories : config_dir,
189 install: true, 189 install: true,
190 c_args : package_c_args, 190 c_args : package_c_args,
diff --git a/src/lib/ecore_drm/ecore_drm_logind.c b/src/lib/ecore_drm/ecore_drm_logind.c
index f5792a774c..4266239a84 100644
--- a/src/lib/ecore_drm/ecore_drm_logind.c
+++ b/src/lib/ecore_drm/ecore_drm_logind.c
@@ -36,12 +36,62 @@
36static Ecore_Event_Handler *active_hdlr; 36static Ecore_Event_Handler *active_hdlr;
37 37
38#ifdef HAVE_SYSTEMD 38#ifdef HAVE_SYSTEMD
39static inline Eina_Bool 39static Eina_Module *_libsystemd = NULL;
40static Eina_Bool _libsystemd_broken = EINA_FALSE;
41
42static int (*_ecore_sd_session_get_vt) (const char *session, unsigned *vtnr) = NULL;
43static int (*_ecore_sd_pid_get_session) (pid_t pid, char **session) = NULL;
44static int (*_ecore_sd_session_get_seat) (const char *session, char **seat) = NULL;
45
46void
47_ecore_drm_sd_init(void)
48{
49 if (_libsystemd_broken) return;
50 _libsystemd = eina_module_new("libsystemd.so.0");
51 if (_libsystemd)
52 {
53 if (!eina_module_load(_libsystemd))
54 {
55 eina_module_free(_libsystemd);
56 _libsystemd = NULL;
57 }
58 }
59 if (!_libsystemd)
60 {
61 _libsystemd_broken = EINA_TRUE;
62 return;
63 }
64 _ecore_sd_session_get_vt =
65 eina_module_symbol_get(_libsystemd, "sd_session_get_vt");
66 _ecore_sd_pid_get_session =
67 eina_module_symbol_get(_libsystemd, "sd_pid_get_session");
68 _ecore_sd_session_get_seat =
69 eina_module_symbol_get(_libsystemd, "sd_session_get_seat");
70 if ((!_ecore_sd_session_get_vt) ||
71 (!_ecore_sd_pid_get_session) ||
72 (!_ecore_sd_session_get_seat))
73 {
74 _ecore_sd_session_get_vt = NULL;
75 _ecore_sd_pid_get_session = NULL;
76 _ecore_sd_session_get_seat = NULL;
77 eina_module_free(_libsystemd);
78 _libsystemd = NULL;
79 _libsystemd_broken = EINA_TRUE;
80 }
81}
82
83static inline Eina_Bool
40_ecore_drm_logind_vt_get(Ecore_Drm_Device *dev) 84_ecore_drm_logind_vt_get(Ecore_Drm_Device *dev)
41{ 85{
42 int ret; 86 int ret;
43 87
44 ret = sd_session_get_vt(dev->session, &dev->vt); 88 _ecore_drm_sd_init();
89 if (!_ecore_sd_session_get_vt)
90 {
91 ERR("Could not get systemd tty");
92 return EINA_FALSE;
93 }
94 ret = _ecore_sd_session_get_vt(dev->session, &dev->vt);
45 if (ret < 0) 95 if (ret < 0)
46 { 96 {
47 ERR("Could not get systemd tty"); 97 ERR("Could not get systemd tty");
@@ -142,20 +192,26 @@ _ecore_drm_logind_cb_activate(void *data, int type EINA_UNUSED, void *event)
142 return ECORE_CALLBACK_PASS_ON; 192 return ECORE_CALLBACK_PASS_ON;
143} 193}
144 194
145Eina_Bool 195Eina_Bool
146_ecore_drm_logind_connect(Ecore_Drm_Device *dev) 196_ecore_drm_logind_connect(Ecore_Drm_Device *dev)
147{ 197{
148#ifdef HAVE_SYSTEMD 198#ifdef HAVE_SYSTEMD
149 char *seat; 199 char *seat = NULL;
150 200
201 _ecore_drm_sd_init();
202 if ((!_ecore_sd_pid_get_session) ||
203 (!_ecore_sd_session_get_seat))
204 {
205 ERR("Could not get systemd session");
206 return EINA_FALSE;
207 }
151 /* get session id */ 208 /* get session id */
152 if (sd_pid_get_session(getpid(), &dev->session) < 0) 209 if (_ecore_sd_pid_get_session(getpid(), &dev->session) < 0)
153 { 210 {
154 ERR("Could not get systemd session"); 211 ERR("Could not get systemd session");
155 return EINA_FALSE; 212 return EINA_FALSE;
156 } 213 }
157 214 if (_ecore_sd_session_get_seat(dev->session, &seat) < 0)
158 if (sd_session_get_seat(dev->session, &seat) < 0)
159 { 215 {
160 ERR("Could not get systemd seat"); 216 ERR("Could not get systemd seat");
161 return EINA_FALSE; 217 return EINA_FALSE;
@@ -166,9 +222,7 @@ _ecore_drm_logind_connect(Ecore_Drm_Device *dev)
166 free(seat); 222 free(seat);
167 return EINA_FALSE; 223 return EINA_FALSE;
168 } 224 }
169
170 free(seat); 225 free(seat);
171
172 if (!_ecore_drm_logind_vt_get(dev)) return EINA_FALSE; 226 if (!_ecore_drm_logind_vt_get(dev)) return EINA_FALSE;
173#endif 227#endif
174 228
diff --git a/src/lib/ecore_drm/ecore_drm_private.h b/src/lib/ecore_drm/ecore_drm_private.h
index 5e292372fd..0be6a61ef8 100644
--- a/src/lib/ecore_drm/ecore_drm_private.h
+++ b/src/lib/ecore_drm/ecore_drm_private.h
@@ -53,10 +53,6 @@
53# include <linux/input.h> 53# include <linux/input.h>
54# include <libinput.h> 54# include <libinput.h>
55 55
56# ifdef HAVE_SYSTEMD
57# include <systemd/sd-login.h>
58# endif
59
60# include <Eldbus.h> 56# include <Eldbus.h>
61# include <Ecore_Drm.h> 57# include <Ecore_Drm.h>
62 58
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 @@
29#include <assert.h> 29#include <assert.h>
30#include <errno.h> 30#include <errno.h>
31 31
32#ifdef HAVE_SYSTEMD
33# include <systemd/sd-journal.h>
34#endif
35
36#ifdef _WIN32 32#ifdef _WIN32
37# include <windows.h> 33# include <windows.h>
38#endif 34#endif
@@ -51,6 +47,7 @@
51#include "eina_thread.h" 47#include "eina_thread.h"
52#include "eina_convert.h" 48#include "eina_convert.h"
53#include "eina_strbuf.h" 49#include "eina_strbuf.h"
50#include "eina_module.h"
54 51
55/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */ 52/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
56#include "eina_safety_checks.h" 53#include "eina_safety_checks.h"
@@ -2091,6 +2088,43 @@ eina_log_print_cb_stdout(const Eina_Log_Domain *d,
2091#endif 2088#endif
2092} 2089}
2093 2090
2091#ifdef HAVE_SYSTEMD
2092static Eina_Module *_libsystemd = NULL;
2093static Eina_Bool _libsystemd_broken = EINA_FALSE;
2094
2095static int (*_eina_sd_journal_send_with_location) (const char *file, const char *line, const char *func, const char *format, ...) = NULL;
2096
2097static void
2098_eina_sd_init(void)
2099{
2100 if (_libsystemd_broken) return;
2101 _libsystemd = eina_module_new("libsystemd.so.0");
2102 if (_libsystemd)
2103 {
2104 if (!eina_module_load(_libsystemd))
2105 {
2106 eina_module_free(_libsystemd);
2107 _libsystemd = NULL;
2108 }
2109 }
2110 if (!_libsystemd)
2111 {
2112 _libsystemd_broken = EINA_TRUE;
2113 return;
2114 }
2115 _eina_sd_journal_send_with_location =
2116 eina_module_symbol_get(_libsystemd, "sd_journal_send_with_location");
2117 if (!_eina_sd_journal_send_with_location)
2118 {
2119 _eina_sd_journal_send_with_location = NULL;
2120 eina_module_free(_libsystemd);
2121 _libsystemd = NULL;
2122 _libsystemd_broken = EINA_TRUE;
2123 }
2124}
2125
2126#endif
2127
2094EAPI void 2128EAPI void
2095eina_log_print_cb_journald(const Eina_Log_Domain *d, 2129eina_log_print_cb_journald(const Eina_Log_Domain *d,
2096 Eina_Log_Level level, 2130 Eina_Log_Level level,
@@ -2108,6 +2142,9 @@ eina_log_print_cb_journald(const Eina_Log_Domain *d,
2108 Eina_Thread cur; 2142 Eina_Thread cur;
2109 int r; 2143 int r;
2110 2144
2145 _eina_sd_init();
2146 if (!_eina_sd_journal_send_with_location) goto nosystemd;
2147
2111 r = asprintf(&file_prefixed, "CODE_FILE=%s", file); 2148 r = asprintf(&file_prefixed, "CODE_FILE=%s", file);
2112 if (r == -1) 2149 if (r == -1)
2113 { 2150 {
@@ -2134,12 +2171,12 @@ eina_log_print_cb_journald(const Eina_Log_Domain *d,
2134#ifdef EINA_LOG_BACKTRACE 2171#ifdef EINA_LOG_BACKTRACE
2135 if (EINA_LIKELY(level > _backtrace_level)) 2172 if (EINA_LIKELY(level > _backtrace_level))
2136#endif 2173#endif
2137 sd_journal_send_with_location(file_prefixed, line_str, fnc, 2174 _eina_sd_journal_send_with_location(file_prefixed, line_str, fnc,
2138 "PRIORITY=%i", level, 2175 "PRIORITY=%i", level,
2139 "MESSAGE=%s", message, 2176 "MESSAGE=%s", message,
2140 "EFL_DOMAIN=%s", d->domain_str, 2177 "EFL_DOMAIN=%s", d->domain_str,
2141 "THREAD=%lu", cur, 2178 "THREAD=%lu", cur,
2142 NULL); 2179 NULL);
2143#ifdef EINA_LOG_BACKTRACE 2180#ifdef EINA_LOG_BACKTRACE
2144 else 2181 else
2145 { 2182 {
@@ -2159,14 +2196,14 @@ eina_log_print_cb_journald(const Eina_Log_Domain *d,
2159 else 2196 else
2160 eina_strbuf_append_printf(bts, "[%s], ", strings[i]); 2197 eina_strbuf_append_printf(bts, "[%s], ", strings[i]);
2161 2198
2162 sd_journal_send_with_location(file_prefixed, line_str, fnc, 2199 _eina_sd_journal_send_with_location(file_prefixed, line_str, fnc,
2163 "PRIORITY=%i", level, 2200 "PRIORITY=%i", level,
2164 "MESSAGE=%s", message, 2201 "MESSAGE=%s", message,
2165 "EFL_DOMAIN=%s", d->domain_str, 2202 "EFL_DOMAIN=%s", d->domain_str,
2166 "THREAD=%lu", cur, 2203 "THREAD=%lu", cur,
2167 "BACKTRACE=%s", 2204 "BACKTRACE=%s",
2168 eina_strbuf_string_get(bts), 2205 eina_strbuf_string_get(bts),
2169 NULL); 2206 NULL);
2170 eina_strbuf_free(bts); 2207 eina_strbuf_free(bts);
2171 free(strings); 2208 free(strings);
2172 } 2209 }
@@ -2176,10 +2213,10 @@ finish:
2176 free(file_prefixed); 2213 free(file_prefixed);
2177 free(line_str); 2214 free(line_str);
2178 free(message); 2215 free(message);
2179 2216 return;
2180#else 2217nosystemd:
2181 eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, data, args);
2182#endif 2218#endif
2219 eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, data, args);
2183} 2220}
2184 2221
2185EAPI void 2222EAPI 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
265endif 265endif
266 266
267if get_option('systemd') == true 267if get_option('systemd') == true
268 systemd = dependency('libsystemd')
269 eina_deps += systemd
270 config_h.set('HAVE_SYSTEMD', '1') 268 config_h.set('HAVE_SYSTEMD', '1')
271 if systemd.version().version_compare('>=209')
272 config_h.set('HAVE_SYSTEMD_LOGIN_209', '1')
273 endif
274else
275 systemd = []
276endif 269endif
277 270
278 271
diff --git a/src/lib/elput/elput_logind.c b/src/lib/elput/elput_logind.c
index cca5ea7eb7..3548cf4a71 100644
--- a/src/lib/elput/elput_logind.c
+++ b/src/lib/elput/elput_logind.c
@@ -1,6 +1,68 @@
1#include "elput_private.h" 1#include "elput_private.h"
2 2
3#if defined(HAVE_SYSTEMD) || defined(HAVE_ELOGIND) 3#ifdef HAVE_SYSTEMD
4static Eina_Module *_libsystemd = NULL;
5static Eina_Bool _libsystemd_broken = EINA_FALSE;
6
7static int (*_elput_sd_session_get_vt) (const char *session, unsigned *vtnr) = NULL;
8static int (*_elput_sd_session_get_tty) (const char *session, char **display) = NULL;
9static int (*_elput_sd_pid_get_session) (pid_t pid, char **session) = NULL;
10static int (*_elput_sd_session_get_seat) (const char *session, char **seat) = NULL;
11
12void
13_elput_sd_init(void)
14{
15 if (_libsystemd_broken) return;
16 _libsystemd = eina_module_new("libsystemd.so.0");
17 if (_libsystemd)
18 {
19 if (!eina_module_load(_libsystemd))
20 {
21 eina_module_free(_libsystemd);
22 _libsystemd = NULL;
23 }
24 }
25 if (!_libsystemd)
26 {
27 _libsystemd = eina_module_new("libelogind.so.0");
28 if (_libsystemd)
29 {
30 if (!eina_module_load(_libsystemd))
31 {
32 eina_module_free(_libsystemd);
33 _libsystemd = NULL;
34 }
35 }
36 }
37 if (!_libsystemd)
38 {
39 _libsystemd_broken = EINA_TRUE;
40 return;
41 }
42 // sd_session_get_vt == newere in systemd 207
43 _elput_sd_session_get_vt =
44 eina_module_symbol_get(_libsystemd, "sd_session_get_vt");
45 // sd_session_get_tty == older api in ssystemd 198
46 _elput_sd_session_get_tty =
47 eina_module_symbol_get(_libsystemd, "sd_session_get_tty");
48 _elput_sd_pid_get_session =
49 eina_module_symbol_get(_libsystemd, "sd_pid_get_session");
50 _elput_sd_session_get_seat =
51 eina_module_symbol_get(_libsystemd, "sd_session_get_seat");
52 if (((!_elput_sd_session_get_vt) && (!_elput_sd_session_get_tty)) ||
53 (!_elput_sd_pid_get_session) ||
54 (!_elput_sd_session_get_seat))
55 {
56 _elput_sd_session_get_vt = NULL;
57 _elput_sd_session_get_tty = NULL;
58 _elput_sd_pid_get_session = NULL;
59 _elput_sd_session_get_seat = NULL;
60 eina_module_free(_libsystemd);
61 _libsystemd = NULL;
62 _libsystemd_broken = EINA_TRUE;
63 }
64}
65
4 66
5static void 67static void
6_logind_session_active_cb_free(void *data EINA_UNUSED, void *event) 68_logind_session_active_cb_free(void *data EINA_UNUSED, void *event)
@@ -140,13 +202,16 @@ _cb_device_resumed(void *data, const Eldbus_Message *msg)
140static Eina_Bool 202static Eina_Bool
141_logind_session_vt_get(const char *sid, unsigned int *vt) 203_logind_session_vt_get(const char *sid, unsigned int *vt)
142{ 204{
143# ifdef HAVE_SYSTEMD_LOGIN_209
144 return (sd_session_get_vt(sid, vt) >= 0);
145# else
146 int ret = 0; 205 int ret = 0;
147 char *tty; 206 char *tty;
148 207
149 ret = sd_session_get_tty(sid, &tty); 208 _elput_sd_init();
209 if ((!_elput_sd_session_get_vt) && (!_elput_sd_session_get_tty))
210 return EINA_FALSE;
211 if (_elput_sd_session_get_vt)
212 return (_elput_sd_session_get_vt(sid, vt) >= 0);
213
214 ret = _elput_sd_session_get_tty(sid, &tty);
150 if (ret < 0) return ret; 215 if (ret < 0) return ret;
151 216
152 ret = sscanf(tty, "tty%u", vt); 217 ret = sscanf(tty, "tty%u", vt);
@@ -154,7 +219,6 @@ _logind_session_vt_get(const char *sid, unsigned int *vt)
154 219
155 if (ret != 1) return EINA_FALSE; 220 if (ret != 1) return EINA_FALSE;
156 return EINA_TRUE; 221 return EINA_TRUE;
157# endif
158} 222}
159 223
160static Eina_Bool 224static Eina_Bool
@@ -489,13 +553,16 @@ _logind_connect(Elput_Manager **manager, const char *seat, unsigned int tty)
489 int ret = 0; 553 int ret = 0;
490 char *s = NULL; 554 char *s = NULL;
491 555
556 _elput_sd_init();
557 if (!_elput_sd_pid_get_session) return EINA_FALSE;
558
492 em = calloc(1, sizeof(Elput_Manager)); 559 em = calloc(1, sizeof(Elput_Manager));
493 if (!em) return EINA_FALSE; 560 if (!em) return EINA_FALSE;
494 561
495 em->interface = &_logind_interface; 562 em->interface = &_logind_interface;
496 em->seat = eina_stringshare_add(seat); 563 em->seat = eina_stringshare_add(seat);
497 564
498 ret = sd_pid_get_session(getpid(), &em->sid); 565 ret = _elput_sd_pid_get_session(getpid(), &em->sid);
499 566
500 if (ret < 0) 567 if (ret < 0)
501 { 568 {
@@ -508,7 +575,7 @@ _logind_connect(Elput_Manager **manager, const char *seat, unsigned int tty)
508 575
509 if (!em->sid) goto session_err; 576 if (!em->sid) goto session_err;
510 577
511 ret = sd_session_get_seat(em->sid, &s); 578 ret = _elput_sd_session_get_seat(em->sid, &s);
512 if (ret < 0) 579 if (ret < 0)
513 { 580 {
514 ERR("Failed to get session seat"); 581 ERR("Failed to get session seat");
diff --git a/src/lib/elput/elput_manager.c b/src/lib/elput/elput_manager.c
index 987e73759b..93f39ea261 100644
--- a/src/lib/elput/elput_manager.c
+++ b/src/lib/elput/elput_manager.c
@@ -2,7 +2,7 @@
2 2
3static Elput_Interface *_ifaces[] = 3static Elput_Interface *_ifaces[] =
4{ 4{
5#if defined(HAVE_SYSTEMD) || defined(HAVE_ELOGIND) 5#ifdef HAVE_SYSTEMD
6 &_logind_interface, 6 &_logind_interface,
7#endif 7#endif
8 NULL, 8 NULL,
diff --git a/src/lib/elput/elput_private.h b/src/lib/elput/elput_private.h
index 744c5a92e3..fd7d843d2e 100644
--- a/src/lib/elput/elput_private.h
+++ b/src/lib/elput/elput_private.h
@@ -23,14 +23,6 @@
23# include <xkbcommon/xkbcommon.h> 23# include <xkbcommon/xkbcommon.h>
24# include <xkbcommon/xkbcommon-compose.h> 24# include <xkbcommon/xkbcommon-compose.h>
25 25
26# ifdef HAVE_SYSTEMD
27# include <systemd/sd-login.h>
28# endif
29
30# ifdef HAVE_ELOGIND
31# include <elogind/sd-login.h>
32# endif
33
34#ifndef ELPUT_NODEFS 26#ifndef ELPUT_NODEFS
35# ifdef ELPUT_DEFAULT_LOG_COLOR 27# ifdef ELPUT_DEFAULT_LOG_COLOR
36# undef ELPUT_DEFAULT_LOG_COLOR 28# undef ELPUT_DEFAULT_LOG_COLOR
diff --git a/src/lib/elput/meson.build b/src/lib/elput/meson.build
index 2aa3590d2b..0e3e2f9c5f 100644
--- a/src/lib/elput/meson.build
+++ b/src/lib/elput/meson.build
@@ -19,12 +19,6 @@ elput_src = [
19elput_deps += dependency('libinput', version : ['>=1.7.0']) 19elput_deps += dependency('libinput', version : ['>=1.7.0'])
20elput_deps += dependency('xkbcommon', version : ['>=0.3.0']) 20elput_deps += dependency('xkbcommon', version : ['>=0.3.0'])
21elput_deps += dependency('libudev') 21elput_deps += dependency('libudev')
22if get_option('systemd')
23 elput_deps += systemd
24endif
25if get_option('elogind')
26 elput_deps += dependency('libelogind')
27endif
28 22
29elput_lib = library('elput', 23elput_lib = library('elput',
30 elput_src, pub_eo_file_target, 24 elput_src, pub_eo_file_target,