From patchwork Wed Aug 6 20:42:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Dauchy X-Patchwork-Id: 377619 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2E5A1140095 for ; Thu, 7 Aug 2014 07:28:51 +1000 (EST) Received: from localhost ([::1]:41461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XF8lN-0004a9-84 for incoming@patchwork.ozlabs.org; Wed, 06 Aug 2014 17:28:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XF83R-0000aW-Ee for qemu-devel@nongnu.org; Wed, 06 Aug 2014 16:43:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XF839-0005Qj-2L for qemu-devel@nongnu.org; Wed, 06 Aug 2014 16:43:25 -0400 Received: from mail-vc0-x22d.google.com ([2607:f8b0:400c:c03::22d]:56816) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XF838-0005Pw-Sq for qemu-devel@nongnu.org; Wed, 06 Aug 2014 16:43:06 -0400 Received: by mail-vc0-f173.google.com with SMTP id hy10so4832712vcb.4 for ; Wed, 06 Aug 2014 13:43:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=Uq2q2XIXSXv+jZNpBLn7Db1bLfcoGj6zA7gsObdYxfk=; b=gElNEj52k1kacXxFgD1+RgBXrt8esM99bDdtuJ63dV+JBzT30lk/PmvWiU5pH2pIJU a4P6aQdGW2qnoh2xcglSuYWqc8CAXdMxe/qo9l/cJjDoCBc77U+xDUFQhfsllZXGpI/3 2muujJGQkP+0bYEGCKNoSOeqTryHiogOsAvaI/Ibpp/5Cnk4j5J/gdBF+iDn3yxAuNTX 45zDsFc/Lk1y3yXl+uYsnPw5KrIyKRwdq7h95rXSzVXKYrV9ATzVI1Dfat0PqTrEk2fP ECSlLTs3gyiu1FPz/F4CrzfBRlZrjbeNANXXxeo1RgHK/C5iQG9N6FD33ZbyFNyEGmEF /1vQ== X-Received: by 10.220.97.5 with SMTP id j5mr12947981vcn.16.1407357785704; Wed, 06 Aug 2014 13:43:05 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.246.38 with HTTP; Wed, 6 Aug 2014 13:42:45 -0700 (PDT) In-Reply-To: References: <201407251442088727201@sangfor.com> <874my5hh4s.fsf@linaro.org> <201407251907132706648@sangfor.com> <53D25991.3010001@suse.de> <201407261028057289331@sangfor.com> <53D7FB52.3080801@redhat.com> From: William Dauchy Date: Wed, 6 Aug 2014 22:42:45 +0200 Message-ID: To: Zhang Haoyu X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400c:c03::22d Cc: =?UTF-8?B?QWxleCBCZW5uw6ll?= , Peter Crosthwaite , =?UTF-8?Q?Andreas_F=C3=A4rber?= , qemu-devel Subject: Re: [Qemu-devel] [questions] about qemu log X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Wed, Aug 6, 2014 at 12:43 PM, William Dauchy 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 #include #include +#include +#include /* 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");