[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Use the new __hurd_exec_file_name RPC
From: |
Emilio Pozuelo Monfort |
Subject: |
[PATCH] Use the new __hurd_exec_file_name RPC |
Date: |
Sat, 22 May 2010 18:26:29 +0200 |
This fixes problems when an script could end with /dev/fd/N
in argv[0] because the exec server didn't know the file name.
---
hurd/Versions | 1 +
hurd/hurd.h | 12 +++++++++-
hurd/hurdexec.c | 48 ++++++++++++++++++++++++++++++++++---------
sysdeps/mach/hurd/execve.c | 5 ++-
sysdeps/mach/hurd/fexecve.c | 6 ++--
sysdeps/mach/hurd/spawni.c | 48 ++++++++++++++++++++++++++----------------
6 files changed, 85 insertions(+), 35 deletions(-)
diff --git a/hurd/Versions b/hurd/Versions
index 83c8ab1..81cd904 100644
--- a/hurd/Versions
+++ b/hurd/Versions
@@ -73,6 +73,7 @@ libc {
_hurd_critical_section_unlock;
_hurd_exception2signal;
_hurd_exec;
+ _hurd_exec_file_name;
_hurd_fd_get;
_hurd_init;
_hurd_intern_fd;
diff --git a/hurd/hurd.h b/hurd/hurd.h
index 642ea43..a83c3fa 100644
--- a/hurd/hurd.h
+++ b/hurd/hurd.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993,94,95,96,97,98,99,2001,2002,2007
+/* Copyright (C) 1993,94,95,96,97,98,99,2001,2002,2007,2010
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -243,13 +243,21 @@ extern FILE *fopenport (io_t port, const char *mode);
extern FILE *__fopenport (io_t port, const char *mode);
-/* Execute a file, replacing TASK's current program image. */
+/* Deprecated: use _hurd_exec_file_name instead. */
extern error_t _hurd_exec (task_t task,
file_t file,
char *const argv[],
char *const envp[]);
+/* Execute a file, replacing TASK's current program image. */
+
+extern error_t _hurd_exec_file_name (task_t task,
+ file_t file,
+ const char *filename,
+ char *const argv[],
+ char *const envp[]);
+
/* Inform the proc server we have exited with STATUS, and kill the
task thoroughly. This function never returns, no matter what. */
diff --git a/hurd/hurdexec.c b/hurd/hurdexec.c
index beae869..fea2618 100644
--- a/hurd/hurdexec.c
+++ b/hurd/hurdexec.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,92,93,94,95,96,97,99,2001,02
+/* Copyright (C) 1991,92,93,94,95,96,97,99,2001,02,10
Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -32,11 +32,26 @@
/* Overlay TASK, executing FILE with arguments ARGV and environment ENVP.
If TASK == mach_task_self (), some ports are dealloc'd by the exec server.
- ARGV and ENVP are terminated by NULL pointers. */
+ ARGV and ENVP are terminated by NULL pointers.
+ Deprecated: use _hurd_exec_file_name instead. */
error_t
_hurd_exec (task_t task, file_t file,
char *const argv[], char *const envp[])
{
+ return _hurd_exec_file_name (task, file, NULL, argv, envp);
+}
+
+/* Overlay TASK, executing FILE with arguments ARGV and environment ENVP.
+ If TASK == mach_task_self (), some ports are dealloc'd by the exec server.
+ ARGV and ENVP are terminated by NULL pointers. FILENAME is the path
+ (either absolute or relative) to FILE. Passing NULL, though possible,
+ should be avoided, since then the exec server may not know the path to
+ FILE if FILE is a script, and will then pass /dev/fd/N to the
+ interpreter. */
+error_t
+_hurd_exec_file_name (task_t task, file_t file, const char *filename,
+ char *const argv[], char *const envp[])
+{
error_t err;
char *args, *env;
size_t argslen, envlen;
@@ -218,7 +233,7 @@ _hurd_exec (task_t task, file_t file,
/* We have euid != svuid or egid != svgid. POSIX.1 says that exec
sets svuid = euid and svgid = egid. So we must get a new auth
port and reauthenticate everything with it. We'll pass the new
- ports in file_exec instead of our own ports. */
+ ports in file_exec_file_name instead of our own ports. */
auth_t newauth;
@@ -362,13 +377,26 @@ _hurd_exec (task_t task, file_t file,
if (__sigismember (&_hurdsig_traced, SIGKILL))
flags |= EXEC_SIGTRAP;
#endif
- err = __file_exec (file, task, flags,
- args, argslen, env, envlen,
- dtable, MACH_MSG_TYPE_COPY_SEND, dtablesize,
- ports, MACH_MSG_TYPE_COPY_SEND, _hurd_nports,
- ints, INIT_INT_MAX,
- please_dealloc, pdp - please_dealloc,
- &_hurd_msgport, task == __mach_task_self () ? 1 : 0);
+ err = __file_exec_file_name (file, task, flags,
+ filename ? filename : "",
+ args, argslen, env, envlen,
+ dtable, MACH_MSG_TYPE_COPY_SEND, dtablesize,
+ ports, MACH_MSG_TYPE_COPY_SEND, _hurd_nports,
+ ints, INIT_INT_MAX,
+ please_dealloc, pdp - please_dealloc,
+ &_hurd_msgport,
+ task == __mach_task_self () ? 1 : 0);
+ /* Fall back for backwards compatibility. This can just be removed
+ when __file_exec goes away. */
+ if (err)
+ err = __file_exec (file, task, flags,
+ args, argslen, env, envlen,
+ dtable, MACH_MSG_TYPE_COPY_SEND, dtablesize,
+ ports, MACH_MSG_TYPE_COPY_SEND, _hurd_nports,
+ ints, INIT_INT_MAX,
+ please_dealloc, pdp - please_dealloc,
+ &_hurd_msgport,
+ task == __mach_task_self () ? 1 : 0);
}
/* Release references to the standard ports. */
diff --git a/sysdeps/mach/hurd/execve.c b/sysdeps/mach/hurd/execve.c
index 8af8b33..7875c3c 100644
--- a/sysdeps/mach/hurd/execve.c
+++ b/sysdeps/mach/hurd/execve.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 93, 94, 95, 97 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 93, 94, 95, 97, 2010 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
@@ -35,7 +35,8 @@ __execve (file_name, argv, envp)
return -1;
/* Hopefully this will not return. */
- err = _hurd_exec (__mach_task_self (), file, argv, envp);
+ err = _hurd_exec_file_name (__mach_task_self (), file,
+ file_name, argv, envp);
/* Oh well. Might as well be tidy. */
__mach_port_deallocate (__mach_task_self (), file);
diff --git a/sysdeps/mach/hurd/fexecve.c b/sysdeps/mach/hurd/fexecve.c
index d6eb7c0..1be8cb9 100644
--- a/sysdeps/mach/hurd/fexecve.c
+++ b/sysdeps/mach/hurd/fexecve.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1994, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1994, 1997, 2010 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
@@ -26,8 +26,8 @@
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_file_name (__mach_task_self (),
port,
+ 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 244ca2d..06728a1 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,02,04 Free Software Foundation, Inc.
+ Copyright (C) 2001,02,04,10 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
@@ -44,7 +44,7 @@ __spawni (pid_t *pid, const char *file,
int use_path)
{
pid_t new_pid;
- char *path, *p, *name;
+ char *path, *p, *name, *filename;
size_t len;
size_t pathlen;
short int flags;
@@ -60,12 +60,12 @@ __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
+ file_exec_file_name 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_ACTIONS), and make the file_exec_file_name 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)
@@ -545,7 +545,7 @@ __spawni (pid_t *pid, const char *file,
if (! use_path || strchr (file, '/') != NULL)
/* The FILE parameter is actually a path. */
- err = child_lookup (file, O_EXEC, 0, &execfile);
+ err = child_lookup (filename = file, O_EXEC, 0, &execfile);
else
{
/* We have to search for FILE on the path. */
@@ -572,20 +572,18 @@ __spawni (pid_t *pid, const char *file,
p = path;
do
{
- char *startp;
-
path = p;
p = __strchrnul (path, ':');
if (p == path)
/* Two adjacent colons, or a colon at the beginning or the end
of `PATH' means to search the current directory. */
- startp = name + 1;
+ filename = name + 1;
else
- startp = (char *) memcpy (name - (p - path), path, p - path);
+ filename = (char *) memcpy (name - (p - path), path, p - path);
/* Try to open this file name. */
- err = child_lookup (startp, O_EXEC, 0, &execfile);
+ err = child_lookup (filename, O_EXEC, 0, &execfile);
switch (err)
{
case EACCES:
@@ -622,14 +620,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_file_name (file, task,
+ (__sigismember (&_hurdsig_traced,
SIGKILL)
+ ? EXEC_SIGTRAP : 0),
+ filename,
+ 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)
+ 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,
--
1.7.1
- Re: exec server and /dev/fd/N, (continued)
- [PATCH] Use the new __hurd_exec_file_name RPC,
Emilio Pozuelo Monfort <=
- Re: [PATCH] Use the new __hurd_exec_file_name RPC, Carl Fredrik Hammar, 2010/05/31
- Re: [PATCH] Use the new __hurd_exec_file_name RPC, olafBuddenhagen, 2010/05/31
- [PATCH 3/3] Use the new _hurd_exec_file_name function, Emilio Pozuelo Monfort, 2010/05/27
- Re: [PATCH 3/3] Use the new _hurd_exec_file_name function, Carl Fredrik Hammar, 2010/05/31
- [PATCH 2/3] Add a file_exec_file_name RPC, Emilio Pozuelo Monfort, 2010/05/27
- Re: [PATCH 2/3] Add a file_exec_file_name RPC, Carl Fredrik Hammar, 2010/05/31
- Re: exec server and /dev/fd/N, Carl Fredrik Hammar, 2010/05/31
- Re: exec server and /dev/fd/N, Carl Fredrik Hammar, 2010/05/31
Re: exec server and /dev/fd/N, olafBuddenhagen, 2010/05/26