Selaa lähdekoodia

* Fixed a bug in conf.c [Wasn't copying homedir in fillconf()]
* Added idxlog()
* Code cleanups


svn: 743

Bryan Drewery 22 vuotta sitten
vanhempi
commit
36df3c66aa
5 muutettua tiedostoa jossa 31 lisäystä ja 27 poistoa
  1. 1 0
      src/conf.c
  2. 15 0
      src/log.c
  3. 1 0
      src/log.h
  4. 13 23
      src/misc.c
  5. 1 4
      src/mod/update.mod/update.c

+ 1 - 0
src/conf.c

@@ -670,6 +670,7 @@ void fillconf(conf_t *inconf) {
   inconf->binname = 		conffile.binname ? strdup(conffile.binname) : NULL;
   inconf->binname = 		conffile.binname ? strdup(conffile.binname) : NULL;
   inconf->uname = 		conffile.uname ? strdup(conffile.uname) : NULL;
   inconf->uname = 		conffile.uname ? strdup(conffile.uname) : NULL;
   inconf->username = 		conffile.username ? strdup(conffile.username) : NULL;
   inconf->username = 		conffile.username ? strdup(conffile.username) : NULL;
+  inconf->homedir = 		conffile.homedir ? strdup(conffile.homedir) : NULL;
   inconf->autocron = 		conffile.autocron;
   inconf->autocron = 		conffile.autocron;
   inconf->autouname = 		conffile.autouname;
   inconf->autouname = 		conffile.autouname;
   inconf->portmin = 		conffile.portmin;
   inconf->portmin = 		conffile.portmin;

+ 15 - 0
src/log.c

@@ -121,6 +121,21 @@ char *maskname(int x)
  *    Logging functions
  *    Logging functions
  */
  */
 
 
+inline void logidx(int idx, char *format, ...)
+{
+  char va_out[LOGLINEMAX + 1];
+  va_list va;
+
+  va_start(va, format);
+  egg_vsnprintf(va_out, LOGLINEMAX, format, va);
+  va_end(va);
+
+  if (idx < 0)
+    putlog(LOG_DEBUG, "*", "%s", va_out);
+  else
+    dprintf(idx, "%s\n", va_out);
+}
+
 /* Log something
 /* Log something
  * putlog(level,channel_name,format,...);
  * putlog(level,channel_name,format,...);
  * Broadcast the log if chname is not '@'
  * Broadcast the log if chname is not '@'

+ 1 - 0
src/log.h

@@ -37,6 +37,7 @@
 
 
 
 
 #ifndef MAKING_MODS
 #ifndef MAKING_MODS
+inline void logidx(int, char *, ...);
 void putlog (int, char *, char *, ...);
 void putlog (int, char *, char *, ...);
 int logmodes(char *);
 int logmodes(char *);
 char *masktype(int);
 char *masktype(int);

+ 13 - 23
src/misc.c

@@ -705,9 +705,9 @@ int ucnt = 0;
 void updatelocal(void)
 void updatelocal(void)
 {
 {
 #ifdef LEAF
 #ifdef LEAF
-  module_entry *me;
+  module_entry *me = NULL;
 #endif /* LEAF */
 #endif /* LEAF */
-  Context;
+
   if (ucnt < 300) {
   if (ucnt < 300) {
     ucnt++;
     ucnt++;
     return;
     return;
@@ -739,15 +739,11 @@ int updatebin(int idx, char *par, int autoi)
   char buf[DIRMAX] = "", old[DIRMAX] = "", testbuf[DIRMAX] = "";
   char buf[DIRMAX] = "", old[DIRMAX] = "", testbuf[DIRMAX] = "";
   struct stat sb;
   struct stat sb;
   int i;
   int i;
-#ifdef LEAF
-  module_entry *me = NULL;
-#endif /* LEAF */
 
 
   path = newsplit(&par);
   path = newsplit(&par);
   par = path;
   par = path;
   if (!par[0]) {
   if (!par[0]) {
-    if (idx)
-      dprintf(idx, STR("Not enough parameters.\n"));
+    logidx(idx, STR("Not enough parameters."));
     return 1;
     return 1;
   }
   }
   path = calloc(1, strlen(binname) + strlen(par) + 2);
   path = calloc(1, strlen(binname) + strlen(par) + 2);
@@ -755,34 +751,29 @@ int updatebin(int idx, char *par, int autoi)
   newbin = strrchr(path, '/');
   newbin = strrchr(path, '/');
   if (!newbin) {
   if (!newbin) {
     free(path);
     free(path);
-    if (idx)
-      dprintf(idx, STR("Don't know current binary name\n"));
+    logidx(idx, STR("Don't know current binary name"));
     return 1;
     return 1;
   }
   }
   newbin++;
   newbin++;
   if (strchr(par, '/')) {
   if (strchr(par, '/')) {
     *newbin = 0;
     *newbin = 0;
-    if (idx)
-      dprintf(idx, STR("New binary must be in %s and name must be specified without path information\n"), path);
+    logidx(idx, STR("New binary must be in %s and name must be specified without path information"), path);
     free(path);
     free(path);
     return 1;
     return 1;
   }
   }
   strcpy(newbin, par);
   strcpy(newbin, par);
   if (!strcmp(path, binname)) {
   if (!strcmp(path, binname)) {
     free(path);
     free(path);
-    if (idx)
-      dprintf(idx, STR("Can't update with the current binary\n"));
+    logidx(idx, STR("Can't update with the current binary"));
     return 1;
     return 1;
   }
   }
   if (stat(path, &sb)) {
   if (stat(path, &sb)) {
-    if (idx)
-      dprintf(idx, STR("%s can't be accessed\n"), path);
+    logidx(idx, STR("%s can't be accessed"), path);
     free(path);
     free(path);
     return 1;
     return 1;
   }
   }
   if (chmod(path, S_IRUSR | S_IWUSR | S_IXUSR)) {
   if (chmod(path, S_IRUSR | S_IWUSR | S_IXUSR)) {
-    if (idx)
-      dprintf(idx, STR("Can't set mode 0600 on %s\n"), path);
+    logidx(idx, STR("Can't set mode 0600 on %s"), path);
     free(path);
     free(path);
     return 1;
     return 1;
   }
   }
@@ -796,15 +787,13 @@ int updatebin(int idx, char *par, int autoi)
   egg_snprintf(testbuf, sizeof testbuf, "%s -2", path);
   egg_snprintf(testbuf, sizeof testbuf, "%s -2", path);
   i = system(testbuf);
   i = system(testbuf);
   if (i == -1 || WEXITSTATUS(i) != 2) {
   if (i == -1 || WEXITSTATUS(i) != 2) {
-    if (idx)
-      dprintf(idx, STR("Couldn't restart new binary (error %d)\n"), i);
+    dprintf(idx, STR("Couldn't restart new binary (error %d)\n"), i);
     putlog(LOG_MISC, "*", STR("Couldn't restart new binary (error %d)"), i);
     putlog(LOG_MISC, "*", STR("Couldn't restart new binary (error %d)"), i);
     return i;
     return i;
   }
   }
 
 
   if (movefile(path, binname)) {
   if (movefile(path, binname)) {
-    if (idx)
-      dprintf(idx, STR("Can't rename %s to %s\n"), path, binname);
+    logidx(idx, STR("Can't rename %s to %s"), path, binname);
     free(path);
     free(path);
     return 1;
     return 1;
   }
   }
@@ -820,14 +809,15 @@ int updatebin(int idx, char *par, int autoi)
   putlog(LOG_DEBUG, "*", "Running for update: %s", buf);
   putlog(LOG_DEBUG, "*", "Running for update: %s", buf);
 #ifdef LEAF
 #ifdef LEAF
   if (!autoi && localhub) {
   if (!autoi && localhub) {
+    module_entry *me = NULL;
+
     /* let's drop the server connection ASAP */
     /* let's drop the server connection ASAP */
     if ((me = module_find("server", 0, 0))) {
     if ((me = module_find("server", 0, 0))) {
       Function *func = me->funcs;
       Function *func = me->funcs;
       (func[SERVER_NUKESERVER]) ("Updating...");
       (func[SERVER_NUKESERVER]) ("Updating...");
     }
     }
 #endif /* LEAF */
 #endif /* LEAF */
-    if (idx)
-      dprintf(idx, STR("Updating...bye\n"));
+    logidx(idx, STR("Updating...bye"));
     putlog(LOG_MISC, "*", STR("Updating..."));
     putlog(LOG_MISC, "*", STR("Updating..."));
     botnet_send_chat(-1, conf.bot->nick, "Updating...");
     botnet_send_chat(-1, conf.bot->nick, "Updating...");
     botnet_send_bye();
     botnet_send_bye();

+ 1 - 4
src/mod/update.mod/update.c

@@ -265,11 +265,8 @@ void finish_update(int idx)
   sprintf(buf, "%s%s", conf.homedir,  strrchr(dcc[idx].u.xfer->filename, '/'));
   sprintf(buf, "%s%s", conf.homedir,  strrchr(dcc[idx].u.xfer->filename, '/'));
 
 
   movefile(dcc[idx].u.xfer->filename, buf); 
   movefile(dcc[idx].u.xfer->filename, buf); 
-  
   chmod(buf, S_IRUSR | S_IWUSR | S_IXUSR);
   chmod(buf, S_IRUSR | S_IWUSR | S_IXUSR);
 
 
-  
-
   sprintf(buf, "%s", strrchr(buf, '/'));
   sprintf(buf, "%s", strrchr(buf, '/'));
   buf2 = buf;
   buf2 = buf;
   buf2++;
   buf2++;
@@ -431,7 +428,7 @@ static void check_updates()
       }
       }
     }
     }
     /* send out notice to update remote bots ... */
     /* send out notice to update remote bots ... */
-    sprintf(buf, "nu? %lu", buildts);
+    egg_snprintf(buf, sizeof buf, "nu? %lu", buildts);
     putallbots(buf);
     putallbots(buf);
   }
   }
 }
 }