Skip to content

Commit 637bc5a

Browse files
XanClicebblake
authored andcommitted
qemu-nbd: Add --pid-file option
--fork is a bit boring if there is no way to get the child's PID. This option helps. Signed-off-by: Max Reitz <[email protected]> Message-Id: <[email protected]> Signed-off-by: Eric Blake <[email protected]>
1 parent 785a602 commit 637bc5a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

qemu-nbd.c

+11
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#define QEMU_NBD_OPT_IMAGE_OPTS 262
6262
#define QEMU_NBD_OPT_FORK 263
6363
#define QEMU_NBD_OPT_TLSAUTHZ 264
64+
#define QEMU_NBD_OPT_PID_FILE 265
6465

6566
#define MBR_SIZE 512
6667

@@ -113,6 +114,7 @@ static void usage(const char *name)
113114
" specify tracing options\n"
114115
" --fork fork off the server process and exit the parent\n"
115116
" once the server is running\n"
117+
" --pid-file=PATH store the server's process ID in the given file\n"
116118
#if HAVE_NBD_DEVICE
117119
"\n"
118120
"Kernel NBD client support:\n"
@@ -641,6 +643,7 @@ int main(int argc, char **argv)
641643
{ "image-opts", no_argument, NULL, QEMU_NBD_OPT_IMAGE_OPTS },
642644
{ "trace", required_argument, NULL, 'T' },
643645
{ "fork", no_argument, NULL, QEMU_NBD_OPT_FORK },
646+
{ "pid-file", required_argument, NULL, QEMU_NBD_OPT_PID_FILE },
644647
{ NULL, 0, NULL, 0 }
645648
};
646649
int ch;
@@ -667,6 +670,7 @@ int main(int argc, char **argv)
667670
bool list = false;
668671
int old_stderr = -1;
669672
unsigned socket_activation;
673+
const char *pid_file_name = NULL;
670674

671675
/* The client thread uses SIGTERM to interrupt the server. A signal
672676
* handler ensures that "qemu-nbd -v -c" exits with a nice status code.
@@ -866,6 +870,9 @@ int main(int argc, char **argv)
866870
case 'L':
867871
list = true;
868872
break;
873+
case QEMU_NBD_OPT_PID_FILE:
874+
pid_file_name = optarg;
875+
break;
869876
}
870877
}
871878

@@ -1186,6 +1193,10 @@ int main(int argc, char **argv)
11861193

11871194
nbd_update_server_watch();
11881195

1196+
if (pid_file_name) {
1197+
qemu_write_pidfile(pid_file_name, &error_fatal);
1198+
}
1199+
11891200
/* now when the initialization is (almost) complete, chdir("/")
11901201
* to free any busy filesystems */
11911202
if (chdir("/") < 0) {

qemu-nbd.texi

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ option; or provide the credentials needed for connecting as a client
117117
in list mode.
118118
@item --fork
119119
Fork off the server process and exit the parent once the server is running.
120+
@item --pid-file=PATH
121+
Store the server's process ID in the given file.
120122
@item --tls-authz=ID
121123
Specify the ID of a qauthz object previously created with the
122124
--object option. This will be used to authorize connecting users

0 commit comments

Comments
 (0)