From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54869) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNlWa-0002cR-3V for qemu-devel@nongnu.org; Thu, 04 Apr 2013 10:52:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UNlWT-0002uL-KO for qemu-devel@nongnu.org; Thu, 04 Apr 2013 10:52:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2350) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNlWT-0002u3-Bo for qemu-devel@nongnu.org; Thu, 04 Apr 2013 10:52:17 -0400 Message-ID: <515D941B.5010605@redhat.com> Date: Thu, 04 Apr 2013 16:54:19 +0200 From: Laszlo Ersek MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC][PATCH]Add timestamp to error message List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Seiji Aguchi Cc: "pbonzini@redhat.com" , "dle-develop@lists.sourceforge.net" , Satoru Moriya , "qemu-devel@nongnu.org" On 02/01/13 15:53, Seiji Aguchi wrote: > /* > * Print an error message to current monitor if we have one, else to stderr. > * Format arguments like sprintf(). The result should not contain > @@ -207,6 +296,7 @@ void error_report(const char *fmt, ...) > { > va_list ap; > > + error_print_timestamp(); > error_print_loc(); > va_start(ap, fmt); > error_vprintf(fmt, ap); > -- 1.7.1 Side note: strictly in theory, this would result in two vfprintf() calls. The message log would remain "record oriented", but (again, in theory) another thread *might* get interleaved and mess up our format with a parallel call to error_report() (or more deeply, to fprintf()). Importantly I'm not talking about "corrupting data"; stdio streams are automatically locked by the fprintf() family. The thing (theoretically, possibly) corrupted would be our record-oriented message format, by interleaved printfs. (a) I'm not sure if this is possible at all in qemu. (b) Anyway, there are two ways to fix it: (b1) In error_report(), lock the stream across the two printfs with flockfile(). Probably overkill, and in case we're printing to the monitor, wasteful/useless. Or, (b2) Format the full message (including the timestamp) into a buffer (sprintf, vsprintf(), or their glib wrappers with automatic allocation, if any) and print it with a single error_printf("%s", buf). Anyway I absolutely do not insist on this, so sorry for the noise. Thanks Laszlo