From nobody Tue Nov 4 15:28:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153061177283642.91650337216038; Tue, 3 Jul 2018 02:56:12 -0700 (PDT) Received: from localhost ([::1]:39277 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faI2e-0008V7-3H for importer@patchew.org; Tue, 03 Jul 2018 05:56:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faHy2-0005vd-MS for qemu-devel@nongnu.org; Tue, 03 Jul 2018 05:51:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faHy1-0000lG-Kl for qemu-devel@nongnu.org; Tue, 03 Jul 2018 05:51:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53888 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1faHxx-0000gF-33; Tue, 03 Jul 2018 05:51:21 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9180E4067720; Tue, 3 Jul 2018 09:51:19 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-103.brq.redhat.com [10.40.204.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FC472156880; Tue, 3 Jul 2018 09:51:18 +0000 (UTC) From: Michal Privoznik To: qemu-devel@nongnu.org Date: Tue, 3 Jul 2018 11:51:14 +0200 Message-Id: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 03 Jul 2018 09:51:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 03 Jul 2018 09:51:19 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mprivozn@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] pr-helper: Rework socket path handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, famz@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When reviewing Paolo's pr-helper patches I've noticed couple of problems: 1) socket_path needs to be calculated at two different places (one for printing out help, the other if socket activation is NOT used), 2) even though the default socket_path is allocated in compute_default_paths() it is the only default path the function handles. For instance, pidfile is allocated outside of this function. And yet again, at different places than 1) Signed-off-by: Michal Privoznik --- scsi/qemu-pr-helper.c | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index 0218d65bbf..59df3fd608 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -76,14 +76,12 @@ static int gid =3D -1; =20 static void compute_default_paths(void) { - if (!socket_path) { - socket_path =3D qemu_get_local_state_pathname("run/qemu-pr-helper.= sock"); - } + socket_path =3D qemu_get_local_state_pathname("run/qemu-pr-helper.sock= "); + pidfile =3D qemu_get_local_state_pathname("run/qemu-pr-helper.pid"); } =20 static void usage(const char *name) { - compute_default_paths(); (printf) ( "Usage: %s [OPTIONS] FILE\n" "Persistent Reservation helper program for QEMU\n" @@ -844,19 +842,6 @@ static gboolean accept_client(QIOChannel *ioc, GIOCond= ition cond, gpointer opaqu return TRUE; } =20 - -/* - * Check socket parameters compatibility when socket activation is used. - */ -static const char *socket_activation_validate_opts(void) -{ - if (socket_path !=3D NULL) { - return "Unix socket can't be set when using socket activation"; - } - - return NULL; -} - static void termsig_handler(int signum) { atomic_cmpxchg(&state, RUNNING, TERMINATE); @@ -930,6 +915,7 @@ int main(int argc, char **argv) char *trace_file =3D NULL; bool daemonize =3D false; bool pidfile_specified =3D false; + bool socket_path_specified =3D false; unsigned socket_activation; =20 struct sigaction sa_sigterm; @@ -946,12 +932,14 @@ int main(int argc, char **argv) qemu_add_opts(&qemu_trace_opts); qemu_init_exec_dir(argv[0]); =20 - pidfile =3D qemu_get_local_state_pathname("run/qemu-pr-helper.pid"); + compute_default_paths(); =20 while ((ch =3D getopt_long(argc, argv, sopt, lopt, &opt_ind)) !=3D -1)= { switch (ch) { case 'k': - socket_path =3D optarg; + g_free(socket_path); + socket_path =3D g_strdup(optarg); + socket_path_specified =3D true; if (socket_path[0] !=3D '/') { error_report("socket path must be absolute"); exit(EXIT_FAILURE); @@ -1042,10 +1030,9 @@ int main(int argc, char **argv) socket_activation =3D check_socket_activation(); if (socket_activation =3D=3D 0) { SocketAddress saddr; - compute_default_paths(); saddr =3D (SocketAddress){ .type =3D SOCKET_ADDRESS_TYPE_UNIX, - .u.q_unix.path =3D g_strdup(socket_path) + .u.q_unix.path =3D socket_path, }; server_ioc =3D qio_channel_socket_new(); if (qio_channel_socket_listen_sync(server_ioc, &saddr, &local_err)= < 0) { @@ -1053,12 +1040,10 @@ int main(int argc, char **argv) error_report_err(local_err); return 1; } - g_free(saddr.u.q_unix.path); } else { /* Using socket activation - check user didn't use -p etc. */ - const char *err_msg =3D socket_activation_validate_opts(); - if (err_msg !=3D NULL) { - error_report("%s", err_msg); + if (socket_path_specified) { + error_report("Unix socket can't be set when using socket activ= ation"); exit(EXIT_FAILURE); } =20 @@ -1075,7 +1060,6 @@ int main(int argc, char **argv) error_get_pretty(local_err)); exit(EXIT_FAILURE); } - socket_path =3D NULL; } =20 if (qemu_init_main_loop(&local_err)) { --=20 2.16.4