Source1: %{name}.manifest
BuildRequires: pkgconfig(libsystemd)
-BuildRequires: pkgconfig(libtzplatform-config)
+BuildRequires: pkgconfig(gio-2.0)
+BuildRequires: pkgconfig(glib-2.0)
BuildRequires: cmake
%description
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
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
*
*/
-/*
- * @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 <dlfcn.h>
-#include <unistd.h>
#include <stdio.h>
-#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <glib-unix.h>
-#define CONTAINER_LIB LIBDIR"/security/pam_krate.so"
+#include <systemd/sd-daemon.h>
-#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;
}