Add spec/cmake define to enable/disable askuser service 80/101280/1
authorZofia Abramowska <z.abramowska@samsung.com>
Mon, 18 Jul 2016 10:51:28 +0000 (12:51 +0200)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Wed, 30 Nov 2016 13:42:07 +0000 (14:42 +0100)
Make usage of systemd daemon configurable.
Remove obsolete systemd libraries and use new one.

Change-Id: I4f4e29932fea3c2c39152094f64012b3245610f1

CMakeLists.txt
packaging/askuser.spec
src/agent/CMakeLists.txt
src/agent/main/main.cpp
src/agent/notification-daemon/CMakeLists.txt
src/agent/notification-daemon/main.cpp
src/common/CMakeLists.txt

index 3601860..e0d174b 100644 (file)
@@ -68,6 +68,10 @@ IF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
     ADD_DEFINITIONS("-DBUILD_TYPE_DEBUG")
 ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
 
+IF (BUILD_WITH_SYSTEMD_DAEMON)
+    ADD_DEFINITIONS("-DBUILD_WITH_SYSTEMD_DAEMON")
+ENDIF (BUILD_WITH_SYSTEMD_DAEMON)
+
 SET(TARGET_ASKUSER "askuser")
 SET(TARGET_ASKUSER_COMMON "askuser-common")
 SET(TARGET_PLUGIN_SERVICE "askuser-plugin-service")
@@ -78,5 +82,7 @@ SET(TARGET_TEST "askuser-test")
 SET(TARGET_TESTS "askuser-tests")
 
 ADD_SUBDIRECTORY(src)
+IF (BUILD_WITH_SYSTEMD_DAEMON)
 ADD_SUBDIRECTORY(systemd)
+ENDIF (BUILD_WITH_SYSTEMD_DAEMON)
 ADD_SUBDIRECTORY(test)
index c182f83..a9e94fb 100644 (file)
@@ -1,3 +1,7 @@
+%if !%{defined with_systemd_daemon}
+%define with_systemd_daemon 0 
+%endif
+
 Name:       askuser
 Summary:    Agent service for Cynara 'ask user' policy
 Version:    0.1.4
@@ -17,13 +21,11 @@ BuildRequires: pkgconfig(cynara-agent)
 BuildRequires: pkgconfig(cynara-creds-socket)
 BuildRequires: pkgconfig(cynara-plugin)
 BuildRequires: pkgconfig(elementary)
-BuildRequires: pkgconfig(libsystemd-daemon)
-BuildRequires: pkgconfig(libsystemd-journal)
+BuildRequires: pkgconfig(libsystemd)
 BuildRequires: pkgconfig(security-manager)
 BuildRequires: pkgconfig(security-privilege-manager)
 BuildRequires: pkgconfig(glib-2.0)
 BuildRequires: coregl
-%{?systemd_requires}
 
 %if !%{defined build_type}
 %define build_type RELEASE
@@ -81,6 +83,7 @@ export LDFLAGS+="-Wl,--rpath=%{_libdir}"
 
 %cmake . \
         -DCMAKE_BUILD_TYPE=%{?build_type} \
+        -DBUILD_WITH_SYSTEMD_DAEMON=%{?with_systemd_daemon} \
         -DCMAKE_VERBOSE_MAKEFILE=ON
 make %{?jobs:-j%jobs}
 
@@ -90,6 +93,7 @@ rm -rf %{buildroot}
 %find_lang %{name}
 
 %post
+%if %{with_systemd_daemon}
 # todo properly use systemd --user
 ln -s /lib/systemd/user/askuser-notification.service \
 /usr/lib/systemd/user/default.target.wants/askuser-notification.service
@@ -103,17 +107,23 @@ if [ $1 = 1 ]; then
 fi
 
 systemctl restart askuser.service
+%endif
+
 systemctl restart cynara.service
 
 %preun
+%if %{with_systemd_daemon}
 if [ $1 = 0 ]; then
     systemctl stop askuser.service
 fi
+%endif
 
 %postun
+%if %{with_systemd_daemon}
 if [ $1 = 0 ]; then
     systemctl daemon-reload
 fi
+%endif
 
 systemctl restart cynara.service
 
@@ -125,13 +135,17 @@ systemctl restart cynara.service
 %manifest %{name}.manifest
 %license LICENSE
 %attr(755, root, root) /usr/bin/askuser
+%if %{with_systemd_daemon}
 /usr/lib/systemd/system/askuser.service
+%endif
 
 %files -n askuser-notification
 %manifest askuser-notification.manifest
 %license LICENSE
 %attr(755,root,root) /usr/bin/askuser-notification
+%if %{with_systemd_daemon}
 /usr/lib/systemd/user/askuser-notification.service
+%endif
 /usr/share/locale/en/LC_MESSAGES/askuser.mo
 /usr/share/locale/pl/LC_MESSAGES/askuser.mo
 
index 85cbdd9..7280ca8 100644 (file)
@@ -21,7 +21,7 @@ PKG_CHECK_MODULES(AGENT_DEP
     cynara-agent
     cynara-plugin
     cynara-creds-socket
-    libsystemd-daemon
+    libsystemd
     security-privilege-manager
     glib-2.0
     )
index aa1f48b..d60bf25 100644 (file)
 #include <cstdlib>
 #include <cstring>
 #include <exception>
-#include <systemd/sd-journal.h>
-#include <systemd/sd-daemon.h>
-
 #include <attributes/attributes.h>
-
 #include <log/alog.h>
 
+#ifdef BUILD_WITH_SYSTEMD_DAEMON
+#include <systemd/sd-daemon.h>
+#endif
+
 #include "Agent.h"
 
 // Handle kill message from systemd
@@ -59,13 +59,14 @@ int main(int argc UNUSED, char **argv UNUSED) {
     try {
         AskUser::Agent::Agent agent;
 
+#ifdef BUILD_WITH_SYSTEMD_DAEMON
         int ret = sd_notify(0, "READY=1");
         if (ret == 0) {
             ALOGW("Agent was not configured to notify its status");
         } else if (ret < 0) {
             ALOGE("sd_notify failed: [" << ret << "]");
         }
-
+#endif
         agent.run();
     } catch (const std::exception &e) {
         ALOGC("Agent stopped because of unhandled exception: <" << e.what() << ">");
index 6306965..6fa05f4 100644 (file)
@@ -4,7 +4,7 @@ PKG_CHECK_MODULES(ASKUSER_NOTIFICATION_DEP
     REQUIRED
     elementary
     cynara-agent
-    libsystemd-daemon
+    libsystemd
     security-manager
     security-privilege-manager
 )
index c23d6b3..3d0a46e 100644 (file)
 #include <csignal>
 #include <cstdlib>
 #include <string>
-#include <systemd/sd-daemon.h>
 #include <thread>
 #include <unistd.h>
 
+#ifdef BUILD_WITH_SYSTEMD_DAEMON
+#include <systemd/sd-daemon.h>
+#endif
+
 #include <exception/Exception.h>
 #include <log/alog.h>
 
@@ -45,12 +48,14 @@ int main()
         GuiRunner gui;
         AskUserTalker askUserTalker(&gui);
 
+#ifdef BUILD_WITH_SYSTEMD_DAEMON
         int ret = sd_notify(0, "READY=1");
         if (ret == 0) {
             ALOGW("Agent was not configured to notify its status");
         } else if (ret < 0) {
             ALOGE("sd_notify failed: [" << ret << "]");
         }
+#endif
 
         askUserTalker.run();
 
index 43d52db..57f9ad9 100644 (file)
@@ -19,7 +19,7 @@ PKG_CHECK_MODULES(COMMON_DEP
     REQUIRED
     cynara-plugin
     cynara-agent
-    libsystemd-journal
+    libsystemd
     )
 
 SET(ASKUSER_COMMON_VERSION_MAJOR 0)