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

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