From 42cae82ba866ebc5828a2bcaf590e55161cfa2e3 Mon Sep 17 00:00:00 2001 From: GNU Libc Maintainers Date: Fri, 25 Nov 2016 22:09:39 +0000 Subject: [PATCH] submitted-exec_filename 2.13-33 dates when this was added TODO: _DEBIAN_ in versions however pose problem. Remove the _DEBIAN_ version once packages are rebuilt against 2.21. 2010-08-04 Emilio Pozuelo Monfort * hurd/hurdexec.c (_hurd_exec): Deprecate it. (_hurd_exec_file_name): New function. * hurd/hurd.h (_hurd_exec): Deprecate it. (_hurd_exec_file_name): Declare it. * hurd/Versions: Export it. * sysdeps/mach/hurd/execve.c: Use it. * sysdeps/mach/hurd/fexecve.c: Likewise. * sysdeps/mach/hurd/spawni.c: Likewise. From d1793416cf8bf6fccd42679a8ec30b0058823ab8 Mon Sep 17 00:00:00 2001 From: Emilio Pozuelo Monfort Date: Sat, 22 May 2010 18:26:29 +0200 Subject: [PATCH] Use the new file_exec_file_name RPC Pass the file name of executable to the exec server, which it needs to execute #!-scripts. Currently, the exec server tries to guess the name from argv[0] but argv[0] only contains the executable name by convention. Gbp-Pq: Topic hurd-i386 Gbp-Pq: Name submitted-exec_filename.diff --- hurd/Makefile | 4 +-- hurd/Versions | 8 +++++ hurd/hurd.h | 12 +++++-- hurd/hurdexec.c | 63 +++++++++++++++++++++++++++++++------ sysdeps/mach/hurd/execve.c | 3 +- sysdeps/mach/hurd/fexecve.c | 5 +-- sysdeps/mach/hurd/spawni.c | 57 ++++++++++++++++++++------------- 7 files changed, 114 insertions(+), 38 deletions(-) diff --git a/hurd/Makefile b/hurd/Makefile index 8a38066bf..b79fa1830 100644 --- a/hurd/Makefile +++ b/hurd/Makefile @@ -32,8 +32,8 @@ user-interfaces := $(addprefix hurd/,\ auth auth_request auth_reply startup \ process process_request \ msg msg_reply msg_request \ - exec exec_startup crash interrupt \ - fs fsys io term tioctl socket ifsock \ + exec exec_experimental exec_startup crash interrupt \ + fs fs_experimental fsys io term tioctl socket ifsock \ login password pfinet \ ) server-interfaces := hurd/msg faultexc diff --git a/hurd/Versions b/hurd/Versions index 41ea1aef9..c44e3e041 100644 --- a/hurd/Versions +++ b/hurd/Versions @@ -140,6 +140,14 @@ libc { _hurd_sigstate_unlock; _hurd_sigstate_delete; } + GLIBC_2.13_DEBIAN_33 { + # "quasi-internal" functions + _hurd_exec_file_name; + } + GLIBC_2.21 { + # "quasi-internal" functions + _hurd_exec_file_name; + } HURD_CTHREADS_0.3 { # weak refs to libthreads functions that libc calls iff libthreads in use diff --git a/hurd/hurd.h b/hurd/hurd.h index ec0782797..ac6ad589b 100644 --- a/hurd/hurd.h +++ b/hurd/hurd.h @@ -241,12 +241,20 @@ 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[]); + char *const envp[]) __attribute_deprecated__; + +/* 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 diff --git a/hurd/hurdexec.c b/hurd/hurdexec.c index 79a620874..355a1d973 100644 --- a/hurd/hurdexec.c +++ b/hurd/hurdexec.c @@ -25,15 +25,36 @@ #include #include #include +#include #include #include +#include + /* 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); +} + +link_warning (_hurd_exec, + "_hurd_exec is deprecated, use _hurd_exec_file_name instead"); + +/* 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; @@ -216,7 +237,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; @@ -360,13 +381,27 @@ _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 == MIG_BAD_ID) + 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. */ @@ -401,3 +436,13 @@ _hurd_exec (task_t task, file_t file, free (env); return err; } +versioned_symbol (libc, __hurd_exec_file_name, _hurd_exec_file_name, GLIBC_2_21); +#if SHLIB_COMPAT (libc, GLIBC_2_13, GLIBC_2_21) +error_t +__hurd_exec_file_name_2_13 (task_t task, file_t file, const char *filename, + char *const argv[], char *const envp[]) +{ + return __hurd_exec_file_name (task, file, filename, argv, envp); +} +compat_symbol (libc, __hurd_exec_file_name_2_13, _hurd_exec_file_name, GLIBC_2_13_DEBIAN_33); +#endif diff --git a/sysdeps/mach/hurd/execve.c b/sysdeps/mach/hurd/execve.c index 6904fc645..6c5f0eff1 100644 --- a/sysdeps/mach/hurd/execve.c +++ b/sysdeps/mach/hurd/execve.c @@ -31,7 +31,8 @@ __execve (const char *file_name, char *const argv[], char *const 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 e7b451543..0f8af7b84 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_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 e4d0be152..22e426afc 100644 --- a/sysdeps/mach/hurd/spawni.c +++ b/sysdeps/mach/hurd/spawni.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include "spawn_int.h" @@ -44,6 +45,7 @@ __spawni (pid_t *pid, const char *file, { pid_t new_pid; char *path, *p, *name; + const char *filename; size_t len; size_t pathlen; short int flags; @@ -59,14 +61,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_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_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) and return proper errno codes rather than the child dying with 127. @@ -546,7 +548,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 (filename = file, O_EXEC, 0, &execfile); else { /* We have to search for FILE on the path. */ @@ -573,20 +575,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: @@ -623,14 +623,27 @@ __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 == 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, -- 2.30.2