X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=qemu-nbd.c;h=a8cb39e51043a9f2731e1c8df26cfe1d7a3835ee;hb=6b7ac49d570c66754fad1b80cc200c7596d1facd;hp=410373a3218260eec241d754a9f573927b343da6;hpb=0b8fa32f551e863bb548a11394239239270dd3dc;p=mirror_qemu.git diff --git a/qemu-nbd.c b/qemu-nbd.c index 410373a321..a8cb39e510 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -21,6 +21,7 @@ #include #include +#include "qemu-common.h" #include "qapi/error.h" #include "qemu/cutils.h" #include "sysemu/block-backend.h" @@ -60,6 +61,7 @@ #define QEMU_NBD_OPT_IMAGE_OPTS 262 #define QEMU_NBD_OPT_FORK 263 #define QEMU_NBD_OPT_TLSAUTHZ 264 +#define QEMU_NBD_OPT_PID_FILE 265 #define MBR_SIZE 512 @@ -112,6 +114,7 @@ static void usage(const char *name) " specify tracing options\n" " --fork fork off the server process and exit the parent\n" " once the server is running\n" +" --pid-file=PATH store the server's process ID in the given file\n" #if HAVE_NBD_DEVICE "\n" "Kernel NBD client support:\n" @@ -640,6 +643,7 @@ int main(int argc, char **argv) { "image-opts", no_argument, NULL, QEMU_NBD_OPT_IMAGE_OPTS }, { "trace", required_argument, NULL, 'T' }, { "fork", no_argument, NULL, QEMU_NBD_OPT_FORK }, + { "pid-file", required_argument, NULL, QEMU_NBD_OPT_PID_FILE }, { NULL, 0, NULL, 0 } }; int ch; @@ -666,6 +670,7 @@ int main(int argc, char **argv) bool list = false; int old_stderr = -1; unsigned socket_activation; + const char *pid_file_name = NULL; /* The client thread uses SIGTERM to interrupt the server. A signal * handler ensures that "qemu-nbd -v -c" exits with a nice status code. @@ -865,6 +870,9 @@ int main(int argc, char **argv) case 'L': list = true; break; + case QEMU_NBD_OPT_PID_FILE: + pid_file_name = optarg; + break; } } @@ -996,10 +1004,11 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } else if (pid == 0) { close(stderr_fd[0]); + + old_stderr = dup(STDERR_FILENO); ret = qemu_daemon(1, 0); /* Temporarily redirect stderr to the parent's pipe... */ - old_stderr = dup(STDERR_FILENO); dup2(stderr_fd[1], STDERR_FILENO); if (ret < 0) { error_report("Failed to daemonize: %s", strerror(errno)); @@ -1185,6 +1194,10 @@ int main(int argc, char **argv) nbd_update_server_watch(); + if (pid_file_name) { + qemu_write_pidfile(pid_file_name, &error_fatal); + } + /* now when the initialization is (almost) complete, chdir("/") * to free any busy filesystems */ if (chdir("/") < 0) {