From 7c434f69023146031e91933338f935b1d50a737d Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Thu, 6 Aug 2020 18:01:21 +0900 Subject: [PATCH] Change systemd-user-helper to dbus test Change-Id: I0c4e3984d75f1151fe1aa7b3a1de2bf70fafab3c --- packaging/session-utils.spec | 10 ++- src/systemd-user-helper/CMakeLists.txt | 12 +-- src/systemd-user-helper/systemd-user-helper.c | 101 ++++++++++++-------------- systemd-user-helper.service | 9 +++ 4 files changed, 71 insertions(+), 61 deletions(-) create mode 100644 systemd-user-helper.service diff --git a/packaging/session-utils.spec b/packaging/session-utils.spec index 9e60fd9..e1fdc49 100644 --- a/packaging/session-utils.spec +++ b/packaging/session-utils.spec @@ -8,7 +8,8 @@ Source0: %{name}-%{version}.tar.bz2 Source1: %{name}.manifest BuildRequires: pkgconfig(libsystemd) -BuildRequires: pkgconfig(libtzplatform-config) +BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(glib-2.0) BuildRequires: cmake %description @@ -53,12 +54,17 @@ install -m 644 units/01-glib_warning_crash_enable.conf %{buildroot}/etc/systemd/ mkdir -p %{buildroot}%{_udevrulesdir} install -m 644 units/61-partlabel-user-for-tm2.rules %{buildroot}%{_udevrulesdir}/ -rm -f %{buildroot}%{_bindir}/systemd-user-helper +mkdir -p %{buildroot}%{_unitdir} +cp systemd-user-helper.service %{buildroot}%{_unitdir}/ + ############################################################################### %files %license LICENSE.Apache-2.0 %manifest session-utils.manifest +%{_bindir}/systemd-user-helper +%{_unitdir}/systemd-user-helper.service + ############################################################################### %files -n glib-warning-crash-enable diff --git a/src/systemd-user-helper/CMakeLists.txt b/src/systemd-user-helper/CMakeLists.txt index e153a36..3be879b 100644 --- a/src/systemd-user-helper/CMakeLists.txt +++ b/src/systemd-user-helper/CMakeLists.txt @@ -1,21 +1,21 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(systemd-user-helper C) -ADD_DEFINITIONS(-DLIBDIR=\"${LIBDIR}\") - INCLUDE(FindPkgConfig) -pkg_check_modules(${PROJECT_NAME}_pkgs REQUIRED - libtzplatform-config +pkg_check_modules(pkgs REQUIRED + glib-2.0 + gio-2.0 + libsystemd ) -FOREACH(flag ${${PROJECT_NAME}_pkgs}) +FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE") ADD_EXECUTABLE(${PROJECT_NAME} systemd-user-helper.c) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_pkgs_LDFLAGS} -ldl -pie) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -pie) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE diff --git a/src/systemd-user-helper/systemd-user-helper.c b/src/systemd-user-helper/systemd-user-helper.c index 763d5c0..4200614 100644 --- a/src/systemd-user-helper/systemd-user-helper.c +++ b/src/systemd-user-helper/systemd-user-helper.c @@ -15,79 +15,74 @@ * */ -/* - * @file systemd-user-helper.c - * @brief Systemd user launch helper for supporting Tizen specific feature - * - * Systemd user launch helper supports Tizen specific feature like directory - * compatibility and container. - */ - -#define _GNU_SOURCE -#include -#include #include -#include +#include +#include +#include +#include +#include -#define CONTAINER_LIB LIBDIR"/security/pam_krate.so" +#include -#define LOAD_SYMBOL(handle, sym, name) \ - do { \ - sym = dlsym(handle, name); \ - if (!sym) { \ - fprintf(stderr, "dlsym %s error\n", name); \ - dlclose(handle); \ - return -1; \ - } \ - } while (0); +int id; +static GMainLoop *mainloop; +static void sig_term(int signo) +{ + fprintf (stderr, "sig term\n"); +} -static int container_postprocess(char *username) +static void sig_abort(int signo) { - int r; - static void *container_handle; - int (*handle_postprocess)(char *); + fprintf (stderr, "sig abort\n"); - /* not support container */ - if (access(CONTAINER_LIB, F_OK)) - return 0; + sd_notify(0, "STOPPING=1"); + g_bus_unown_name (id); +} - container_handle = dlopen(CONTAINER_LIB, RTLD_LAZY); - if (!container_handle) { - fprintf(stderr, "container module dlopen error\n"); - return -1; - } +static void sig_quit(int signo) +{ + fprintf (stderr, "sig quit\n"); - LOAD_SYMBOL(container_handle, handle_postprocess, "container_postprocess"); + g_main_loop_quit(mainloop); +} - r = handle_postprocess(username); - if (r < 0) { - fprintf(stderr, "container module postprocess error\n"); - return r; - } +static void name_acquire(GDBusConnection *connection, const gchar *name, gpointer user_data) +{ + fprintf (stderr, "name acquire : %s\n", name); +} - return 0; +static void name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data) +{ + fprintf (stderr, "name lost : %s\n", name); } int main(int argc, char *argv[]) { - char *operation; - char *username; + GError *err = NULL; + GDBusConnection *conn = NULL; - if (argc < 3) { - fprintf(stderr, "require user argument\n"); + conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + if (!conn || err) { + fprintf (stderr, "failed to get system bus\n"); return -1; } - operation = argv[1]; - username = argv[2]; - - if (strcmp(operation, "container_postprocess") == 0) - return container_postprocess(username); - else { - fprintf(stderr, "option is invalid(%s)\n", operation); - return -2; + + id = g_bus_own_name_on_connection(conn, "org.myname", G_BUS_NAME_OWNER_FLAGS_NONE, + name_acquire, name_lost, NULL, NULL); + + if (id == 0) { + fprintf (stderr, "g_bus_own_name_on_connection fails\n"); + return -1; } + signal(SIGQUIT, sig_quit); + signal(SIGABRT, sig_abort); + signal(SIGTERM, sig_term); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + return 0; } diff --git a/systemd-user-helper.service b/systemd-user-helper.service new file mode 100644 index 0000000..41546c0 --- /dev/null +++ b/systemd-user-helper.service @@ -0,0 +1,9 @@ +[Unit] +Description=systemd user helper + +[Service] +SmackProcessLabel=System +Type=dbus +BusName=org.myname +ExecStart=/usr/bin/systemd-user-helper +NotifyAccess=main -- 2.7.4