log: print dummy timestamp if localtime call fails
authorU. Artie Eoff <ullysses.a.eoff@intel.com>
Wed, 15 Jan 2014 16:24:40 +0000 (08:24 -0800)
committerKristian Høgsberg <krh@bitplanet.net>
Mon, 20 Jan 2014 05:58:57 +0000 (21:58 -0800)
Handle the case where localtime fails (NULL) and print
something else to indicate localtime is erroneous.

Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
src/log.c

index 911b0c6..99bbe18 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -46,6 +46,9 @@ static int weston_log_timestamp(void)
        gettimeofday(&tv, NULL);
 
        brokendown_time = localtime(&tv.tv_sec);
+       if (brokendown_time == NULL)
+               return fprintf(weston_logfile, "[(NULL)localtime] ");
+
        if (brokendown_time->tm_mday != cached_tm_mday) {
                strftime(string, sizeof string, "%Y-%m-%d %Z", brokendown_time);
                fprintf(weston_logfile, "Date: %s\n", string);