1 This patch implements "magic" lookup for "pid/…", as used when looking up
4 The patch comes from the 't/magic-pid' branch
5 at <https://git.savannah.gnu.org/cgit/hurd/glibc.git>. It squashes
6 commit 392e52286a302ca6157fbd221295e64ab6b6d8ba (by Justus Winter)
7 and commit 392e52286a302ca6157fbd221295e64ab6b6d8ba (a subsequent fix by
10 From: Justus Winter <4winter@informatik.uni-hamburg.de>
11 Subject: [PATCH] hurd: Handle `pid' magical lookup retry
13 * hurd/lookup-retry.c: Handle `pid' magical lookup
16 diff --git a/hurd/lookup-retry.c b/hurd/lookup-retry.c
17 index aee2ba8f93..6ed8de1653 100644
18 --- a/hurd/lookup-retry.c
19 +++ b/hurd/lookup-retry.c
23 #include <eloop-threshold.h>
26 /* Translate the error from dir_lookup into the error the user sees. */
28 @@ -59,6 +60,7 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
32 + file_t lastdir = MACH_PORT_NULL;
34 error_t lookup_op (file_t startdir)
36 @@ -107,14 +109,15 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
39 if (err = reauthenticate (*result))
45 if (nloops++ >= __eloop_threshold ())
47 __mach_port_deallocate (__mach_task_self (), *result);
53 /* An empty RETRYNAME indicates we have the final port. */
54 @@ -174,7 +177,7 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
57 __mach_port_deallocate (__mach_task_self (), *result);
63 @@ -189,7 +192,10 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
64 if (*result != MACH_PORT_NULL)
65 __mach_port_deallocate (__mach_task_self (), *result);
66 if (nloops++ >= __eloop_threshold ())
72 file_name = &retryname[1];
75 @@ -208,7 +214,8 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
76 (*end != '/' && *end != '\0'))
83 if (! get_dtable_port)
85 @@ -226,9 +233,12 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
99 /* Do a normal retry on the remaining components. */
100 @@ -255,9 +265,12 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
101 if (err = __host_info (__mach_host_self (), HOST_BASIC_INFO,
102 (integer_t *) &hostinfo,
106 if (hostinfocnt != HOST_BASIC_INFO_COUNT)
107 - return EGRATUITOUS;
112 p = _itoa (hostinfo.cpu_subtype, &retryname[8], 10, 0);
114 p = _itoa (hostinfo.cpu_type, &retryname[8], 10, 0);
115 @@ -293,10 +306,11 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
119 - return opentty (result);
120 + err = opentty (result);
123 if (err = opentty (&startdir))
126 strcpy (retryname, &retryname[4]);
129 @@ -306,14 +320,48 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
134 + if (retryname[1] == 'i' && retryname[2] == 'd' &&
135 + (retryname[3] == '/' || retryname[3] == 0))
137 + char *p, buf[1024]; /* XXX */
139 + p = _itoa (__getpid (), &buf[sizeof buf], 10, 0);
140 + len = &buf[sizeof buf] - p;
141 + memcpy (buf, p, len);
142 + strcpy (buf + len, &retryname[3]);
143 + strcpy (retryname, buf);
145 + /* Do a normal retry on the remaining components. */
146 + __mach_port_mod_refs (__mach_task_self (), lastdir,
147 + MACH_PORT_RIGHT_SEND, 1);
148 + startdir = lastdir;
149 + file_name = retryname;
157 - return EGRATUITOUS;
164 - return EGRATUITOUS;
169 + if (MACH_PORT_VALID (*result) && *result != lastdir)
171 + if (MACH_PORT_VALID (lastdir))
172 + __mach_port_deallocate (__mach_task_self (), lastdir);
175 + __mach_port_mod_refs (__mach_task_self (), lastdir,
176 + MACH_PORT_RIGHT_SEND, 1);
179 if (startdir != MACH_PORT_NULL)
180 @@ -326,6 +374,10 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
181 err = (*use_init_port) (dirport, &lookup_op);
185 + if (MACH_PORT_VALID (lastdir))
186 + __mach_port_deallocate (__mach_task_self (), lastdir);
190 weak_alias (__hurd_file_name_lookup_retry, hurd_file_name_lookup_retry)