[ABRT PATCH v2 3/4] make abrtd socket activated

Jakub Filak jfilak at redhat.com
Mon Aug 26 07:28:09 UTC 2013


abrt-dump-location.path starts abrtd.service whenever the dump location
changes in order to ensure that the directory exists and has right
Selinux context, UID and GID.

Closes rhbz#963182

Signed-off-by: Jakub Filak <jfilak at redhat.com>
---
 Makefile.am                            |  2 ++
 configure.ac                           | 10 ++++++++
 init-scripts/abrt-ccpp.service         |  4 ++--
 init-scripts/abrt-dump-location.path   |  9 ++++++++
 init-scripts/abrt-oops.service         |  4 ++--
 init-scripts/abrt-pstoreoops.service   |  4 ++--
 init-scripts/abrt-upload-watch.service |  4 ++--
 init-scripts/abrt-vmcore.service       |  4 ++--
 init-scripts/abrt-xorg.service         |  4 ++--
 init-scripts/abrtd.service             |  3 ---
 init-scripts/abrtd.socket              |  5 ++++
 src/daemon/Makefile.am                 |  4 +++-
 src/daemon/abrtd.c                     | 42 +++++++++++++++++++++++-----------
 src/hooks/abrt-hook-ccpp.c             |  2 ++
 14 files changed, 72 insertions(+), 29 deletions(-)
 create mode 100644 init-scripts/abrt-dump-location.path
 create mode 100644 init-scripts/abrtd.socket

diff --git a/Makefile.am b/Makefile.am
index 3d194f3..63c45f3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,6 +36,8 @@ pkgconfig_DATA = abrt.pc
 
 if HAVE_SYSTEMD
     dist_systemdsystemunit_DATA = init-scripts/abrtd.service \
+                                  init-scripts/abrtd.socket \
+                                  init-scripts/abrt-dump-location.path \
                                   init-scripts/abrt-ccpp.service \
                                   init-scripts/abrt-oops.service \
                                   init-scripts/abrt-xorg.service \
diff --git a/configure.ac b/configure.ac
index 113b315..0a69654 100644
--- a/configure.ac
+++ b/configure.ac
@@ -109,11 +109,21 @@ PKG_CHECK_MODULES([GIO], [gio-2.0])
 PKG_CHECK_MODULES([SATYR], [satyr])
 
 PKG_PROG_PKG_CONFIG
+
+AH_TEMPLATE([HAVE_SYSTEMD],
+        [Define to 1 if you want to build abrt with systemd support.])
+
 AC_ARG_WITH([systemdsystemunitdir],
         AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
         [], [with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)])
 AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
+
 AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir"])
+[if test -n "$with_systemdsystemunitdir"]
+[then]
+    PKG_CHECK_MODULES([LIBSYSTEMD_DEAMON], [libsystemd-daemon])
+    AC_DEFINE([HAVE_SYSTEMD], [1])
+[fi]
 
 AC_ARG_WITH([dbusinterfacedir],
         AS_HELP_STRING([--with-dbusinterfacedir=DIR], [Directory for dbus interface files]),
diff --git a/init-scripts/abrt-ccpp.service b/init-scripts/abrt-ccpp.service
index 3e247eb..b5afb1c 100644
--- a/init-scripts/abrt-ccpp.service
+++ b/init-scripts/abrt-ccpp.service
@@ -1,7 +1,7 @@
 [Unit]
 Description=Install ABRT coredump hook
-After=abrtd.service
-Requisite=abrtd.service
+After=abrtd.socket
+Requisite=abrtd.socket
 
 [Service]
 Type=oneshot
diff --git a/init-scripts/abrt-dump-location.path b/init-scripts/abrt-dump-location.path
new file mode 100644
index 0000000..9231d3a
--- /dev/null
+++ b/init-scripts/abrt-dump-location.path
@@ -0,0 +1,9 @@
+[Unit]
+Description=ABRT Dump Location Watch
+After=systemd-tmpfiles-setup.service abrtd.socket
+Before=paths.target
+
+[Path]
+Unit=abrtd.service
+PathChanged=/var/tmp/abrt
+MakeDirectory=yes
diff --git a/init-scripts/abrt-oops.service b/init-scripts/abrt-oops.service
index b8b2b81..ea09e51 100644
--- a/init-scripts/abrt-oops.service
+++ b/init-scripts/abrt-oops.service
@@ -1,7 +1,7 @@
 [Unit]
 Description=ABRT kernel log watcher
-After=abrtd.service
-Requisite=abrtd.service
+After=abrtd.socket
+Requisite=abrtd.socket
 
 [Service]
 # TODO: do we really need absolute paths here?
diff --git a/init-scripts/abrt-pstoreoops.service b/init-scripts/abrt-pstoreoops.service
index 50cb6ee..e9b3426 100644
--- a/init-scripts/abrt-pstoreoops.service
+++ b/init-scripts/abrt-pstoreoops.service
@@ -1,7 +1,7 @@
 [Unit]
 Description=Collect UEFI-saved oopses for ABRT
-After=abrtd.service
-Requisite=abrtd.service
+After=abrtd.socket
+Requisite=abrtd.socket
 ConditionDirectoryNotEmpty=/sys/fs/pstore
 
 [Service]
diff --git a/init-scripts/abrt-upload-watch.service b/init-scripts/abrt-upload-watch.service
index 47ccf71..2d07ef8 100644
--- a/init-scripts/abrt-upload-watch.service
+++ b/init-scripts/abrt-upload-watch.service
@@ -1,7 +1,7 @@
 [Unit]
 Description=ABRT upload watcher
-After=abrtd.service
-Requisite=abrtd.service
+After=abrtd.socket
+Requisite=abrtd.socket
 
 [Service]
 ExecStart=/usr/sbin/abrt-upload-watch
diff --git a/init-scripts/abrt-vmcore.service b/init-scripts/abrt-vmcore.service
index 000f0e3..185e5e6 100644
--- a/init-scripts/abrt-vmcore.service
+++ b/init-scripts/abrt-vmcore.service
@@ -1,7 +1,7 @@
 [Unit]
 Description=Harvest vmcores for ABRT
-After=abrtd.service
-Requisite=abrtd.service
+After=abrtd.socket
+Requisite=abrtd.socket
 ConditionDirectoryNotEmpty=/var/crash
 
 [Service]
diff --git a/init-scripts/abrt-xorg.service b/init-scripts/abrt-xorg.service
index c3af56f..58f165c 100644
--- a/init-scripts/abrt-xorg.service
+++ b/init-scripts/abrt-xorg.service
@@ -1,7 +1,7 @@
 [Unit]
 Description=ABRT Xorg log watcher
-After=abrtd.service
-Requisite=abrtd.service
+After=abrtd.socket
+Requisite=abrtd.socket
 ConditionPathExists=/var/log/Xorg.0.log
 
 [Service]
diff --git a/init-scripts/abrtd.service b/init-scripts/abrtd.service
index 9ce15ec..12dd803 100644
--- a/init-scripts/abrtd.service
+++ b/init-scripts/abrtd.service
@@ -7,6 +7,3 @@ After=syslog.target livesys.service
 
 [Service]
 ExecStart=/usr/sbin/abrtd -d -s
-
-[Install]
-WantedBy=multi-user.target
diff --git a/init-scripts/abrtd.socket b/init-scripts/abrtd.socket
new file mode 100644
index 0000000..38a3d86
--- /dev/null
+++ b/init-scripts/abrtd.socket
@@ -0,0 +1,5 @@
+[Socket]
+ListenStream=/var/run/abrt/abrt.socket
+
+[Install]
+WantedBy=sockets.target
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am
index 9369d26..e1ed43b 100644
--- a/src/daemon/Makefile.am
+++ b/src/daemon/Makefile.am
@@ -29,11 +29,13 @@ abrtd_CPPFLAGS = \
     -DLIBEXEC_DIR=\"$(libexecdir)\" \
     $(GLIB_CFLAGS) \
     $(LIBREPORT_CFLAGS) \
+    $(LIBSYSTEMD_DEAMON_CFLAGS) \
     -D_GNU_SOURCE \
     -fPIE
 abrtd_LDADD = \
     ../lib/libabrt.la \
-    $(LIBREPORT_LIBS)
+    $(LIBREPORT_LIBS) \
+    $(LIBSYSTEMD_DEAMON_LIBS)
 abrtd_LDFLAGS = \
     -Wl,-z,relro -Wl,-z,now \
     -pie
diff --git a/src/daemon/abrtd.c b/src/daemon/abrtd.c
index 8196d39..239c43d 100644
--- a/src/daemon/abrtd.c
+++ b/src/daemon/abrtd.c
@@ -16,16 +16,21 @@
     with this program; if not, write to the Free Software Foundation, Inc.,
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
+#include "libabrt.h"
+
 #if HAVE_LOCALE_H
 # include <locale.h>
 #endif
+
+#if HAVE_SYSTEMD
+# include <systemd/sd-daemon.h>
+#endif
+
 #include <sys/un.h>
 #include <syslog.h>
 
 #include "abrt_glib.h"
 #include "abrt-inotify.h"
-#include "libabrt.h"
-
 
 /* I want to use -Werror, but gcc-4.4 throws a curveball:
  * "warning: ignoring return value of 'ftruncate', declared with attribute warn_unused_result"
@@ -287,20 +292,31 @@ static void run_main_loop(GMainLoop* loop)
  */
 static void dumpsocket_init(void)
 {
-    unlink(SOCKET_FILE); /* not caring about the result */
+    int socketfd;
+#if HAVE_SYSTEMD
+    const int n = sd_listen_fds(0);
+    if (n > 1)
+        error_msg_and_die(_("Too many file descriptors received"));
+    else if (n == 1)
+        socketfd = SD_LISTEN_FDS_START + 0;
+    else
+#endif
+    {
+        unlink(SOCKET_FILE); /* not caring about the result */
 
-    int socketfd = xsocket(AF_UNIX, SOCK_STREAM, 0);
-    close_on_exec_on(socketfd);
+        socketfd = xsocket(AF_UNIX, SOCK_STREAM, 0);
+        close_on_exec_on(socketfd);
 
-    struct sockaddr_un local;
-    memset(&local, 0, sizeof(local));
-    local.sun_family = AF_UNIX;
-    strcpy(local.sun_path, SOCKET_FILE);
-    xbind(socketfd, (struct sockaddr*)&local, sizeof(local));
-    xlisten(socketfd, MAX_CLIENT_COUNT);
+        struct sockaddr_un local;
+        memset(&local, 0, sizeof(local));
+        local.sun_family = AF_UNIX;
+        strcpy(local.sun_path, SOCKET_FILE);
+        xbind(socketfd, (struct sockaddr*)&local, sizeof(local));
+        xlisten(socketfd, MAX_CLIENT_COUNT);
 
-    if (chmod(SOCKET_FILE, SOCKET_PERMISSION) != 0)
-        perror_msg_and_die("chmod '%s'", SOCKET_FILE);
+        if (chmod(SOCKET_FILE, SOCKET_PERMISSION) != 0)
+            perror_msg_and_die("chmod '%s'", SOCKET_FILE);
+    }
 
     channel_socket = abrt_gio_channel_unix_new(socketfd);
 
diff --git a/src/hooks/abrt-hook-ccpp.c b/src/hooks/abrt-hook-ccpp.c
index aa66bb6..bbc4e34 100644
--- a/src/hooks/abrt-hook-ccpp.c
+++ b/src/hooks/abrt-hook-ccpp.c
@@ -606,6 +606,7 @@ int main(int argc, char** argv)
         default: goto create_user_core; // not a signal we care about
     }
 
+#if !HAVE_SYSTEMD
     if (!daemon_is_ok())
     {
         /* not an error, exit with exit code 0 */
@@ -615,6 +616,7 @@ int main(int argc, char** argv)
         );
         goto create_user_core;
     }
+#endif
 
     if (g_settings_nMaxCrashReportsSize > 0)
     {
-- 
1.8.3.1



More information about the Crash-catcher mailing list