Просмотр исходного кода

* Use new simple_exec() instead of system() in some places

Bryan Drewery 16 лет назад
Родитель
Сommit
c218710aa2
3 измененных файлов с 17 добавлено и 24 удалено
  1. 2 8
      src/binary.c
  2. 3 6
      src/conf.c
  3. 12 10
      src/misc.c

+ 2 - 8
src/binary.c

@@ -560,14 +560,8 @@ check_sum(const char *fname, const char *cfgfile, bool read_stdin)
 
 
 bool check_bin_initialized(const char *fname)
 bool check_bin_initialized(const char *fname)
 {
 {
-  int i = 0;
-  size_t len = strlen(shell_escape(fname)) + 3 + 1;
-  char *path = (char *) my_calloc(1, len);
-
-  simple_snprintf(path, len, STR("%s -p"), shell_escape(fname));
-
-  i = system(path);
-  free(path);
+  const char* argv[] = {fname, "-p", 0};
+  int i = simple_exec(argv);
   if (i != -1 && WEXITSTATUS(i) == 4)
   if (i != -1 && WEXITSTATUS(i) == 4)
     return 1;
     return 1;
 
 

+ 3 - 6
src/conf.c

@@ -83,16 +83,13 @@ tellconf()
 
 
 void spawnbot(const char *nick)
 void spawnbot(const char *nick)
 {
 {
-  size_t size = strlen(shell_escape(nick)) + strlen(shell_escape(binname)) + 20;
-  char *run = (char *) my_calloc(1, size);
   int status = 0;
   int status = 0;
 
 
-  simple_snprintf(run, size, "%s %s", shell_escape(binname), shell_escape(nick));
-  sdprintf("Spawning '%s': %s", nick, run);
-  status = system(run);
+  sdprintf("Spawning '%s'", nick);
+  const char* argv[] = {binname, nick, 0};
+  status = simple_exec(argv);
   if (status == -1 || WEXITSTATUS(status))
   if (status == -1 || WEXITSTATUS(status))
     sdprintf("Failed to spawn '%s': %s", nick, strerror(errno));
     sdprintf("Failed to spawn '%s': %s", nick, strerror(errno));
-  free(run);
 }
 }
 
 
 /* spawn and kill bots accordingly
 /* spawn and kill bots accordingly

+ 12 - 10
src/misc.c

@@ -781,8 +781,6 @@ restart(int idx)
 void 
 void 
 hard_restart(int idx)
 hard_restart(int idx)
 {
 {
-  char buf[1024] = "";
-
   write_userfile(idx);
   write_userfile(idx);
   if (!conf.bot->hub) {
   if (!conf.bot->hub) {
     nuke_server((char *) reason);		/* let's drop the server connection ASAP */
     nuke_server((char *) reason);		/* let's drop the server connection ASAP */
@@ -790,9 +788,8 @@ hard_restart(int idx)
   }
   }
   fatal(idx <= 0x7FF0 ? reason : NULL, 1);
   fatal(idx <= 0x7FF0 ? reason : NULL, 1);
   usleep(2000 * 500);
   usleep(2000 * 500);
-  simple_snprintf(buf, sizeof(buf), "%s -B %s\n", shell_escape(binname), shell_escape(conf.bot->nick));
   unlink(conf.bot->pid_file); /* if this fails it is ok, cron will restart the bot, *hopefully* */
   unlink(conf.bot->pid_file); /* if this fails it is ok, cron will restart the bot, *hopefully* */
-  system(buf); /* start new bot. */
+  simple_exec(binname, conf.bot->nick);
   exit(0);
   exit(0);
 }
 }
 #endif
 #endif
@@ -807,6 +804,7 @@ int updatebin(int idx, char *par, int secs)
   size_t path_siz = strlen(binname) + strlen(par) + 2;
   size_t path_siz = strlen(binname) + strlen(par) + 2;
   char *path = (char *) my_calloc(1, path_siz);
   char *path = (char *) my_calloc(1, path_siz);
   char *newbin = NULL, buf[DIRMAX] = "";
   char *newbin = NULL, buf[DIRMAX] = "";
+  const char* argv[5];
 #ifndef CYGWIN_HACKS
 #ifndef CYGWIN_HACKS
   int i;
   int i;
 #endif /* !CYGWIN_HACKS */
 #endif /* !CYGWIN_HACKS */
@@ -876,9 +874,11 @@ int updatebin(int idx, char *par, int secs)
 
 
   /* The binary should return '2' when ran with -2, if not it's probably corrupt. */
   /* The binary should return '2' when ran with -2, if not it's probably corrupt. */
 #ifndef CYGWIN_HACKS
 #ifndef CYGWIN_HACKS
-  simple_snprintf(buf, sizeof(buf), STR("%s -2"), shell_escape(path));
-  putlog(LOG_DEBUG, "*", STR("Running for update binary test: %s"), buf);
-  i = system(buf);
+  putlog(LOG_DEBUG, "*", STR("Running for update binary test: %s -2"), path);
+  argv[0] = path;
+  argv[1] = "-2";
+  argv[2] = 0;
+  i = simple_exec(argv);
   if (i == -1 || WEXITSTATUS(i) != 2) {
   if (i == -1 || WEXITSTATUS(i) != 2) {
     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);
@@ -889,9 +889,11 @@ int updatebin(int idx, char *par, int secs)
 
 
   /* now to send our config to the new binary */
   /* now to send our config to the new binary */
 #ifndef CYGWIN_HACKS
 #ifndef CYGWIN_HACKS
-  simple_snprintf(buf, sizeof(buf), STR("%s -4 %s"), shell_escape(path), conffile->file);
-  putlog(LOG_DEBUG, "*", STR("Running for update conf: %s"), buf);
-  i = system(buf);
+  putlog(LOG_DEBUG, "*", STR("Running for update conf: %s -4 %s"), path, conffile->file);
+  argv[0] = path;
+  argv[1] = "-4";
+  argv[2] = conffile->file;
+  i = simple_exec(argv);
   delete conffile;
   delete conffile;
   if (i == -1 || WEXITSTATUS(i) != 6) { /* 6 for successfull config read/write */
   if (i == -1 || WEXITSTATUS(i) != 6) { /* 6 for successfull config read/write */
     dprintf(idx, STR("Couldn't pass config to new binary (error %d)\n"), i);
     dprintf(idx, STR("Couldn't pass config to new binary (error %d)\n"), i);