qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Akihiko Odaki <akihiko.odaki@daynix.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org,
	virtio-fs@redhat.com,  Yuval Shaia <yuval.shaia.ml@gmail.com>,
	 Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	 Konstantin Kostiuk <kkostiuk@redhat.com>,
	 Michael Roth <michael.roth@amd.com>,
	Paolo Bonzini <pbonzini@redhat.com>,  Fam Zheng <fam@euphon.net>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	 Stefan Hajnoczi <stefanha@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>,  Stefan Weil <sw@weilnetz.de>,
	Yan Vugenfirer <yan@daynix.com>,
	 Akihiko Odaki <akihiko.odaki@daynix.com>
Subject: [PATCH v4 2/7] ivshmem-server: Use qemu_get_runtime_dir()
Date: Tue, 16 Jul 2024 16:27:32 +0900	[thread overview]
Message-ID: <20240716-run-v4-2-5f7a29631168@daynix.com> (raw)
In-Reply-To: <20240716-run-v4-0-5f7a29631168@daynix.com>

qemu_get_runtime_dir() is used to construct the default PID file path.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-Id: <20230921075425.16738-3-akihiko.odaki@daynix.com>
---
 contrib/ivshmem-server/main.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/contrib/ivshmem-server/main.c b/contrib/ivshmem-server/main.c
index 5901f17707e0..313124dd4520 100644
--- a/contrib/ivshmem-server/main.c
+++ b/contrib/ivshmem-server/main.c
@@ -14,7 +14,6 @@
 
 #define IVSHMEM_SERVER_DEFAULT_VERBOSE        0
 #define IVSHMEM_SERVER_DEFAULT_FOREGROUND     0
-#define IVSHMEM_SERVER_DEFAULT_PID_FILE       "/var/run/ivshmem-server.pid"
 #define IVSHMEM_SERVER_DEFAULT_UNIX_SOCK_PATH "/tmp/ivshmem_socket"
 #define IVSHMEM_SERVER_DEFAULT_SHM_PATH       "ivshmem"
 #define IVSHMEM_SERVER_DEFAULT_SHM_SIZE       (4 * 1024 * 1024)
@@ -35,15 +34,23 @@ typedef struct IvshmemServerArgs {
     unsigned n_vectors;
 } IvshmemServerArgs;
 
+static char *ivshmem_server_get_default_pid_file(void)
+{
+    g_autofree char *run = qemu_get_runtime_dir();
+    return g_build_filename(run, "ivshmem-server.pid", NULL);
+}
+
 static void
 ivshmem_server_usage(const char *progname)
 {
+    g_autofree char *pid_file = ivshmem_server_get_default_pid_file();
+
     printf("Usage: %s [OPTION]...\n"
            "  -h: show this help\n"
            "  -v: verbose mode\n"
            "  -F: foreground mode (default is to daemonize)\n"
            "  -p <pid-file>: path to the PID file (used in daemon mode only)\n"
-           "     default " IVSHMEM_SERVER_DEFAULT_PID_FILE "\n"
+           "     default %s\n"
            "  -S <unix-socket-path>: path to the unix socket to listen to\n"
            "     default " IVSHMEM_SERVER_DEFAULT_UNIX_SOCK_PATH "\n"
            "  -M <shm-name>: POSIX shared memory object to use\n"
@@ -54,7 +61,7 @@ ivshmem_server_usage(const char *progname)
            "     default %u\n"
            "  -n <nvectors>: number of vectors\n"
            "     default %u\n",
-           progname, IVSHMEM_SERVER_DEFAULT_SHM_SIZE,
+           progname, pid_file, IVSHMEM_SERVER_DEFAULT_SHM_SIZE,
            IVSHMEM_SERVER_DEFAULT_N_VECTORS);
 }
 
@@ -189,10 +196,10 @@ main(int argc, char *argv[])
 {
     IvshmemServer server;
     struct sigaction sa, sa_quit;
+    g_autofree char *default_pid_file = NULL;
     IvshmemServerArgs args = {
         .verbose = IVSHMEM_SERVER_DEFAULT_VERBOSE,
         .foreground = IVSHMEM_SERVER_DEFAULT_FOREGROUND,
-        .pid_file = IVSHMEM_SERVER_DEFAULT_PID_FILE,
         .unix_socket_path = IVSHMEM_SERVER_DEFAULT_UNIX_SOCK_PATH,
         .shm_path = IVSHMEM_SERVER_DEFAULT_SHM_PATH,
         .use_shm_open = true,
@@ -207,6 +214,11 @@ main(int argc, char *argv[])
      */
     printf("*** Example code, do not use in production ***\n");
 
+    qemu_init_exec_dir(argv[0]);
+
+    default_pid_file = ivshmem_server_get_default_pid_file();
+    args.pid_file = default_pid_file;
+
     /* parse arguments, will exit on error */
     ivshmem_server_parse_args(&args, argc, argv);
 

-- 
2.45.2



  parent reply	other threads:[~2024-07-16  7:29 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-16  7:27 [PATCH v4 0/7] util: Introduce qemu_get_runtime_dir() Akihiko Odaki
2024-07-16  7:27 ` [PATCH v4 1/7] " Akihiko Odaki
2024-07-16  9:53   ` Daniel P. Berrangé
2024-07-16 10:52     ` Akihiko Odaki
2024-07-16 10:54       ` Daniel P. Berrangé
2024-07-16 11:27         ` Akihiko Odaki
2024-07-16  7:27 ` Akihiko Odaki [this message]
2024-07-16  7:27 ` [PATCH v4 3/7] qga: Use qemu_get_runtime_dir() Akihiko Odaki
2024-07-16  7:27 ` [PATCH v4 4/7] scsi: " Akihiko Odaki
2024-07-16  7:27 ` [PATCH v4 5/7] module: " Akihiko Odaki
2024-07-16  7:27 ` [PATCH v4 6/7] util: Remove qemu_get_local_state_dir() Akihiko Odaki
2024-07-16  7:27 ` [PATCH v4 7/7] spice-app: Use qemu_get_runtime_dir() Akihiko Odaki
2024-07-16  8:06 ` [PATCH v4 0/7] util: Introduce qemu_get_runtime_dir() Michael Tokarev
2024-07-16  9:32   ` Akihiko Odaki
2024-07-16  9:41     ` Michael Tokarev
2024-07-16  9:56   ` Daniel P. Berrangé
2024-07-16 10:43     ` Paolo Bonzini
2024-07-16 12:45       ` Akihiko Odaki
2024-07-16 13:29         ` Paolo Bonzini
2024-07-16 13:35           ` Akihiko Odaki
2024-07-16  8:45 ` Paolo Bonzini
2025-01-11  5:15 ` Akihiko Odaki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240716-run-v4-2-5f7a29631168@daynix.com \
    --to=akihiko.odaki@daynix.com \
    --cc=dgilbert@redhat.com \
    --cc=fam@euphon.net \
    --cc=kkostiuk@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=sw@weilnetz.de \
    --cc=virtio-fs@redhat.com \
    --cc=yan@daynix.com \
    --cc=yuval.shaia.ml@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).