summaryrefslogtreecommitdiff
path: root/sysdeps/mach/hurd/spawni.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/mach/hurd/spawni.c')
-rw-r--r--sysdeps/mach/hurd/spawni.c80
1 files changed, 62 insertions, 18 deletions
diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/spawni.c
index 328a4bb13f..9351c13e56 100644
--- a/sysdeps/mach/hurd/spawni.c
+++ b/sysdeps/mach/hurd/spawni.c
@@ -1,5 +1,5 @@
/* spawn a new process running an executable. Hurd version.
- Copyright (C) 2001-2016 Free Software Foundation, Inc.
+ Copyright (C) 2001-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -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,9 @@ __spawni (pid_t *pid, const char *file,
{
pid_t new_pid;
char *path, *p, *name;
+ char *concat_name = NULL;
+ const char *relpath, *abspath;
+ int res;
size_t len;
size_t pathlen;
short int flags;
@@ -59,14 +63,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.
@@ -281,6 +285,9 @@ __spawni (pid_t *pid, const char *file,
}
#endif
+ if (!err && (flags & POSIX_SPAWN_SETSID) != 0)
+ err = __proc_setsid (proc);
+
/* Set the process group ID. */
if (!err && (flags & POSIX_SPAWN_SETPGROUP) != 0)
err = __proc_setpgrp (proc, new_pid, attrp->__pgrp);
@@ -544,7 +551,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. */
@@ -605,6 +612,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');
@@ -612,6 +620,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];
@@ -621,14 +649,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,
@@ -747,6 +789,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);