2
0
Эх сурвалжийг харах

Term on Linux: fix path of launched command

Arthur Yefimov 3 жил өмнө
parent
commit
d1595466a3
1 өөрчлөгдсөн 15 нэмэгдсэн , 13 устгасан
  1. 15 13
      src/term/term_linux.c

+ 15 - 13
src/term/term_linux.c

@@ -54,24 +54,26 @@ int StartProcessIn(char *process, char *dir) {
       }
       close(q[1]);
       close(p[0]);
-      if (process && process[0] != '/' && dir && dir[0] != '\0') {
-        if (getcwd(cmd, 256) == NULL) {
-          perror("StartProcessIn: Could not getcwd()");
-        }
-        i = 0;
-        while (cmd[i]) i++;
-        if (i && cmd[i - 1] != '/') {
-          cmd[i] = '/';
-          i++;
+      if (dir && dir[0] != '\0') {
+        if (process && process[0] != '/') {
+          if (getcwd(cmd, 256) == NULL) {
+            perror("StartProcessIn: Could not getcwd()");
+          }
+          i = 0;
+          while (cmd[i]) i++;
+          if (i && cmd[i - 1] != '/') {
+            cmd[i] = '/';
+            i++;
+            cmd[i] = '\0';
+          }
+          j = 0;
+          while (process[j]) { cmd[i] = process[j]; i++; j++; }
           cmd[i] = '\0';
+          process = &cmd[0];
         }
-        j = 0;
-        while (process[j]) { cmd[i] = process[j]; i++; j++; }
-        cmd[i] = '\0';
         if (chdir(dir) != 0) {
           perror("StartProcessIn: Could not chdir() in child process");
         }
-        process = &cmd[0];
       }
       if (execl(process, process, (char*)NULL)) {
         perror("StartProcess: Could not execl()");