From patchwork Wed Nov 7 11:37:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 30058 Received: (qmail 12080 invoked by alias); 7 Nov 2018 11:37:14 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 12062 invoked by uid 89); 7 Nov 2018 11:37:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] Hurd: Implement chdir support in posix_spawn Date: Wed, 07 Nov 2018 12:37:05 +0100 Message-ID: <87h8gtjezi.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 This fixes build-many-glibcs.py on i686-gnu. Note that I don't really know what I'm doing here, and I don't have a way to check this code. Thanks, Florian 2018-11-07 Florian Weimer * sysdeps/mach/hurd/spawni.c (__spawni): Add nested function child_chdir. Handle spawn_do_chdir. diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/spawni.c index 9351c13e56..b554ccc646 100644 --- a/sysdeps/mach/hurd/spawni.c +++ b/sysdeps/mach/hurd/spawni.c @@ -205,6 +205,38 @@ __spawni (pid_t *pid, const char *file, return __hurd_file_name_lookup (&child_init_port, &child_fd, 0, file, oflag, mode, result); } + auto error_t child_chdir (const char *name) + { + if (rcwdir != MACH_PORT_NULL) + { + __mach_port_deallocate (__mach_task_self (), rcwdir); + rcwdir = MACH_PORT_NULL; + } + + /* See _hurd_change_directory_port_from_name. */ + + /* Append trailing "/." to directory name to force ENOTDIR if + it's not a directory and EACCES if we don't have search + permission. */ + len = strlen (name); + const char *lookup = name; + if (len >= 2 && name[len - 2] == '/' && name[len - 1] == '.') + lookup = name; + else if (len == 0) + /* Special-case empty file name according to POSIX. */ + return __hurd_fail (ENOENT); + else + { + char *n = alloca (len + 3); + memcpy (n, name, len); + n[len] = '/'; + n[len + 1] = '.'; + n[len + 2] = '\0'; + lookup = n; + } + + return child_lookup (lookup, 0, 0, &rcwdir); + } /* Do this once. */ @@ -485,6 +517,10 @@ __spawni (pid_t *pid, const char *file, dtable_cells[fd] = NULL; break; } + + case spawn_do_chdir: + err = child_chdir (action->action.chdir_action.path); + break; } if (err)