[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [questions] about qemu log
From: |
William Dauchy |
Subject: |
Re: [Qemu-devel] [questions] about qemu log |
Date: |
Wed, 6 Aug 2014 22:42:45 +0200 |
On Wed, Aug 6, 2014 at 12:43 PM, William Dauchy <address@hidden> wrote:
> this make it incompatible with -daemonize option.
> there should be a possibility to detach the process and also redirect
> stderr somewhere.
I have done a quick and dirty patch for my own qemu binary so I can
use daemonize and also redirect stderr to syslog.
diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
index f131521..bf92ec1 100644
--- a/include/sysemu/os-posix.h
+++ b/include/sysemu/os-posix.h
@@ -34,6 +34,7 @@ void os_setup_signal_handling(void);
void os_daemonize(void);
void os_setup_post(void);
int os_mlock(void);
+void tolog(FILE **pfp);
typedef struct timeval qemu_timeval;
#define qemu_gettimeofday(tp) gettimeofday(tp, NULL)
diff --git a/os-posix.c b/os-posix.c
index cb2a7f7..8d8d425 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -33,6 +33,8 @@
#include <pwd.h>
#include <grp.h>
#include <libgen.h>
+#include <stdio.h>
+#include <syslog.h>
/* Needed early for CONFIG_BSD etc. */
#include "config-host.h"
@@ -250,6 +252,28 @@ void os_daemonize(void)
}
}
+static size_t writer(void *cookie, char const *data, size_t len)
+{
+ while(*data == ' ') {
+ ++data;
+ --len;
+ }
+
+ syslog(LOG_DEBUG, "%.*s", len, data);
+ return len;
+}
+
+static int noop(void) {return 0;}
+static cookie_io_functions_t log_fn = {
+ (void*) noop, (void*) writer, (void*) noop, (void*) noop
+};
+
+void tolog(FILE **pfp)
+{
+ *pfp = fopencookie(NULL, "w", log_fn);
+ setvbuf(*pfp, NULL, _IOLBF, 0);
+}
+
void os_setup_post(void)
{
int fd = 0;
@@ -280,8 +304,8 @@ void os_setup_post(void)
if (daemonize) {
dup2(fd, 0);
- dup2(fd, 1);
- dup2(fd, 2);
+ tolog(&stdout);
+ tolog(&stderr);
close(fd);
}
diff --git a/vl.c b/vl.c
index fe451aa..6b6b62c 100644
--- a/vl.c
+++ b/vl.c
@@ -3969,6 +3970,10 @@ int main(int argc, char **argv, char **envp)
loc_set_none();
os_daemonize();
+ if (is_daemonized()) {
+ tolog(&stdout);
+ tolog(&stderr);
+ }
if (qemu_init_main_loop()) {
fprintf(stderr, "qemu_init_main_loop failed\n");
--
William
- Re: [Qemu-devel] [questions] about qemu log, William Dauchy, 2014/08/05
- Re: [Qemu-devel] [questions] about qemu log, Peter Crosthwaite, 2014/08/05
- Re: [Qemu-devel] [questions] about qemu log, Zhang Haoyu, 2014/08/05
- Re: [Qemu-devel] [questions] about qemu log, Peter Crosthwaite, 2014/08/05
- Re: [Qemu-devel] [questions] about qemu log, Zhang Haoyu, 2014/08/05
- Re: [Qemu-devel] [questions] about qemu log, Markus Armbruster, 2014/08/06
- Re: [Qemu-devel] [questions] about qemu log, Zhang Haoyu, 2014/08/06
- Re: [Qemu-devel] [questions] about qemu log, Markus Armbruster, 2014/08/06
- Re: [Qemu-devel] [questions] about qemu log, Peter Crosthwaite, 2014/08/06
Re: [Qemu-devel] [questions] about qemu log, William Dauchy, 2014/08/06
- Re: [Qemu-devel] [questions] about qemu log,
William Dauchy <=