File: submitted-exec_filename.diff

package info (click to toggle)
glibc 2.24-10
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 223,412 kB
  • sloc: ansic: 991,967; asm: 261,800; sh: 10,385; makefile: 9,710; cpp: 4,169; python: 3,971; perl: 2,254; awk: 1,753; pascal: 1,521; yacc: 291; sed: 80
file content (325 lines) | stat: -rw-r--r-- 12,216 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
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  <pochu27@gmail.com>
	* 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 <pochu27@gmail.com>
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.
---
 hurd/Makefile               |    4 +-
 hurd/Versions               |    4 ++
 hurd/hurd.h                 |   14 ++++++++--
 hurd/hurdexec.c             |   50 ++++++++++++++++++++++++++++++-------
 sysdeps/mach/hurd/execve.c  |    6 ++--
 sysdeps/mach/hurd/fexecve.c |    7 ++---
 sysdeps/mach/hurd/spawni.c  |   59 ++++++++++++++++++++++++++------------------
 8 files changed, 102 insertions(+), 43 deletions(-)

--- 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
--- 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
--- a/hurd/hurd.h
+++ b/hurd/hurd.h
@@ -245,12 +245,20 @@ extern FILE *fopenport (io_t port, const
 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
--- a/hurd/hurdexec.c
+++ b/hurd/hurdexec.c
@@ -25,16 +25,37 @@
 #include <hurd/fd.h>
 #include <hurd/signal.h>
 #include <hurd/id.h>
+#include <hurd/fs_experimental.h>
 #include <assert.h>
 #include <argz.h>
 
+#include <shlib-compat.h>
+
 /* 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;
   size_t argslen, envlen;
@@ -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
--- a/sysdeps/mach/hurd/execve.c
+++ b/sysdeps/mach/hurd/execve.c
@@ -31,7 +31,8 @@ __execve (const char *file_name, char *c
     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);
--- 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);
--- a/sysdeps/mach/hurd/spawni.c
+++ b/sysdeps/mach/hurd/spawni.c
@@ -29,6 +29,7 @@
 #include <hurd/id.h>
 #include <hurd/lookup.h>
 #include <hurd/resource.h>
+#include <hurd/fs_experimental.h>
 #include <assert.h>
 #include <argz.h>
 #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,