aboutsummaryrefslogtreecommitdiff
path: root/scsi/qemu-pr-helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'scsi/qemu-pr-helper.c')
-rw-r--r--scsi/qemu-pr-helper.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
index 21e1b8ea60..d0f83176e1 100644
--- a/scsi/qemu-pr-helper.c
+++ b/scsi/qemu-pr-helper.c
@@ -924,6 +924,7 @@ int main(int argc, char **argv)
Error *local_err = NULL;
char *trace_file = NULL;
bool daemonize = false;
+ bool pidfile_specified = false;
unsigned socket_activation;
struct sigaction sa_sigterm;
@@ -954,6 +955,7 @@ int main(int argc, char **argv)
case 'f':
g_free(pidfile);
pidfile = g_strdup(optarg);
+ pidfile_specified = true;
break;
#ifdef CONFIG_LIBCAP
case 'u': {
@@ -1081,20 +1083,22 @@ int main(int argc, char **argv)
accept_client,
NULL, NULL);
-#ifdef CONFIG_LIBCAP
- if (drop_privileges() < 0) {
- error_report("Failed to drop privileges: %s", strerror(errno));
- exit(EXIT_FAILURE);
- }
-#endif
-
if (daemonize) {
if (daemon(0, 0) < 0) {
error_report("Failed to daemonize: %s", strerror(errno));
exit(EXIT_FAILURE);
}
+ }
+
+ if (daemonize || pidfile_specified)
write_pidfile();
+
+#ifdef CONFIG_LIBCAP
+ if (drop_privileges() < 0) {
+ error_report("Failed to drop privileges: %s", strerror(errno));
+ exit(EXIT_FAILURE);
}
+#endif
state = RUNNING;
do {