Blame SOURCES/kvm-pr-helper-Rework-socket-path-handling.patch

383d26
From 5b8df1e97b5b90c9d41fd10796217bfe06951856 Mon Sep 17 00:00:00 2001
383d26
From: Paolo Bonzini <pbonzini@redhat.com>
383d26
Date: Fri, 6 Jul 2018 17:56:58 +0200
383d26
Subject: [PATCH 24/89] pr-helper: Rework socket path handling
383d26
383d26
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
383d26
Message-id: <20180706175659.30615-9-pbonzini@redhat.com>
383d26
Patchwork-id: 81252
383d26
O-Subject: [RHEL7.6 qemu-kvm-rhev PATCH 8/9] pr-helper: Rework socket path handling
383d26
Bugzilla: 1533158
383d26
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
383d26
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
383d26
RH-Acked-by: Michal Privoznik <mprivozn@redhat.com>
383d26
383d26
From: Michal Privoznik <mprivozn@redhat.com>
383d26
383d26
When reviewing Paolo's pr-helper patches I've noticed couple of
383d26
problems:
383d26
383d26
1) socket_path needs to be calculated at two different places
383d26
(one for printing out help, the other if socket activation is NOT
383d26
used),
383d26
383d26
2) even though the default socket_path is allocated in
383d26
compute_default_paths() it is the only default path the function
383d26
handles. For instance, pidfile is allocated outside of this
383d26
function. And yet again, at different places than 1)
383d26
383d26
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
383d26
Message-Id: <c791ba035f26ea957e8f3602e3009b621769b1ba.1530611283.git.mprivozn@redhat.com>
383d26
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
383d26
(cherry picked from commit 2729d79d4993099782002c9a218de1fc12c32c69)
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 scsi/qemu-pr-helper.c | 36 ++++++++++--------------------------
383d26
 1 file changed, 10 insertions(+), 26 deletions(-)
383d26
383d26
diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
383d26
index 4d843bd..bae3e55 100644
383d26
--- a/scsi/qemu-pr-helper.c
383d26
+++ b/scsi/qemu-pr-helper.c
383d26
@@ -76,14 +76,12 @@ static int gid = -1;
383d26
 
383d26
 static void compute_default_paths(void)
383d26
 {
383d26
-    if (!socket_path) {
383d26
-        socket_path = qemu_get_local_state_pathname("run/qemu-pr-helper.sock");
383d26
-    }
383d26
+    socket_path = qemu_get_local_state_pathname("run/qemu-pr-helper.sock");
383d26
+    pidfile = qemu_get_local_state_pathname("run/qemu-pr-helper.pid");
383d26
 }
383d26
 
383d26
 static void usage(const char *name)
383d26
 {
383d26
-    compute_default_paths();
383d26
     (printf) (
383d26
 "Usage: %s [OPTIONS] FILE\n"
383d26
 "Persistent Reservation helper program for QEMU\n"
383d26
@@ -830,19 +828,6 @@ static gboolean accept_client(QIOChannel *ioc, GIOCondition cond, gpointer opaqu
383d26
     return TRUE;
383d26
 }
383d26
 
383d26
-
383d26
-/*
383d26
- * Check socket parameters compatibility when socket activation is used.
383d26
- */
383d26
-static const char *socket_activation_validate_opts(void)
383d26
-{
383d26
-    if (socket_path != NULL) {
383d26
-        return "Unix socket can't be set when using socket activation";
383d26
-    }
383d26
-
383d26
-    return NULL;
383d26
-}
383d26
-
383d26
 static void termsig_handler(int signum)
383d26
 {
383d26
     atomic_cmpxchg(&state, RUNNING, TERMINATE);
383d26
@@ -916,6 +901,7 @@ int main(int argc, char **argv)
383d26
     char *trace_file = NULL;
383d26
     bool daemonize = false;
383d26
     bool pidfile_specified = false;
383d26
+    bool socket_path_specified = false;
383d26
     unsigned socket_activation;
383d26
 
383d26
     struct sigaction sa_sigterm;
383d26
@@ -932,12 +918,14 @@ int main(int argc, char **argv)
383d26
     qemu_add_opts(&qemu_trace_opts);
383d26
     qemu_init_exec_dir(argv[0]);
383d26
 
383d26
-    pidfile = qemu_get_local_state_pathname("run/qemu-pr-helper.pid");
383d26
+    compute_default_paths();
383d26
 
383d26
     while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
383d26
         switch (ch) {
383d26
         case 'k':
383d26
-            socket_path = optarg;
383d26
+            g_free(socket_path);
383d26
+            socket_path = g_strdup(optarg);
383d26
+            socket_path_specified = true;
383d26
             if (socket_path[0] != '/') {
383d26
                 error_report("socket path must be absolute");
383d26
                 exit(EXIT_FAILURE);
383d26
@@ -1028,10 +1016,9 @@ int main(int argc, char **argv)
383d26
     socket_activation = check_socket_activation();
383d26
     if (socket_activation == 0) {
383d26
         SocketAddress saddr;
383d26
-        compute_default_paths();
383d26
         saddr = (SocketAddress){
383d26
             .type = SOCKET_ADDRESS_TYPE_UNIX,
383d26
-            .u.q_unix.path = g_strdup(socket_path)
383d26
+            .u.q_unix.path = socket_path,
383d26
         };
383d26
         server_ioc = qio_channel_socket_new();
383d26
         if (qio_channel_socket_listen_sync(server_ioc, &saddr, &local_err) < 0) {
383d26
@@ -1039,12 +1026,10 @@ int main(int argc, char **argv)
383d26
             error_report_err(local_err);
383d26
             return 1;
383d26
         }
383d26
-        g_free(saddr.u.q_unix.path);
383d26
     } else {
383d26
         /* Using socket activation - check user didn't use -p etc. */
383d26
-        const char *err_msg = socket_activation_validate_opts();
383d26
-        if (err_msg != NULL) {
383d26
-            error_report("%s", err_msg);
383d26
+        if (socket_path_specified) {
383d26
+            error_report("Unix socket can't be set when using socket activation");
383d26
             exit(EXIT_FAILURE);
383d26
         }
383d26
 
383d26
@@ -1061,7 +1046,6 @@ int main(int argc, char **argv)
383d26
                          error_get_pretty(local_err));
383d26
             exit(EXIT_FAILURE);
383d26
         }
383d26
-        socket_path = NULL;
383d26
     }
383d26
 
383d26
     if (qemu_init_main_loop(&local_err)) {
383d26
-- 
383d26
1.8.3.1
383d26