@@ -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)
@@ -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);
}
@@ -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");