From patchwork Sat Dec 1 12:56:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 30507 Received: (qmail 105796 invoked by alias); 1 Dec 2018 12:56:58 -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 105783 invoked by uid 89); 1 Dec 2018 12:56:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy=operate, ven, 5536, UD:orig X-HELO: hera.aquilenet.fr Date: Sat, 1 Dec 2018 13:56:51 +0100 From: Samuel Thibault To: Florian Weimer Cc: libc-alpha@sourceware.org Subject: Re: [PATCH] posix: New function posix_spawn_file_actions_addfchdir_np [BZ #17405] Message-ID: <20181201125651.h7vap4swt7qgadcq@function> References: <874lbyu1c2.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <874lbyu1c2.fsf@oldenburg.str.redhat.com> User-Agent: NeoMutt/20170113 (1.7.2) Hello, Florian Weimer, le ven. 30 nov. 2018 14:44:29 +0100, a ecrit: > This will need porting to Hurd (currently it results in a -Werror > failure); it should be easier than the last time. Indeed, here is the patch to do it, which you can apply alongside. Samuel 2018-12-01 Samuel Thibault * sysdeps/mach/hurd/spawni.c (child_lookup_under, child_fchdir): New functions. (__spawni): Handle spawn_do_fchdir by calling child_fchdir. Index: glibc-upstream/sysdeps/mach/hurd/spawni.c =================================================================== --- glibc-upstream.orig/sysdeps/mach/hurd/spawni.c +++ glibc-upstream/sysdeps/mach/hurd/spawni.c @@ -259,6 +259,46 @@ __spawni (pid_t *pid, const char *file, return err; } + inline error_t child_lookup_under (file_t startdir, const char *file, + int oflag, mode_t mode, file_t *result) + { + error_t use_init_port (int which, error_t (*operate) (mach_port_t)) + { + return (which == INIT_PORT_CWDIR ? (*operate) (startdir) : + child_init_port (which, operate)); + } + + return __hurd_file_name_lookup (&use_init_port, &child_fd, 0, + file, oflag, mode, result); + } + auto error_t child_fchdir (int fd) + { + file_t new_ccwdir; + error_t err; + + if ((unsigned int)fd >= dtablesize + || dtable[fd] == MACH_PORT_NULL) + return EBADF; + + /* We look up "." to force ENOTDIR if it's not a directory and EACCES if + we don't have search permission. */ + if (dtable_cells[fd] != NULL) + err = HURD_PORT_USE (dtable_cells[fd], + ({ + child_lookup_under (port, ".", O_NOTRANS, 0, &new_ccwdir); + })); + else + err = child_lookup_under (dtable[fd], ".", O_NOTRANS, 0, &new_ccwdir); + + if (!err) + { + if (ccwdir != MACH_PORT_NULL) + __mach_port_deallocate (__mach_task_self (), ccwdir); + ccwdir = new_ccwdir; + } + + return err; + } /* Do this once. */ @@ -553,6 +593,10 @@ __spawni (pid_t *pid, const char *file, case spawn_do_chdir: err = child_chdir (action->action.chdir_action.path); break; + + case spawn_do_fchdir: + err = child_fchdir (action->action.fchdir_action.fd); + break; } if (err)