aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/mach/hurd
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/mach/hurd')
-rw-r--r--sysdeps/mach/hurd/execve.c36
-rw-r--r--sysdeps/mach/hurd/fexecve.c5
-rw-r--r--sysdeps/mach/hurd/spawni.c74
3 files changed, 94 insertions, 21 deletions
diff --git a/sysdeps/mach/hurd/execve.c b/sysdeps/mach/hurd/execve.c
index 04d3bd0d3e..1c5b681d89 100644
--- a/sysdeps/mach/hurd/execve.c
+++ b/sysdeps/mach/hurd/execve.c
@@ -18,6 +18,8 @@
#include <unistd.h>
#include <hurd.h>
#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
/* Replace the current process, executing FILE_NAME with arguments ARGV and
environment ENVP. ARGV and ENVP are terminated by NULL pointers. */
@@ -25,16 +27,46 @@ int
__execve (const char *file_name, char *const argv[], char *const envp[])
{
error_t err;
- file_t file = __file_name_lookup (file_name, O_EXEC, 0);
+ char *concat_name = NULL;
+ const char *abs_path;
+ file_t file = __file_name_lookup (file_name, O_EXEC, 0);
if (file == MACH_PORT_NULL)
return -1;
+ if (file_name[0] == '/')
+ {
+ /* Already an absolute path */
+ abs_path = file_name;
+ }
+ else
+ {
+ /* Relative path */
+ char *cwd = __getcwd (NULL, 0);
+ if (cwd == NULL)
+ {
+ __mach_port_deallocate (__mach_task_self (), file);
+ return -1;
+ }
+
+ int res = __asprintf (&concat_name, "%s/%s", cwd, file_name);
+ free (cwd);
+ if (res == -1)
+ {
+ __mach_port_deallocate (__mach_task_self (), file);
+ return -1;
+ }
+
+ abs_path = concat_name;
+ }
+
/* Hopefully this will not return. */
- err = _hurd_exec (__mach_task_self (), file, argv, envp);
+ err = _hurd_exec_paths (__mach_task_self (), file,
+ file_name, abs_path, argv, envp);
/* Oh well. Might as well be tidy. */
__mach_port_deallocate (__mach_task_self (), file);
+ free (concat_name);
return __hurd_fail (err);
}
diff --git a/sysdeps/mach/hurd/fexecve.c b/sysdeps/mach/hurd/fexecve.c
index a56a51bba1..c5679f197e 100644
--- a/sysdeps/mach/hurd/fexecve.c
+++ b/sysdeps/mach/hurd/fexecve.c
@@ -25,8 +25,9 @@
int
fexecve (int fd, char *const argv[], char *const envp[])
{
- error_t err = HURD_DPORT_USE (fd, _hurd_exec (__mach_task_self (), port,
- argv, envp));
+ error_t err = HURD_DPORT_USE (fd, _hurd_exec_paths (__mach_task_self (),
+ port, NULL, NULL,
+ argv, envp));
if (! err)
err = EGRATUITOUS;
return __hurd_fail (err);
diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/spawni.c
index 24c1e5cfb2..aa3b0c4660 100644
--- a/sysdeps/mach/hurd/spawni.c
+++ b/sysdeps/mach/hurd/spawni.c
@@ -22,6 +22,7 @@
#include <spawn.h>
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include <unistd.h>
#include <hurd.h>
#include <hurd/signal.h>
@@ -44,6 +45,8 @@ __spawni (pid_t *pid, const char *file,
{
pid_t new_pid;
char *path, *p, *name;
+ char *concat_name = NULL, *relpath, *abspath;
+ int res;
size_t len;
size_t pathlen;
short int flags;
@@ -59,14 +62,14 @@ __spawni (pid_t *pid, const char *file,
that remains visible after an exec is registration with the proc
server, and the inheritance of various values and ports. All those
inherited values and ports are what get collected up and passed in the
- file_exec RPC by an exec call. So we do the proc server registration
- here, following the model of fork (see fork.c). We then collect up
- the inherited values and ports from this (parent) process following
- the model of exec (see hurd/hurdexec.c), modify or replace each value
- that fork would (plus the specific changes demanded by ATTRP and
- FILE_ACTIONS), and make the file_exec RPC on the requested executable
- file with the child process's task port rather than our own. This
- should be indistinguishable from the fork + exec implementation,
+ file_exec_paths RPC by an exec call. So we do the proc server
+ registration here, following the model of fork (see fork.c). We then
+ collect up the inherited values and ports from this (parent) process
+ following the model of exec (see hurd/hurdexec.c), modify or replace each
+ value that fork would (plus the specific changes demanded by ATTRP and
+ FILE_ACTIONS), and make the file_exec_paths RPC on the requested
+ executable file with the child process's task port rather than our own.
+ This should be indistinguishable from the fork + exec implementation,
except that all errors will be detected here (in the parent process)
and return proper errno codes rather than the child dying with 127.
@@ -547,7 +550,7 @@ __spawni (pid_t *pid, const char *file,
if ((xflags & SPAWN_XFLAGS_USE_PATH) == 0 || strchr (file, '/') != NULL)
/* The FILE parameter is actually a path. */
- err = child_lookup (file, O_EXEC, 0, &execfile);
+ err = child_lookup (relpath = file, O_EXEC, 0, &execfile);
else
{
/* We have to search for FILE on the path. */
@@ -608,6 +611,7 @@ __spawni (pid_t *pid, const char *file,
}
// We only get here when we are done looking for the file.
+ relpath = startp;
break;
}
while (*p++ != '\0');
@@ -615,6 +619,26 @@ __spawni (pid_t *pid, const char *file,
if (err)
goto out;
+ if (relpath[0] == '/')
+ {
+ /* Already an absolute path */
+ abspath = relpath;
+ }
+ else
+ {
+ /* Relative path */
+ char *cwd = __getcwd (NULL, 0);
+ if (cwd == NULL)
+ goto out;
+
+ res = __asprintf (&concat_name, "%s/%s", cwd, relpath);
+ free (cwd);
+ if (res == -1)
+ goto out;
+
+ abspath = concat_name;
+ }
+
/* Almost there! */
{
mach_port_t ports[_hurd_nports];
@@ -624,14 +648,28 @@ __spawni (pid_t *pid, const char *file,
inline error_t exec (file_t file)
{
- return __file_exec (file, task,
- (__sigismember (&_hurdsig_traced, SIGKILL)
- ? EXEC_SIGTRAP : 0),
- args, argslen, env, envlen,
- dtable, MACH_MSG_TYPE_COPY_SEND, dtablesize,
- ports, MACH_MSG_TYPE_COPY_SEND, _hurd_nports,
- ints, INIT_INT_MAX,
- NULL, 0, NULL, 0);
+ error_t err = __file_exec_paths
+ (file, task,
+ __sigismember (&_hurdsig_traced, SIGKILL) ? EXEC_SIGTRAP : 0,
+ relpath, abspath, args, argslen, env, envlen,
+ dtable, MACH_MSG_TYPE_COPY_SEND, dtablesize,
+ ports, MACH_MSG_TYPE_COPY_SEND, _hurd_nports,
+ ints, INIT_INT_MAX,
+ NULL, 0, NULL, 0);
+
+ /* Fallback for backwards compatibility. This can just be removed
+ when __file_exec goes away. */
+ if (err == MIG_BAD_ID)
+ return __file_exec (file, task,
+ (__sigismember (&_hurdsig_traced, SIGKILL)
+ ? EXEC_SIGTRAP : 0),
+ args, argslen, env, envlen,
+ dtable, MACH_MSG_TYPE_COPY_SEND, dtablesize,
+ ports, MACH_MSG_TYPE_COPY_SEND, _hurd_nports,
+ ints, INIT_INT_MAX,
+ NULL, 0, NULL, 0);
+
+ return err;
}
/* Now we are out of things that can fail before the file_exec RPC,
@@ -750,6 +788,8 @@ __spawni (pid_t *pid, const char *file,
_hurd_port_free (dtable_cells[i], &ulink_dtable[i], dtable[i]);
}
+ free (concat_name);
+
if (err)
/* This hack canonicalizes the error code that we return. */
err = (__hurd_fail (err), errno);