URL: https://github.com/SSSD/sssd/pull/30
Author: pbrezina
 Title: #30: sssctl: use systemd D-Bus API
Action: opened

PR body:
"""
If systemd is used we leverage it's D-Bus API instead of running systemctl.

Resolves:
https://fedorahosted.org/sssd/ticket/3056
"""

To pull the PR as Git branch:
git remote add ghsssd https://github.com/SSSD/sssd
git fetch ghsssd pull/30/head:pr30
git checkout pr30
From 73b6071341262a298e3caf6857361504c8512d6c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrez...@redhat.com>
Date: Wed, 21 Sep 2016 12:25:43 +0200
Subject: [PATCH] sssctl: use systemd D-Bus API

If systemd is used we leverage it's D-Bus API instead of running systemctl.

Resolves:
https://fedorahosted.org/sssd/ticket/3056
---
 Makefile.am               |  1 +
 src/tools/sssctl/sssctl.c | 23 +++++++++++++----------
 src/tools/sssctl/sssctl.h |  4 ++++
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index f792ed6..7e6bf7e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1570,6 +1570,7 @@ sss_override_CFLAGS = \
 
 sssctl_SOURCES = \
     src/tools/sssctl/sssctl.c \
+    src/tools/sssctl/sssctl_systemd.c \
     src/tools/sssctl/sssctl_cache.c \
     src/tools/sssctl/sssctl_data.c \
     src/tools/sssctl/sssctl_logs.c \
diff --git a/src/tools/sssctl/sssctl.c b/src/tools/sssctl/sssctl.c
index 20ea26f..2ccb30e 100644
--- a/src/tools/sssctl/sssctl.c
+++ b/src/tools/sssctl/sssctl.c
@@ -26,12 +26,6 @@
 #include "tools/common/sss_tools.h"
 #include "tools/common/sss_process.h"
 
-#ifdef HAVE_SYSTEMD
-    #define SSSD_SVC_CMD(cmd) "systemctl " cmd " sssd.service"
-#else
-    #define SSSD_SVC_CMD(cmd) "service sssd " cmd
-#endif
-
 static const char *
 sssctl_prompt_str(enum sssctl_prompt_result result)
 {
@@ -125,14 +119,23 @@ errno_t sssctl_run_command(const char *command)
 
 static errno_t sssctl_manage_service(enum sssctl_svc_action action)
 {
-#if defined(HAVE_SYSTEMD) || defined(HAVE_SERVICE)
+#ifdef HAVE_SYSTEMD
+    switch (action) {
+    case SSSCTL_SVC_START:
+        return sssctl_systemd_start();
+    case SSSCTL_SVC_STOP:
+        return sssctl_systemd_stop();
+    case SSSCTL_SVC_RESTART:
+        return sssctl_systemd_restart();
+    }
+#elif HAVE_SERVICE
     switch (action) {
     case SSSCTL_SVC_START:
-        return sssctl_run_command(SSSD_SVC_CMD("start"));
+        return sssctl_run_command("service sssd start");
     case SSSCTL_SVC_STOP:
-        return sssctl_run_command(SSSD_SVC_CMD("stop"));
+        return sssctl_run_command("service sssd stop");
     case SSSCTL_SVC_RESTART:
-        return sssctl_run_command(SSSD_SVC_CMD("restart"));
+        return sssctl_run_command("service sssd restart");
     }
 #endif
 
diff --git a/src/tools/sssctl/sssctl.h b/src/tools/sssctl/sssctl.h
index d4e3359..5270a9e 100644
--- a/src/tools/sssctl/sssctl.h
+++ b/src/tools/sssctl/sssctl.h
@@ -70,6 +70,10 @@ sss_sifp_error _sssctl_sifp_send(TALLOC_CTX *mem_ctx,
     _sssctl_sifp_send(mem_ctx, sifp, reply, path, iface, method,         \
                       ##__VA_ARGS__, DBUS_TYPE_INVALID);
 
+errno_t sssctl_systemd_start(void);
+errno_t sssctl_systemd_stop(void);
+errno_t sssctl_systemd_restart(void);
+
 errno_t sssctl_domain_list(struct sss_cmdline *cmdline,
                            struct sss_tool_ctx *tool_ctx,
                            void *pvt);
_______________________________________________
sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org
To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org

Reply via email to