handle plain-style char** args also
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Thu, 19 Aug 2004 14:09:34 +0000 (14:09 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Thu, 19 Aug 2004 14:09:34 +0000 (14:09 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1665 94cd875c-1c1d-0410-91d2-eb244daf1a30

util-vserver/lib_internal/command-appendparameter.c
util-vserver/lib_internal/command-exec.c
util-vserver/lib_internal/command-free.c
util-vserver/lib_internal/command-init.c

index 26c34c5..13a2ec3 100644 (file)
 #endif
 
 #include "command.h"
+#include "util.h"
 
 void
 Command_appendParameter(struct Command *cmd, char const *param)
 {
-  char const **        p = Vector_pushback(&cmd->params);
-  *p = param;
+  switch (cmd->params_style_) {
+    case parNONE       :
+      Vector_init(&cmd->params.v, 10);
+      cmd->params_style_ = parVEC;
+       /*@fallthrough@*/
+    case parVEC                : {
+      char const **p = Vector_pushback(&cmd->params.v);
+      *p = param;
+      break;
+    }
+
+    default            :
+      WRITE_MSG(2, "internal error: conflicting functions Command_appendParameter() and Command_setParams() used together; aborting...\n");
+      abort();
+  }
 }
index 9f6b17a..d44b1ac 100644 (file)
@@ -21,6 +21,7 @@
 #endif
 
 #include "command.h"
+#include "util.h"
 
 #include <unistd.h>
 #include <fcntl.h>
@@ -39,7 +40,8 @@ Command_exec(struct Command *cmd, bool do_fork)
 {
   int          p[2];
 
-  Vector_zeroEnd(&cmd->params);
+  if (cmd->params_style_==parVEC)
+    Vector_zeroEnd(&cmd->params.v);
 
   if (!do_fork)
     cmd->pid = 0;
@@ -50,10 +52,18 @@ Command_exec(struct Command *cmd, bool do_fork)
   }
   
   if (cmd->pid==0) {
+    char const **      argv = { 0 };
+    
     if (do_fork) close(p[0]);
 
-    execv(cmd->filename ? cmd->filename : ((char **)(Vector_begin(&cmd->params)))[0],
-         cmd->params.data);
+    switch (cmd->params_style_) {
+      case parVEC      :  argv = cmd->params.v.data; break;
+      case parDATA     :  argv = cmd->params.d;      break;
+      default          :  break;
+    }
+
+    execv(cmd->filename ? cmd->filename : argv[0],
+         reinterpret_cast(char **const)(argv));
     cmd->err = errno;
     assert(cmd->err != 0);
 
index 8163503..7075857 100644 (file)
@@ -25,5 +25,6 @@
 void
 Command_free(struct Command *cmd)
 {
-  Vector_free(&cmd->params);
+  if (cmd->params_style_==parVEC)
+    Vector_free(&cmd->params.v);
 }
index 1484766..436d16b 100644 (file)
 #include "command.h"
 
 void
-Command_init(struct Command *cmd, size_t UNUSED param_count)
+Command_init(struct Command *cmd)
 {
-  Vector_init(&cmd->params, sizeof(char *));
-  cmd->filename =  0;
-  cmd->pid      = -1;
-  cmd->rc       = -1;
-  cmd->err      =  0;
+  cmd->filename      =  0;
+  cmd->pid           = -1;
+  cmd->rc            = -1;
+  cmd->err           =  0;
+  cmd->params_style_ =  parNONE;
 }