~ubuntu-branches/ubuntu/lucid/rsyslog/lucid-updates

« back to all changes in this revision

Viewing changes to runtime/datetime.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-06-23 12:12:43 UTC
  • mfrom: (1.1.11 upstream) (3.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20090623121243-d2fejarzidywnn17
Tags: 4.2.0-1
* New upstream release of the now stable v4 branch.
  - Fix warnings when /etc/rsyslog.d/ is empty. Closes: #530228
* debian/patches/imudp_multiple_udp_sockets.patch
  - Removed, merged upstream.
* debian/rsyslog.default
  - Set default compat mode to '4'.
* debian/rsyslog.logcheck.ignore.server
  - Update logcheck rules files to also ignore rsyslogd and imklog stop
    messages.
* debian/control
  - Bump Standards-Version to 3.8.2. No further changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
 * most portable and removes the need for additional structures
63
63
 * (but I have to admit it is somewhat "bulky";)).
64
64
 *
65
 
 * Obviously, all caller-provided pointers must not be NULL...
 
65
 * Obviously, *t must not be NULL...
 
66
 *
 
67
 * rgerhards, 2008-10-07: added ttSeconds to provide a way to 
 
68
 * obtain the second-resolution UNIX timestamp. This is needed
 
69
 * in some situations to minimize time() calls (namely when doing
 
70
 * output processing). This can be left NULL if not needed.
66
71
 */
67
 
static void getCurrTime(struct syslogTime *t)
 
72
static void getCurrTime(struct syslogTime *t, time_t *ttSeconds)
68
73
{
69
74
        struct timeval tp;
70
75
        struct tm *tm;
83
88
#       else
84
89
                gettimeofday(&tp, NULL);
85
90
#       endif
 
91
        if(ttSeconds != NULL)
 
92
                *ttSeconds = tp.tv_sec;
 
93
 
86
94
        tm = localtime_r((time_t*) &(tp.tv_sec), &tmBuf);
87
95
 
88
96
        t->year = tm->tm_year + 1900;
304
312
        /* variables to temporarily hold time information while we parse */
305
313
        int month;
306
314
        int day;
 
315
        int year = 0; /* 0 means no year provided */
307
316
        int hour; /* 24 hour clock */
308
317
        int minute;
309
318
        int second;
464
473
 
465
474
        if(*pszTS++ != ' ')
466
475
                ABORT_FINALIZE(RS_RET_INVLD_TIME);
 
476
 
 
477
        /* time part */
467
478
        hour = srSLMGParseInt32(&pszTS);
 
479
        if(hour > 1970 && hour < 2100) {
 
480
                /* if so, we assume this actually is a year. This is a format found
 
481
                 * e.g. in Cisco devices.
 
482
                 * (if you read this 2100+ trying to fix a bug, congratulate me
 
483
                 * to how long the code survived - me no longer ;)) -- rgerhards, 2008-11-18
 
484
                 */
 
485
                year = hour;
 
486
 
 
487
                /* re-query the hour, this time it must be valid */
 
488
                if(*pszTS++ != ' ')
 
489
                        ABORT_FINALIZE(RS_RET_INVLD_TIME);
 
490
                hour = srSLMGParseInt32(&pszTS);
 
491
        }
 
492
 
468
493
        if(hour < 0 || hour > 23)
469
494
                ABORT_FINALIZE(RS_RET_INVLD_TIME);
470
495
 
494
519
        *ppszTS = pszTS; /* provide updated parse position back to caller */
495
520
        pTime->timeType = 1;
496
521
        pTime->month = month;
 
522
        if(year > 0)
 
523
                pTime->year = year; /* persist year if detected */
497
524
        pTime->day = day;
498
525
        pTime->hour = hour;
499
526
        pTime->minute = minute;