diff options
author | Michal Privoznik <mprivozn@redhat.com> | 2018-04-03 15:12:14 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2018-04-09 16:36:40 +0200 |
commit | 8dc0bf2647919f9f3e06380d8c748ef5b33b545d (patch) | |
tree | c0c399ce96860195cd5e35fefe47e732510cd82d /scsi/qemu-pr-helper.c | |
parent | 9f91022f28dc092e3b3250823814e4b3191c51ed (diff) |
qemu-pr-helper: Daemonize before dropping privileges
After we've dropped privileges it might be not possible to write
pidfile. For instance, if this binary is run as root (because
user wants it to write pidfile to some privileged location)
writing pidfile fails because privileges are dropped before we
even get to that.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'scsi/qemu-pr-helper.c')
-rw-r--r-- | scsi/qemu-pr-helper.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index 21e1b8ea60..eeff80acf2 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -1081,13 +1081,6 @@ 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)); @@ -1096,6 +1089,13 @@ int main(int argc, char **argv) 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 { main_loop_wait(false); |