From nobody Tue Nov 30 02:16:38 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 79BBA18B19D6; Tue, 30 Nov 2021 02:16:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J35SQ4GGbz4Vd3; Tue, 30 Nov 2021 02:16:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 463A559FD; Tue, 30 Nov 2021 02:16:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1AU2Gctf008184; Tue, 30 Nov 2021 02:16:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1AU2Gcwe008183; Tue, 30 Nov 2021 02:16:38 GMT (envelope-from git) Date: Tue, 30 Nov 2021 02:16:38 GMT Message-Id: <202111300216.1AU2Gcwe008183@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 25cda42a4981 - main - posix_spawn: add chdir-related non-portable actions List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 25cda42a498101612687b32005856cd8b14f2f7a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638238598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=aAyGFv8xddZxCxPpXoYP6Xy5FWe8ZA4TlSkXQ1aj6SU=; b=Qq6nWJ0ea2e0rBTo4+K24/FQJnI8HFnpYIBZN4/O22ToFq/KyvRUbVjmTmCi602giCq/ce AgwTCc2HE4oVzL+IltXl+2B6fCWReNjut3uk/4JIJBo45wd03HAO/UGlmiP2rB30ERYBKp HSn3tS/BW/9U3utnMGG0kbLLSqMySTtZV8I6kftmrRXJPHZ+ZEQXPwrkFWvYPZLUtJs3DB cNdUMT0G3qm1Ax6WaKSsPZai+fO85dR34Kb9iclQhxbr/KhK0TorSGFW6wcTZGfOewcKyA E/rMNg/ZnG9pPpbeTtBned82vbN/1XLgkNBDyYkUHqzdxWUWs8nR59ap2/jC8A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638238598; a=rsa-sha256; cv=none; b=B2h6U9BxqI0Q9asRWzgiQJSgKK1KWa+FqJkbNd56StHH4cho2fn3YqEGJbp+Q75QGMNTTz /3XXvfZEiUaQSF/71NB24FkD79Ax5cXe1wJq8hwSNB6pl0gYaJmiEqmKYUKSQudxHlGETi owv/To486EP4nG0WtllWyLX+X80tqvTePtWLo/qUluI5DjKWGXWVe7MfnsQtF1ZTuBr512 75VH5MBndrzMBxuIUQCxdqo2iEV3RLXddEPN6w6mtZ1wXOecTCIZgmob425hXb0Zzzeih5 gJI1/PHtJgKH9eaMaOhRwP5/WfQzJcY+gXReQ3rBpa+xXAT/emgd9iGLEZoL1w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=25cda42a498101612687b32005856cd8b14f2f7a commit 25cda42a498101612687b32005856cd8b14f2f7a Author: Konstantin Belousov AuthorDate: 2021-11-27 22:49:03 +0000 Commit: Konstantin Belousov CommitDate: 2021-11-30 01:43:54 +0000 posix_spawn: add chdir-related non-portable actions Namely posix_spawn_file_actions_addchdir_np and posix_spawn_file_actions_addfchdir_np. Reviewed by: kevans, ngie (previous version) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D33143 --- include/spawn.h | 7 ++++++ lib/libc/gen/Symbol.map | 2 ++ lib/libc/gen/posix_spawn.c | 57 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/include/spawn.h b/include/spawn.h index 79753bba0510..4ba3998a3e90 100644 --- a/include/spawn.h +++ b/include/spawn.h @@ -87,6 +87,13 @@ int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t * __restrict, int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int, int); int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *, int); +#if __BSD_VISIBLE +int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t * + __restrict, const char * __restrict); +int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *, + int); +#endif + /* * Spawn attributes */ diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map index b6c3c252be7c..bae2463d99d4 100644 --- a/lib/libc/gen/Symbol.map +++ b/lib/libc/gen/Symbol.map @@ -436,6 +436,8 @@ FBSD_1.6 { }; FBSD_1.7 { + posix_spawn_file_actions_addchdir_np; + posix_spawn_file_actions_addfchdir_np; sched_getaffinity; sched_setaffinity; sched_getcpu; diff --git a/lib/libc/gen/posix_spawn.c b/lib/libc/gen/posix_spawn.c index 03283cfcfb04..00d1724a6515 100644 --- a/lib/libc/gen/posix_spawn.c +++ b/lib/libc/gen/posix_spawn.c @@ -66,6 +66,8 @@ typedef struct __posix_spawn_file_actions_entry { FAE_OPEN, FAE_DUP2, FAE_CLOSE, + FAE_CHDIR, + FAE_FCHDIR, } fae_action; int fae_fildes; @@ -180,6 +182,14 @@ process_file_actions_entry(posix_spawn_file_actions_entry_t *fae) /* Perform a close(), do not fail if already closed */ (void)_close(fae->fae_fildes); break; + case FAE_CHDIR: + if (chdir(fae->fae_path) != 0) + return (errno); + break; + case FAE_FCHDIR: + if (fchdir(fae->fae_fildes) != 0) + return (errno); + break; } return (0); } @@ -393,7 +403,8 @@ posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *fa) STAILQ_REMOVE_HEAD(&(*fa)->fa_list, fae_list); /* Deallocate file action entry */ - if (fae->fae_action == FAE_OPEN) + if (fae->fae_action == FAE_OPEN || + fae->fae_action == FAE_CHDIR) free(fae->fae_path); free(fae); } @@ -478,6 +489,50 @@ posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *fa, return (0); } +int +posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t * + __restrict fa, const char *__restrict path) +{ + posix_spawn_file_actions_entry_t *fae; + int error; + + fae = malloc(sizeof(posix_spawn_file_actions_entry_t)); + if (fae == NULL) + return (errno); + + fae->fae_action = FAE_CHDIR; + fae->fae_path = strdup(path); + if (fae->fae_path == NULL) { + error = errno; + free(fae); + return (error); + } + + STAILQ_INSERT_TAIL(&(*fa)->fa_list, fae, fae_list); + return (0); +} + +int +posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *__restrict fa, + int fildes) +{ + posix_spawn_file_actions_entry_t *fae; + + if (fildes < 0) + return (EBADF); + + /* Allocate object */ + fae = malloc(sizeof(posix_spawn_file_actions_entry_t)); + if (fae == NULL) + return (errno); + + fae->fae_action = FAE_FCHDIR; + fae->fae_fildes = fildes; + + STAILQ_INSERT_TAIL(&(*fa)->fa_list, fae, fae_list); + return (0); +} + /* * Spawn attributes */