fix possible crash on user deletion
[srvx.git] / src / global.c
index d904b082915fa1c778a6ec86ae1774cd8a0333e2..4f263e2dec2fb5688ba5a7df34cb69ddeed7e7ca 100644 (file)
@@ -69,7 +69,7 @@ struct globalMessage
     unsigned long   id;
     long            flags;
 
-    time_t          posted;
+    unsigned long   posted;
     char            posted_s[24];
     unsigned long   duration;
 
@@ -86,7 +86,7 @@ static struct module *global_module;
 static struct service *global_service;
 static struct globalMessage *messageList;
 static long messageCount;
-static time_t last_max_alert;
+static unsigned long last_max_alert;
 static struct log_type *G_LOG;
 
 static struct
@@ -94,15 +94,19 @@ static struct
     unsigned long db_backup_frequency;
 } global_conf;
 
-#define global_notice(target, format...) send_message(target , global , ## format)
+#if defined(GCC_VARMACROS)
+# define global_notice(target, ARGS...) send_message(target, global, ARGS)
+#elif defined(C99_VARMACROS)
+# define global_notice(target, ...) send_message(target, global, __VA_ARGS__)
+#endif
 
 void message_expire(void *data);
 
 static struct globalMessage*
-message_add(long flags, time_t posted, unsigned long duration, char *from, const char *msg)
+message_add(long flags, unsigned long posted, unsigned long duration, char *from, const char *msg)
 {
     struct globalMessage *message;
-    struct tm tm;
+    time_t feh;
 
     message = malloc(sizeof(struct globalMessage));
     if(!message)
@@ -118,9 +122,9 @@ message_add(long flags, time_t posted, unsigned long duration, char *from, const
     message->message = strdup(msg);
 
     if ((flags & MESSAGE_OPTION_IMMEDIATE) == 0) {
-        localtime_r(&message->posted, &tm);
+        feh = message->posted;
         strftime(message->posted_s, sizeof(message->posted_s),
-                 "%I:%M %p, %m/%d/%Y", &tm);
+                 "%I:%M %p, %m/%d/%Y", localtime(&feh));
     }
 
     if(messageList)
@@ -539,11 +543,11 @@ static GLOBAL_FUNC(cmd_messages)
     return 1;
 }
 
-static int
+static void
 global_process_user(struct userNode *user)
 {
     if(IsLocal(user) || self->uplink->burst || user->uplink->burst)
-        return 0;
+        return;
     send_messages(user, MESSAGE_RECIPIENT_LUSERS, 1);
 
     /* only alert on new usercount if the record was broken in the last
@@ -557,8 +561,6 @@ global_process_user(struct userNode *user)
         global_message(MESSAGE_RECIPIENT_OPERS, message);
         last_max_alert = now;
     }
-
-    return 0;
 }
 
 static void
@@ -599,7 +601,7 @@ static int
 global_saxdb_read(struct dict *db)
 {
     struct record_data *hir;
-    time_t posted;
+    unsigned long posted;
     long flags;
     unsigned long duration;
     char *str, *from, *message;