Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> --- qemu-nbd.c | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/qemu-nbd.c b/qemu-nbd.c index 573bf3d..5031158 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -30,6 +30,7 @@ #include <netinet/tcp.h> #include <arpa/inet.h> #include <signal.h> +#include <syslog.h> #include <libgen.h> #define SOCKET_PATH "/var/lock/qemu-nbd-%s" @@ -37,6 +38,7 @@ #define NBD_BUFFER_SIZE (1024*1024) static int verbose; +static int daemonized; static void usage(const char *name) { @@ -87,7 +89,11 @@ static void err(int status, const char *format, ...) if (vasprintf(&s, format, ap) == -1) { abort(); } - fprintf(stderr, "qemu-nbd: %s: %s\n", s, msg); + if (daemonized) { + syslog(LOG_ERR, "%s: %s", s, msg); + } else { + fprintf(stderr, "qemu-nbd: %s: %s\n", s, msg); + } free(s); exit(status); } @@ -101,7 +107,11 @@ static void errx(int status, const char *format, ...) if (vasprintf(&s, format, ap) == -1) { abort(); } - fprintf(stderr, "qemu-nbd: %s\n", s); + if (daemonized) { + syslog(LOG_ERR, "%s", s); + } else { + fprintf(stderr, "qemu-nbd: %s\n", s); + } free(s); exit(status); } @@ -387,9 +397,11 @@ int main(int argc, char **argv) if (!verbose) { /* detach client and server */ + openlog("qemu-nbd", LOG_PID, LOG_USER); if (qemu_daemon(0, 0) == -1) { err(EXIT_FAILURE, "Failed to daemonize"); } + daemonized = 1; } if (socket == NULL) { -- 1.7.6.4