cryptospore / rpms / qemu-kvm

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