[PATCH 03/10] Add timestamping to logging functions

Alan Coopersmith Alan.Coopersmith at Sun.COM
Tue Jan 5 10:37:21 PST 2010


strftime isn't signal safe, but I see some of the signal handlers log.

(And I also see we need to dump the old SysV/unreliable signal() crud and
 move them all to reliable POSIX sigaction() to cleanup the UNRELIABLE_SIGNALS
 and SIGNALS_RESET_WHEN_CAUGHT bits of code, but that's a different issue.)

	-alan-

Julien Cristau wrote:
> Based on patch by Branden Robinson <branden at debian.org>
> ---
>  error.c |   20 +++++++++++++++++---
>  1 files changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/error.c b/error.c
> index d1bd16e..4f5eb6b 100644
> --- a/error.c
> +++ b/error.c
> @@ -64,9 +64,6 @@ LogVWrite(const char *fmt, va_list args)
>  	va_end(args);		\
>      } while(0)
>  
> -#define LogHeader(type)		\
> -    LogAppend("xdm %s (pid %ld): ", type, (long)getpid())
> -
>  /* Append more text to the log without a new header, right after
>     having called LogInfo or LogError */
>  void
> @@ -75,6 +72,23 @@ LogAppend(const char * fmt, ...)
>      LogVarArgsWrite(fmt);
>  }
>  
> +static void
> +LogHeader(const char *type) {
> +    time_t seconds;
> +    size_t rc = 0;
> +    struct tm *timestamp = NULL;
> +    char timebuf[256];
> +    if (time(&seconds) != (time_t) -1)
> +	timestamp = localtime(&seconds);
> +
> +    if (timestamp)
> +	rc = strftime(timebuf, 255, "%c", timestamp);
> +    if (!rc)
> +	strcpy(timebuf, "(time unavailable)");
> +
> +    LogAppend("%s xdm %s (pid %ld): ", timebuf, type, (long)getpid());
> +}
> +
>  void
>  LogInfo(const char * fmt, ...)
>  {

-- 
	-Alan Coopersmith-           alan.coopersmith at sun.com
	 Sun Microsystems, Inc. - X Window System Engineering



More information about the xorg-devel mailing list