Bryan Drewery 16 лет назад
Родитель
Сommit
6aac26514e
3 измененных файлов с 21 добавлено и 9 удалено
  1. 1 1
      src/binary.c
  2. 19 7
      src/shell.c
  3. 1 1
      src/shell.h

+ 1 - 1
src/binary.c

@@ -576,7 +576,7 @@ bool check_bin_compat(const char *fname)
   char *out = NULL;
 
   simple_snprintf(path, len, STR("%s -3"), shell_escape(fname));
-  if (shell_exec(path, NULL, &out, NULL)) {
+  if (shell_exec(path, NULL, &out, NULL, 1)) {
     if (out) {
       char *buf = out;
       size_t settings_ver = atoi(newsplit(&buf)), settings_len = atoi(newsplit(&buf));

+ 19 - 7
src/shell.c

@@ -312,7 +312,7 @@ void check_trace(int start)
 }
 #endif /* !CYGWIN_HACKS */
 
-int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
+int shell_exec(char *cmdline, char *input, char **output, char **erroutput, bool simple)
 {
   if (!cmdline)
     return 0;
@@ -414,11 +414,10 @@ int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
   } else {
     /* Child: make fd's and set them up as std* */
 //    int ind, outd, errd;
-    char *argv[4] = { NULL, NULL, NULL, NULL };
-
 //    ind = fileno(inpFile);
 //    outd = fileno(outFile);
 //    errd = fileno(errFile);
+
     if (dup2(in->fd, STDIN_FILENO) == (-1)) {
       kill(parent, SIGCHLD);
       exit(1);
@@ -431,10 +430,23 @@ int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
       kill(parent, SIGCHLD);
       exit(1);
     }
-    argv[0] = "/bin/sh";
-    argv[1] = "-c";
-    argv[2] = cmdline;
-    argv[3] = NULL;
+
+    char *argv[15];
+    if (simple) {
+      char *p = NULL;
+      int n = 0;
+      char *mycmdline = strdup(cmdline);
+
+      while (mycmdline[0] && (p = newsplit(&mycmdline)))
+        argv[n++] = p;
+      argv[n] = NULL;
+    } else {
+      argv[0] = "/bin/sh";
+      argv[1] = "-c";
+      argv[2] = cmdline;
+      argv[3] = NULL;
+    }
+
     execvp(argv[0], &argv[0]);
     kill(parent, SIGCHLD);
     exit(1);

+ 1 - 1
src/shell.h

@@ -47,7 +47,7 @@ char *homedir(bool = 1);
 char *my_username();
 void expand_tilde(char **);
 int email(char *, char *, int);
-int shell_exec(char *, char *, char **, char **);
+int shell_exec(char *, char *, char **, char **, bool = 0);
 int simple_exec(const char* argv[]);
 #ifndef CYGWIN_HACKS
 void check_last();