Ignore:
Timestamp:
09/30/13 03:39:55 (11 years ago)
Author:
atzm
Message:

parse syslog datetime

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ksyslog/trunk/ksyslog.c

    r234 r235  
    128128{ 
    129129        struct ksyslog_entry *entry; 
    130         unsigned int facility, severity; 
    131         unsigned char priority, *start; 
     130        unsigned int priority, facility, severity, month, day, hour, minute, second; 
     131        unsigned char *start, month_s[4]; 
     132        struct tm tm; 
    132133        int length, i; 
    133134 
    134         if (sscanf(skb->data, "<%3hhu>", &priority) != 1) 
     135        if (sscanf(skb->data, "<%3u>%3s %2u %2u:%2u:%2u ", 
     136                   &priority, month_s, &day, &hour, &minute, &second) != 6) 
    135137                return ERR_PTR(-EINVAL); 
    136138 
     
    146148                return ERR_PTR(-EINVAL); 
    147149        if (severity >= __KSYSLOG_S_MAX) 
     150                return ERR_PTR(-EINVAL); 
     151 
     152        month = ksyslog_month_num(month_s); 
     153        if (!month) 
     154                return ERR_PTR(-EINVAL); 
     155        if (day > 31) 
     156                return ERR_PTR(-EINVAL); 
     157        if (hour > 23) 
     158                return ERR_PTR(-EINVAL); 
     159        if (minute > 59) 
     160                return ERR_PTR(-EINVAL); 
     161        if (second > 59) 
    148162                return ERR_PTR(-EINVAL); 
    149163 
     
    164178                do_gettimeofday(&entry->tv); 
    165179 
     180        time_to_tm(entry->tv.tv_sec, 0, &tm); 
     181        entry->time = mktime(tm.tm_year + 1900, month, day, hour, minute, second); 
     182 
     183        entry->priority = priority; 
    166184        entry->facility = facility; 
    167185        entry->severity = severity; 
Note: See TracChangeset for help on using the changeset viewer.