[pve-devel] [PATCH ha-manager 1/5] remove watchdog-mux.socket

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Jan 11 13:20:14 CET 2016


The use of an systemd socket unit for the watchdog socket is not
necessary for us it even generates problems as the socket already
runs and accepts input when the watchdog-mux daemon itself is not
running. So the LRM/CRM could successfully open and update the
watchdog even if it was not running!

This patch removes the unit file, adds a postinst script which
handles the removal of the links generated from systemd itself
and removes also the code from watchdog-mux which handled
the systemd socket unit.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 debian/postinst            | 46 ++++++++++++++++++++++++++++++++++
 debian/watchdog-mux.socket | 10 --------
 src/Makefile               |  2 +-
 src/watchdog-mux.c         | 61 +++++++++++++++++-----------------------------
 4 files changed, 69 insertions(+), 50 deletions(-)
 create mode 100755 debian/postinst
 delete mode 100644 debian/watchdog-mux.socket

diff --git a/debian/postinst b/debian/postinst
new file mode 100755
index 0000000..def84e0
--- /dev/null
+++ b/debian/postinst
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+# Abort if any command returns an error value
+set -e
+
+# This script is called as the last step of the installation of the
+# package.  All the package's files are in place, dpkg has already
+# done its automatic conffile handling, and all the packages we depend
+# of are already fully installed and configured.
+
+# The following idempotent stuff doesn't generally need protecting
+# against being run in the abort-* cases.
+
+# Use debconf. (installs templates)
+. /usr/share/debconf/confmodule
+# all done with debconf here.
+db_stop
+
+case "$1" in
+  triggered)
+    # We don't print a status message here, as dpkg already said
+    # "Processing triggers for ...".
+    exit 0;;
+
+  configure)
+
+      # remove the systemd watchdog mux socket service
+      # as watchdog-mux should handle this on it's own
+      rm -f /etc/systemd/system/sockets.target.wants/watchdog-mux.socket
+      rm -f /var/lib/systemd/deb-systemd-helper-enabled/sockets.target.wants/watchdog-mux.socket
+      rm -f /var/lib/systemd/deb-systemd-helper-enabled/watchdog-mux.socket.dsh-also
+      ;;
+
+  abort-upgrade|abort-remove|abort-deconfigure)
+    exit 0
+    ;;
+
+  *)
+    echo "postinst called with unknown argument \`$1'" >&2
+    exit 1
+    ;;
+
+esac
+
+
+exit 0
diff --git a/debian/watchdog-mux.socket b/debian/watchdog-mux.socket
deleted file mode 100644
index a402038..0000000
--- a/debian/watchdog-mux.socket
+++ /dev/null
@@ -1,10 +0,0 @@
-[Unit]
-Description=Proxmox VE watchdog multiplexer socket
-
-[Socket]
-ListenStream=/run/watchdog-mux.sock
-Backlog=32
-SocketMode=0600
-
-[Install]
-WantedBy=sockets.target
diff --git a/src/Makefile b/src/Makefile
index bd0fc73..a636a5e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -45,7 +45,7 @@ ha-manager.bash-completion:
 
 
 watchdog-mux: watchdog-mux.c
-	gcc watchdog-mux.c -o watchdog-mux -Wall -Wl,-z,relro $$(pkg-config --libs --cflags libsystemd-daemon)
+	gcc watchdog-mux.c -o watchdog-mux -Wall -Wl,-z,relro
 
 .PHONY: install
 install: watchdog-mux pve-ha-crm pve-ha-lrm ha-manager.1.pod ha-manager.1.gz pve-ha-crm.1.pod pve-ha-crm.1.gz pve-ha-lrm.1.pod pve-ha-lrm.1.gz ha-manager.bash-completion pve-ha-lrm.bash-completion pve-ha-crm.bash-completion
diff --git a/src/watchdog-mux.c b/src/watchdog-mux.c
index 2b44013..a74e90c 100644
--- a/src/watchdog-mux.c
+++ b/src/watchdog-mux.c
@@ -18,8 +18,6 @@
 #include <linux/types.h>
 #include <linux/watchdog.h>
 
-#include <systemd/sd-daemon.h>
-
 #define WD_SOCK_PATH "/run/watchdog-mux.sock"
 #define WD_ACTIVE_MARKER "/run/watchdog-mux.active"
 
@@ -107,7 +105,7 @@ main(void)
     struct sockaddr_un my_addr, peer_addr;
     socklen_t peer_addr_size;
     struct epoll_event ev, events[MAX_EVENTS];
-    int socket_count, listen_sock, nfds, epollfd, sigfd;
+    int listen_sock, nfds, epollfd, sigfd;
     int unlink_socket = 0;
     
     struct stat fs;
@@ -157,45 +155,30 @@ main(void)
     fprintf(stderr, "Watchdog driver '%s', version %x\n",
             wdinfo.identity, wdinfo.firmware_version);
 
-    socket_count = sd_listen_fds(0);
-    
-    if (socket_count > 1) {
-
-        perror("too many file descriptors received.\n");
-        goto err;
-	    
-    } else if (socket_count == 1) {
-
-        listen_sock = SD_LISTEN_FDS_START + 0;
-	
-    } else {
-
-	unlink_socket = 1;
-	
-        unlink(WD_SOCK_PATH);
+    /* always unlink socket path then create socket */
+    unlink(WD_SOCK_PATH);
+    unlink_socket = 1;
 
-        listen_sock = socket(AF_UNIX, SOCK_STREAM, 0);
-        if (listen_sock == -1) {
-            perror("socket create");
-            exit(EXIT_FAILURE);
-        }
+    listen_sock = socket(AF_UNIX, SOCK_STREAM, 0);
+    if (listen_sock == -1) {
+      perror("socket create");
+      exit(EXIT_FAILURE);
+    }
+    memset(&my_addr, 0, sizeof(struct sockaddr_un));
+    my_addr.sun_family = AF_UNIX;
+    strncpy(my_addr.sun_path, WD_SOCK_PATH, sizeof(my_addr.sun_path) - 1);
+
+    if (bind(listen_sock, (struct sockaddr *) &my_addr,
+	     sizeof(struct sockaddr_un)) == -1) {
+      perror("socket bind");
+      exit(EXIT_FAILURE);
+    }
 
-        memset(&my_addr, 0, sizeof(struct sockaddr_un));
-        my_addr.sun_family = AF_UNIX;
-        strncpy(my_addr.sun_path, WD_SOCK_PATH, sizeof(my_addr.sun_path) - 1);
-	    
-        if (bind(listen_sock, (struct sockaddr *) &my_addr,
-                 sizeof(struct sockaddr_un)) == -1) {
-	    perror("socket bind");
-	    exit(EXIT_FAILURE);
-        }
-   
-        if (listen(listen_sock, LISTEN_BACKLOG) == -1) {
-	    perror("socket listen");
-	    goto err;
-        }
+    if (listen(listen_sock, LISTEN_BACKLOG) == -1) {
+      perror("socket listen");
+      goto err;
     }
-    
+
     epollfd = epoll_create(10);
     if (epollfd == -1) {
         perror("epoll_create");
-- 
2.1.4





More information about the pve-devel mailing list