Browse Source

* Added a signal to handle refreshing binary data

svn: 1879
Bryan Drewery 21 years ago
parent
commit
42ba520486
4 changed files with 28 additions and 4 deletions
  1. 1 0
      doc/UPDATES
  2. 15 4
      src/binary.c
  3. 2 0
      src/binary.h
  4. 10 0
      src/debug.c

+ 1 - 0
doc/UPDATES

@@ -28,6 +28,7 @@ Lines prefixxed with '-' were disabled before release and are not finishsed.
 * Removed channel flag '+|-manop' as it was redundant with chanint 'manop'
 * Removed channel flag '+|-nomop' as it was redundant with chanint 'mop'
 * Upped user limit for processes to 60.
+* After you edit a binary with -C, the first bot will be sent a signal to reload the data from the binary.
 
 1.2.2
 * Don't sanity check flags for users on DCC CHAT if they are on the bot via .botcmd.

+ 15 - 4
src/binary.c

@@ -66,11 +66,11 @@ bin_checksum(const char *fname, int todo)
     while ((len = fread(buf, 1, sizeof buf - 1, f))) {
       if (!memcmp(buf, &settings.prefix, PREFIXLEN))
         break;
-      MD5_Update(ctx, buf, len);
+      MD5_Update(&ctx, buf, len);
     }
 
     fclose(f);
-    MD5_Final(md5out, ctx);
+    MD5_Final(md5out, &ctx);
     strlcpy(hash, btoh(md5out, MD5_DIGEST_LENGTH), sizeof(hash));
     OPENSSL_cleanse(&ctx, sizeof(ctx));
   }
@@ -100,7 +100,7 @@ bin_checksum(const char *fname, int todo)
       newpos += len;
 
       if (!memcmp(buf, &settings.prefix, PREFIXLEN)) {		/* found the settings struct! */
-        MD5_Final(md5out, ctx);
+        MD5_Final(md5out, &ctx);
         strlcpy(hash, btoh(md5out, MD5_DIGEST_LENGTH), sizeof(hash));
         OPENSSL_cleanse(&ctx, sizeof(ctx));
 
@@ -145,7 +145,7 @@ bin_checksum(const char *fname, int todo)
         /* skip reading over the stuff we already wrote */
         fseek(f, newpos, SEEK_SET);
       } else if (!hash[0])		/* hash as long as we haven't reached the prefix */
-        MD5_Update(ctx, buf, len);
+        MD5_Update(&ctx, buf, len);
     }
 
     fclose(f);
@@ -470,3 +470,14 @@ void conf_to_bin(conf_t *in, bool move, int die)
   /* tellconfig(&settings); */
   write_settings(newbin, die, 1);
 }
+
+void reload_bin_data() {
+  if (bin_checksum(binname, GET_CONF)) {
+    free_conf();
+    bin_to_conf();
+    fill_conf_bot();
+    if (!conf.bot->localhub)
+      free_conf_bots();
+  }
+}
+

+ 2 - 0
src/binary.h

@@ -9,8 +9,10 @@ extern int checked_bin_buf;
 #  define WRITE_CHECKSUM 	BIT1
 #  define WRITE_PACK            BIT2
 #  define WRITE_CONF            BIT3
+#  define GET_CONF              BIT4
 
 void check_sum(const char *, const char *);
 void write_settings(const char *, int, bool);
 void conf_to_bin(conf_t *, bool, int);
+void reload_bin_data();
 #endif /* !_BINARY_H */

+ 10 - 0
src/debug.c

@@ -13,6 +13,7 @@
 #include "net.h"
 #include "shell.h"
 #include "color.h"
+#include "binary.h"
 #include "userrec.h"
 #include "main.h"
 #include "dccutil.h"
@@ -283,6 +284,14 @@ got_hup(int z)
   restart(-1);
 }
 
+static void
+got_usr1(int z)
+{
+  putlog(LOG_MISC, "*", "GOT SIGUSR1 -- RECHECKING BINARY");
+  
+  reload_bin_data();
+}
+
 void init_signals() 
 {
   signal(SIGBUS, got_bus);
@@ -295,6 +304,7 @@ void init_signals()
   signal(SIGILL, got_ill);
   signal(SIGALRM, got_alarm);
   signal(SIGHUP, got_hup);
+  signal(SIGUSR1, got_usr1);
 }
 
 #ifdef DEBUG_CONTEXT