summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Szewczyk <p.szewczyk@samsung.com>2018-06-28 12:20:28 +0200
committerPaweł Szewczyk <p.szewczyk@samsung.com>2018-06-28 13:11:40 +0200
commit963911e53cfc6883e0087b24703e0e858754cc6a (patch)
treee0fd49063e07d35b1180b87b795d1be5511d47d1
parent6f13e9d8a1587ce155f57094ff282d0c8bfe0c54 (diff)
downloaddevice-manager-plugin-artik-963911e53cfc6883e0087b24703e0e858754cc6a.tar.gz
device-manager-plugin-artik-963911e53cfc6883e0087b24703e0e858754cc6a.tar.bz2
device-manager-plugin-artik-963911e53cfc6883e0087b24703e0e858754cc6a.zip
Move systemd-related code to common library
Change-Id: I3de92bdc9ec5308cff875f30c22d70d307e00002 Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
-rw-r--r--hw/usb_cfs_client/CMakeLists.txt2
-rw-r--r--hw/usb_cfs_client/usb_cfs_client.c121
-rw-r--r--hw/usb_client/CMakeLists.txt2
-rw-r--r--hw/usb_client/usb_client.c59
-rwxr-xr-xpackaging/device-manager-plugin-artik.spec2
5 files changed, 4 insertions, 182 deletions
diff --git a/hw/usb_cfs_client/CMakeLists.txt b/hw/usb_cfs_client/CMakeLists.txt
index 15e7cbc..fefe1dc 100644
--- a/hw/usb_cfs_client/CMakeLists.txt
+++ b/hw/usb_cfs_client/CMakeLists.txt
@@ -4,7 +4,7 @@ PROJECT(usb_cfs_client C)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
INCLUDE(FindPkgConfig)
-pkg_check_modules(usb_cfs_client_pkgs REQUIRED hwcommon dlog glib-2.0 libsystemd libusbgx)
+pkg_check_modules(usb_cfs_client_pkgs REQUIRED hwcommon dlog glib-2.0 libusbgx)
FOREACH(flag ${usb_cfs_client_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
diff --git a/hw/usb_cfs_client/usb_cfs_client.c b/hw/usb_cfs_client/usb_cfs_client.c
index c7875a4..28b10a0 100644
--- a/hw/usb_cfs_client/usb_cfs_client.c
+++ b/hw/usb_cfs_client/usb_cfs_client.c
@@ -17,6 +17,7 @@
*/
#include <hw/usb_client.h>
+#include <hw/systemd.h>
#include "../shared.h"
@@ -28,7 +29,6 @@
#include <sys/mount.h>
#include <usbg/usbg.h>
#include <unistd.h>
-#include <systemd/sd-bus.h>
#include <unistd.h>
@@ -587,125 +587,6 @@ static int cfs_set_gadget_strs(struct cfs_client *cfs_client,
return ret;
}
-#define SYSTEMD_DBUS_SERVICE "org.freedesktop.systemd1"
-#define SYSTEMD_DBUS_PATH "/org/freedesktop/systemd1"
-#define SYSTEMD_DBUS_MANAGER_IFACE "org.freedesktop.systemd1.Manager"
-
-#define SYSTEMD_SOCKET_SUFFIX ".socket"
-#define MAX_SOCKET_NAME 1024
-
-struct bus_ctx {
- const char *unit;
- sd_event *loop;
-};
-
-static int socket_started(sd_bus_message *m, void *userdata,
- sd_bus_error *ret_error)
-{
- struct bus_ctx *ctx = userdata;
- char *signal_unit;
- int ret;
-
- ret = sd_bus_message_read(m, "uoss", NULL, NULL, &signal_unit, NULL);
- if (ret < 0) {
- sd_event_exit(ctx->loop, ret);
- return 0;
- }
-
- if (!strcmp(signal_unit, ctx->unit))
- sd_event_exit(ctx->loop, 0);
-
- return 0;
-}
-
-static int systemd_unit_interface_sync(const char *method, const char *unit,
- bool wait)
-{
- sd_bus *bus = NULL;
- sd_event *loop = NULL;
- struct bus_ctx ctx;
- int ret;
-
- ret = sd_bus_open_system(&bus);
- if (ret < 0)
- return ret;
-
- if (wait) {
- ret = sd_event_new(&loop);
- if (ret < 0)
- goto unref_bus;
-
- ctx.loop = loop;
- ctx.unit = unit;
-
- ret = sd_bus_attach_event(bus, loop, SD_EVENT_PRIORITY_NORMAL);
- if (ret < 0)
- goto unref_loop;
-
- ret = sd_bus_add_match(bus, NULL,
- "type='signal',"
- "sender='" SYSTEMD_DBUS_SERVICE "',"
- "interface='" SYSTEMD_DBUS_MANAGER_IFACE "',"
- "member='JobRemoved',"
- "path_namespace='" SYSTEMD_DBUS_PATH "'",
- socket_started,
- &ctx);
- if (ret < 0)
- goto unref_loop;
- }
-
-
- ret = sd_bus_call_method(bus,
- SYSTEMD_DBUS_SERVICE,
- SYSTEMD_DBUS_PATH,
- SYSTEMD_DBUS_MANAGER_IFACE,
- method,
- NULL,
- NULL,
- "ss",
- unit,
- "replace");
- if (ret < 0)
- goto unref_loop;
-
- if (wait)
- ret = sd_event_loop(loop);
-
-unref_loop:
- if (wait)
- sd_event_unref(loop);
-unref_bus:
- sd_bus_unref(bus);
- return ret;
-}
-
-static int systemd_start_socket(const char *socket_name)
-{
- char unit[MAX_SOCKET_NAME];
- int ret;
-
- ret = snprintf(unit, sizeof(unit), "%s" SYSTEMD_SOCKET_SUFFIX,
- socket_name);
- if (ret < 0 || ret >= sizeof(unit))
- return -ENAMETOOLONG;
-
-
- return systemd_unit_interface_sync("StartUnit", unit, true);
-}
-
-static int systemd_stop_socket(const char *socket_name)
-{
- char unit[MAX_SOCKET_NAME];
- int ret;
-
- ret = snprintf(unit, sizeof(unit), "%s" SYSTEMD_SOCKET_SUFFIX,
- socket_name);
- if (ret < 0 || ret >= sizeof(unit))
- return -ENAMETOOLONG;
-
- return systemd_unit_interface_sync("StopUnit", unit, false);
-}
-
static int cfs_ensure_dir(char *path)
{
int ret;
diff --git a/hw/usb_client/CMakeLists.txt b/hw/usb_client/CMakeLists.txt
index 4a10107..8494082 100644
--- a/hw/usb_client/CMakeLists.txt
+++ b/hw/usb_client/CMakeLists.txt
@@ -4,7 +4,7 @@ PROJECT(usb_client C)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
INCLUDE(FindPkgConfig)
-pkg_check_modules(usb_client_pkgs REQUIRED hwcommon dlog glib-2.0 libusbgx libsystemd)
+pkg_check_modules(usb_client_pkgs REQUIRED hwcommon dlog glib-2.0 libusbgx)
FOREACH(flag ${usb_client_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
diff --git a/hw/usb_client/usb_client.c b/hw/usb_client/usb_client.c
index 0f1effe..2857c33 100644
--- a/hw/usb_client/usb_client.c
+++ b/hw/usb_client/usb_client.c
@@ -17,6 +17,7 @@
*/
#include <hw/usb_client.h>
+#include <hw/systemd.h>
#include "../shared.h"
@@ -24,7 +25,6 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
-#include <systemd/sd-bus.h>
#define zalloc(amount) calloc(1, amount)
@@ -63,63 +63,6 @@
/* +5 to be always big enough */
#define INT_BUF_SIZE (sizeof(int)*8 + 5)
-#define SYSTEMD_DBUS_SERVICE "org.freedesktop.systemd1"
-#define SYSTEMD_DBUS_PATH "/org/freedesktop/systemd1"
-#define SYSTEMD_DBUS_MANAGER_IFACE "org.freedesktop.systemd1.Manager"
-
-#define SYSTEMD_SERVICE_SUFFIX ".service"
-#define MAX_SERVICE_NAME 1024
-
-static int systemd_unit_interface(const char *method, const char *unit)
-{
- sd_bus *bus = NULL;
- int r;
-
- r = sd_bus_open_system(&bus);
- if (r < 0)
- return r;
-
- r = sd_bus_call_method(bus,
- SYSTEMD_DBUS_SERVICE,
- SYSTEMD_DBUS_PATH,
- SYSTEMD_DBUS_MANAGER_IFACE,
- method,
- NULL,
- NULL,
- "ss",
- unit,
- "replace");
-
- sd_bus_unref(bus);
- return r;
-}
-
-static int systemd_start_service(const char *service_name)
-{
- char unit[MAX_SERVICE_NAME];
- int ret;
-
- ret = snprintf(unit, sizeof(unit), "%s" SYSTEMD_SERVICE_SUFFIX,
- service_name);
- if (ret < 0 || ret >= sizeof(unit))
- return -ENAMETOOLONG;
-
- return systemd_unit_interface("StartUnit", unit);
-}
-
-static int systemd_stop_service(const char *service_name)
-{
- char unit[MAX_SERVICE_NAME];
- int ret;
-
- ret = snprintf(unit, sizeof(unit), "%s" SYSTEMD_SERVICE_SUFFIX,
- service_name);
- if (ret < 0 || ret >= sizeof(unit))
- return -ENAMETOOLONG;
-
- return systemd_unit_interface("StopUnit", unit);
-}
-
static int get_int_from_file(char *path, int *_val, int base)
{
char buf[INT_BUF_SIZE];
diff --git a/packaging/device-manager-plugin-artik.spec b/packaging/device-manager-plugin-artik.spec
index 7268a6a..ea99faa 100755
--- a/packaging/device-manager-plugin-artik.spec
+++ b/packaging/device-manager-plugin-artik.spec
@@ -15,8 +15,6 @@ BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(libudev)
BuildRequires: pkgconfig(capi-system-peripheral-io)
BuildRequires: pkgconfig(libusbgx)
-BuildRequires: pkgconfig(libsystemd)
-BuildRequires: pkgconfig(libusbgx)
%description
Device manager plugin artik