Skip to content
Snippets Groups Projects
Commit 12018284 authored by Raymond Toy's avatar Raymond Toy
Browse files

Fix #45: Handle relative paths in `run-program`

This is basically the solution proposed by Elias Pipping with a few
minor tweaks.

    - In `run-program`, don't merge `program` with the "path:"
      search-list.  `spawn` will handle this.
    - In `spawn`, if the first call to execve fails, instead of trying
      "/bin/sh", use "/usr/bin/env" which will use the user's PATH if
      necessary to find the program.
parent 39dff2ee
No related branches found
No related tags found
No related merge requests found
......@@ -528,10 +528,7 @@
;; info. Also, establish proc at this level so we can return it.
(let (*close-on-error* *close-in-parent* *handlers-installed* proc)
(unwind-protect
(let ((pfile (unix-namestring (merge-pathnames program "path:") t t))
(cookie (list 0)))
(unless pfile
(error (intl:gettext "No such program: ~S") program))
(let ((cookie (list 0)))
(multiple-value-bind
(stdin input-stream)
(get-descriptor-for input cookie :direction :input
......@@ -570,7 +567,7 @@
env))
(let ((child-pid
(without-gcing
(spawn pfile argv envp pty-name
(spawn program argv envp pty-name
stdin stdout stderr))))
(when (< child-pid 0)
(error (intl:gettext "Could not fork child process: ~A")
......
......@@ -65,10 +65,10 @@ spawn(char *program, char *argv[], char *envp[], char *pty_name,
/* Exec the program. */
execve(program, argv, envp);
/* It didn't work, so try /bin/sh. */
/* It didn't work, so try /usr/bin/env. */
argv[0] = program;
argv[-1] = "sh";
execve("/bin/sh", argv - 1, envp);
argv[-1] = "/usr/bin/env";
execve("/usr/bin/env", argv - 1, envp);
/* The exec didn't work, flame out. */
exit(1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment