Remove extraneous semicolons from end of macro uses.
[srvx.git] / src / log.c
index 22804e84e233433cf30cfe2ed04d1c1360c6d2bc..fe9f74a35848f7ee271ecc8f0be2d55b5b9ee8e8 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -73,7 +73,7 @@ static struct dict *log_types;
 static struct log_type *log_default;
 static int log_inited, log_debugged;
 
-DEFINE_LIST(logList, struct logDestination*);
+DEFINE_LIST(logList, struct logDestination*)
 static void log_format_audit(struct logEntry *entry);
 static const struct message_entry msgtab[] = {
     { "MSG_INVALID_FACILITY", "$b%s$b is an invalid log facility." },
@@ -244,7 +244,7 @@ find_severity(const char *text)
  *   KEY := LOGSET '.' SEVSET
  *   LOGSET := LOGLIT | LOGLIT ',' LOGSET
  *   LOGLIT := a registered log type
- *   SEVSET := '*' | SEVLIT | '=' SEVLIT | '<' SEVLIT | '<=' SEVLIT | '>' SEVLIT | '>=' SEVLIT | SEVLIT ',' SEVSET
+ *   SEVSET := '*' | SEVLIT | '<' SEVLIT | '<=' SEVLIT | '>' SEVLIT | '>=' SEVLIT | SEVLIT ',' SEVSET
  *   SEVLIT := one of log_severity_names
  * A KEY contains the Cartesian product of the logs in its LOGSET
  * and the severities in its SEVSET.
@@ -273,7 +273,8 @@ log_parse_sevset(char *buffer, char targets[LOG_NUM_SEVERITIES])
         int first;
 
         cont = strchr(buffer, ',');
-        if (cont) *cont++ = 0;
+        if (cont)
+            *cont++ = 0;
         if (buffer[0] == '*' && buffer[1] == 0) {
             for (bound = 0; bound < LOG_NUM_SEVERITIES; bound++) {
                 /* make people explicitly specify replay targets */
@@ -526,7 +527,7 @@ log_audit(struct log_type *type, enum log_severity sev, struct userNode *user, s
     /* remove old elements from the linked list */
     while (type->log_count > type->max_count)
         log_type_free_oldest(type);
-    while (type->log_oldest && (type->log_oldest->time + type->max_age < (unsigned long)now))
+    while (type->log_oldest && (type->log_oldest->time + type->max_age < now))
         log_type_free_oldest(type);
     if (type->log_oldest)
         type->log_oldest->prev = 0;
@@ -566,6 +567,8 @@ log_module(struct log_type *type, enum log_severity sev, const char *format, ...
     unsigned int ii;
     va_list args;
 
+    if (!type)
+        return;
     if (sev > LOG_FATAL) {
         log_module(MAIN_LOG, LOG_ERROR, "Illegal log_module severity %d", sev);
         return;
@@ -586,6 +589,10 @@ log_module(struct log_type *type, enum log_severity sev, const char *format, ...
         /* Special behavior before we start full operation */
         fprintf(stderr, "%s: %s\n", log_severity_names[sev], msgbuf);
     }
+    if (sev == LOG_FATAL) {
+        assert(0 && "fatal message logged");
+        _exit(1);
+    }
 }
 
 /* audit log searching */
@@ -599,8 +606,8 @@ log_discrim_create(struct userNode *service, struct userNode *user, unsigned int
     /* Assume all criteria require arguments. */
     if((argc - 1) % 2)
     {
-       send_message(user, service, "MSG_MISSING_PARAMS", argv[0]);
-       return NULL;
+        send_message(user, service, "MSG_MISSING_PARAMS", argv[0]);
+        return NULL;
     }
 
     discrim = malloc(sizeof(struct logSearch));
@@ -643,7 +650,7 @@ log_discrim_create(struct userNode *service, struct userNode *user, unsigned int
                 else
                     discrim->max_time = now - (ParseInterval(cmp+1) - 1);
             } else {
-                discrim->min_time = now - ParseInterval(cmp+2);
+                discrim->min_time = now - ParseInterval(cmp);
             }
         } else if (!irccasecmp(argv[ii], "limit")) {
             discrim->limit = strtoul(argv[++ii], NULL, 10);
@@ -667,10 +674,10 @@ log_discrim_create(struct userNode *service, struct userNode *user, unsigned int
                 send_message(user, service, "MSG_INVALID_FACILITY", argv[ii]);
                 goto fail;
             }
-       } else {
-           send_message(user, service, "MSG_INVALID_CRITERIA", argv[ii]);
-           goto fail;
-       }
+        } else {
+            send_message(user, service, "MSG_INVALID_CRITERIA", argv[ii]);
+            goto fail;
+        }
     }
 
     return discrim;
@@ -700,7 +707,7 @@ entry_match(struct logSearch *discrim, struct logEntry *entry)
             && !match_ircglob(entry->user_hostmask, discrim->masks.user_hostmask))
         || (discrim->masks.command
             && !match_ircglob(entry->command, discrim->masks.command))) {
-       return 0;
+        return 0;
     }
     return 1;
 }
@@ -718,9 +725,13 @@ log_entry_search(struct logSearch *discrim, entry_search_func esf, void *data)
     unsigned int matched = 0;
 
     if (discrim->type) {
+        static volatile struct logEntry *last;
         struct logEntry *entry;
 
-        for (entry = discrim->type->log_oldest; entry; entry = entry->next) {
+        for (entry = discrim->type->log_oldest, last = NULL;
+             entry;
+             last = entry, entry = entry->next) {
+            verify(entry);
             if (entry_match(discrim, entry)) {
                 esf(entry, data);
                 if (++matched >= discrim->limit)
@@ -742,10 +753,12 @@ log_entry_search(struct logSearch *discrim, entry_search_func esf, void *data)
 /* generic helper functions */
 
 static void
-log_format_timestamp(time_t when, struct string_buffer *sbuf)
+log_format_timestamp(unsigned long when, struct string_buffer *sbuf)
 {
     struct tm local;
-    localtime_r(&when, &local);
+    time_t feh;
+    feh = when;
+    localtime_r(&feh, &local);
     if (sbuf->size < 24) {
         sbuf->size = 24;
         free(sbuf->list);