From patchwork Wed Sep 1 17:39:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 44829 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 07550385AC25 for ; Wed, 1 Sep 2021 17:40:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07550385AC25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1630518021; bh=Gd9KRYFmk6f1Ns7zbW3FPqjjpu/CsBFIOSU5/8BOIL0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=p+3k8A2WKTGZ7WqCUnTUfu7nOVoK/EGBYRBL2WQYlhOLz1FmllP7pTLwzqiCfCocU Vy0Yl3FT6LXAygoPDq4p5GEd/AkQXtc9QhfIJhKR5cd2frzwjZzchXtvvFr3OIiPGj xEAz1jm3lR7lf+2rSRBctnZrj/6ONX1sN6iFHFK0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id 56611385743C for ; Wed, 1 Sep 2021 17:39:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 56611385743C Received: by mail-qk1-x729.google.com with SMTP id f22so261573qkm.5 for ; Wed, 01 Sep 2021 10:39:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Gd9KRYFmk6f1Ns7zbW3FPqjjpu/CsBFIOSU5/8BOIL0=; b=EOiKslL4JIkSDAuUx/kVF86TMinCYMzTRNqoYcIMGAlZYC8qiucEv3Lu19h5adOvTt oDkHJrDNRCILxG5rPpv73GBhzFneXUmdqHYko5rnWNYvIF92V1MATyE4fWn7vuMjtCp2 lMhlwrXzTwowhxcAhfu3ZdvZd5bXK69jZ3tBJPUuwX37Yr23d8u4+vN6ck1LzxVRW+cR iZhBGibxwiTHeW+TnXZtl0QJEAgfNFpZceXQ/KFWjOyoKgBEBeF8HCKQvWbM07LIeKbN Wx97RTXaXl5pon/hV/rtAfX26BlwIpvTziBnLJLGenm19RMl7M+7ENqgwjoTDevZbWsR 5Fqw== X-Gm-Message-State: AOAM530NcEzO9UJXHeh3gqkz96Ia/BoJtiByfWFN8KMXpFHSo0UYm4LT V9ziB3ADqNzmguAXYYQ2wALomfXDsfrm9A== X-Google-Smtp-Source: ABdhPJy36vswmui2UCtgg8zALgO7DTF3TMvIbZaslynuG1C13uslzm0amHBx7J9B1n6WtkFe5ruzTg== X-Received: by 2002:a05:620a:8cb:: with SMTP id z11mr814780qkz.328.1630517989585; Wed, 01 Sep 2021 10:39:49 -0700 (PDT) Received: from birita.. ([2804:18:8b5:79f6:6068:def9:ee5b:1e9]) by smtp.gmail.com with ESMTPSA id t194sm125847qka.72.2021.09.01.10.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 10:39:49 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v4 1/2] posix: Remove spawni.c Date: Wed, 1 Sep 2021 14:39:37 -0300 Message-Id: <20210901173938.1048607-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Godmar Back Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Although it provide an alternate implementation that communicates using pipe() instead of shared memory, no port uses and it adds extra burden for posix_spawn() extensions. Reviewed-by: Florian Weimer --- sysdeps/posix/spawni.c | 343 ----------------------------------------- 1 file changed, 343 deletions(-) delete mode 100644 sysdeps/posix/spawni.c diff --git a/sysdeps/posix/spawni.c b/sysdeps/posix/spawni.c deleted file mode 100644 index ad1858fe4e..0000000000 --- a/sysdeps/posix/spawni.c +++ /dev/null @@ -1,343 +0,0 @@ -/* Guts of POSIX spawn interface. Generic POSIX.1 version. - Copyright (C) 2000-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "spawn_int.h" - - -/* The Unix standard contains a long explanation of the way to signal - an error after the fork() was successful. Since no new wait status - was wanted there is no way to signal an error using one of the - available methods. The committee chose to signal an error by a - normal program exit with the exit code 127. */ -#define SPAWN_ERROR 127 - -struct posix_spawn_args -{ - sigset_t oldmask; - const char *file; - int (*exec) (const char *, char *const *, char *const *); - const posix_spawn_file_actions_t *fa; - const posix_spawnattr_t *restrict attr; - char *const *argv; - ptrdiff_t argc; - char *const *envp; - int xflags; - int pipe[2]; -}; - -/* Older version requires that shell script without shebang definition - to be called explicitly using /bin/sh (_PATH_BSHELL). */ -static void -maybe_script_execute (struct posix_spawn_args *args) -{ - if (SHLIB_COMPAT (libc, GLIBC_2_2, GLIBC_2_15) - && (args->xflags & SPAWN_XFLAGS_TRY_SHELL) && errno == ENOEXEC) - { - char *const *argv = args->argv; - ptrdiff_t argc = args->argc; - - /* Construct an argument list for the shell. */ - char *new_argv[argc + 2]; - new_argv[0] = (char *) _PATH_BSHELL; - new_argv[1] = (char *) args->file; - if (argc > 1) - memcpy (new_argv + 2, argv + 1, argc * sizeof (char *)); - else - new_argv[2] = NULL; - - /* Execute the shell. */ - args->exec (new_argv[0], new_argv, args->envp); - } -} - -/* Function used in the clone call to setup the signals mask, posix_spawn - attributes, and file actions. */ -static int -__spawni_child (void *arguments) -{ - struct posix_spawn_args *args = arguments; - const posix_spawnattr_t *restrict attr = args->attr; - const posix_spawn_file_actions_t *file_actions = args->fa; - int ret; - - __close (args->pipe[0]); - - /* Set signal default action. */ - if ((attr->__flags & POSIX_SPAWN_SETSIGDEF) != 0) - { - /* We have to iterate over all signals. This could possibly be - done better but it requires system specific solutions since - the sigset_t data type can be very different on different - architectures. */ - int sig; - struct sigaction sa; - - memset (&sa, '\0', sizeof (sa)); - sa.sa_handler = SIG_DFL; - - for (sig = 1; sig <= _NSIG; ++sig) - if (__sigismember (&attr->__sd, sig) != 0 - && __sigaction (sig, &sa, NULL) != 0) - goto fail; - } - -#ifdef _POSIX_PRIORITY_SCHEDULING - /* Set the scheduling algorithm and parameters. */ - if ((attr->__flags & (POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER)) - == POSIX_SPAWN_SETSCHEDPARAM) - { - if (__sched_setparam (0, &attr->__sp) == -1) - goto fail; - } - else if ((attr->__flags & POSIX_SPAWN_SETSCHEDULER) != 0) - { - if (__sched_setscheduler (0, attr->__policy, &attr->__sp) == -1) - goto fail; - } -#endif - - /* Set the process session ID. */ - if ((attr->__flags & POSIX_SPAWN_SETSID) != 0 - && __setsid () < 0) - goto fail; - - /* Set the process group ID. */ - if ((attr->__flags & POSIX_SPAWN_SETPGROUP) != 0 - && __setpgid (0, attr->__pgrp) != 0) - goto fail; - - /* Set the effective user and group IDs. */ - if ((attr->__flags & POSIX_SPAWN_RESETIDS) != 0 - && (local_seteuid (__getuid ()) != 0 - || local_setegid (__getgid ())) != 0) - goto fail; - - /* Execute the file actions. */ - if (file_actions != NULL) - { - int cnt; - struct rlimit64 fdlimit; - bool have_fdlimit = false; - - for (cnt = 0; cnt < file_actions->__used; ++cnt) - { - struct __spawn_action *action = &file_actions->__actions[cnt]; - - switch (action->tag) - { - case spawn_do_close: - if (__close_nocancel (action->action.close_action.fd) != 0) - { - if (have_fdlimit == 0) - { - __getrlimit64 (RLIMIT_NOFILE, &fdlimit); - have_fdlimit = true; - } - - /* Only signal errors for file descriptors out of range. */ - if (action->action.close_action.fd < 0 - || action->action.close_action.fd >= fdlimit.rlim_cur) - goto fail; - } - break; - - case spawn_do_open: - { - /* POSIX states that if fildes was already an open file descriptor, - it shall be closed before the new file is opened. This avoid - pontential issues when posix_spawn plus addopen action is called - with the process already at maximum number of file descriptor - opened and also for multiple actions on single-open special - paths (like /dev/watchdog). */ - __close_nocancel (action->action.open_action.fd); - - int new_fd = __open_nocancel (action->action.open_action.path, - action->action.open_action.oflag - | O_LARGEFILE, - action->action.open_action.mode); - - if (new_fd == -1) - goto fail; - - /* Make sure the desired file descriptor is used. */ - if (new_fd != action->action.open_action.fd) - { - if (__dup2 (new_fd, action->action.open_action.fd) - != action->action.open_action.fd) - goto fail; - - if (__close_nocancel (new_fd) != 0) - goto fail; - } - } - break; - - case spawn_do_dup2: - /* Austin Group issue #411 requires adddup2 action with source - and destination being equal to remove close-on-exec flag. */ - if (action->action.dup2_action.fd - == action->action.dup2_action.newfd) - { - int fd = action->action.dup2_action.newfd; - int flags = __fcntl (fd, F_GETFD, 0); - if (flags == -1) - goto fail; - if (__fcntl (fd, F_SETFD, flags & ~FD_CLOEXEC) == -1) - goto fail; - } - else if (__dup2 (action->action.dup2_action.fd, - action->action.dup2_action.newfd) - != action->action.dup2_action.newfd) - goto fail; - break; - - case spawn_do_chdir: - if (__chdir (action->action.chdir_action.path) != 0) - goto fail; - break; - - case spawn_do_fchdir: - if (__fchdir (action->action.fchdir_action.fd) != 0) - goto fail; - break; - - case spawn_do_closefrom: - __set_errno (EINVAL); - goto fail; - } - } - } - - /* Set the initial signal mask of the child if POSIX_SPAWN_SETSIGMASK - is set, otherwise restore the previous one. */ - __sigprocmask (SIG_SETMASK, (attr->__flags & POSIX_SPAWN_SETSIGMASK) - ? &attr->__ss : &args->oldmask, 0); - - args->exec (args->file, args->argv, args->envp); - - /* This is compatibility function required to enable posix_spawn run - script without shebang definition for older posix_spawn versions - (2.15). */ - maybe_script_execute (args); - -fail: - /* errno should have an appropriate non-zero value; otherwise, - there's a bug in glibc or the kernel. For lack of an error code - (EINTERNALBUG) describing that, use ECHILD. Another option would - be to set args->err to some negative sentinel and have the parent - abort(), but that seems needlessly harsh. */ - ret = errno ? : ECHILD; - if (ret) - /* Since sizeof errno < PIPE_BUF, the write is atomic. */ - while (__write_nocancel (args->pipe[1], &ret, sizeof (ret)) < 0); - - _exit (SPAWN_ERROR); -} - -/* Spawn a new process executing PATH with the attributes describes in *ATTRP. - Before running the process perform the actions described in FILE-ACTIONS. */ -int -__spawnix (pid_t *pid, const char *file, - const posix_spawn_file_actions_t *file_actions, - const posix_spawnattr_t *attrp, char *const argv[], - char *const envp[], int xflags, - int (*exec) (const char *, char *const *, char *const *)) -{ - struct posix_spawn_args args; - int ec; - - if (__pipe2 (args.pipe, O_CLOEXEC)) - return errno; - - /* Disable asynchronous cancellation. */ - int state; - __libc_ptf_call (__pthread_setcancelstate, - (PTHREAD_CANCEL_DISABLE, &state), 0); - - ptrdiff_t argc = 0; - ptrdiff_t limit = INT_MAX - 1; - while (argv[argc++] != NULL) - if (argc == limit) - { - errno = E2BIG; - return errno; - } - - args.file = file; - args.exec = exec; - args.fa = file_actions; - args.attr = attrp ? attrp : &(const posix_spawnattr_t) { 0 }; - args.argv = argv; - args.argc = argc; - args.envp = envp; - args.xflags = xflags; - - /* Generate the new process. */ - pid_t new_pid = __fork (); - - if (new_pid == 0) - __spawni_child (&args); - else if (new_pid > 0) - { - __close (args.pipe[1]); - - if (__read (args.pipe[0], &ec, sizeof ec) != sizeof ec) - ec = 0; - else - __waitpid (new_pid, &(int) { 0 }, 0); - } - else - ec = errno; - - __close (args.pipe[0]); - - if ((ec == 0) && (pid != NULL)) - *pid = new_pid; - - __libc_ptf_call (__pthread_setcancelstate, (state, NULL), 0); - - return ec; -} - -int -__spawni (pid_t * pid, const char *file, - const posix_spawn_file_actions_t * acts, - const posix_spawnattr_t * attrp, char *const argv[], - char *const envp[], int xflags) -{ - /* It uses __execvpex to avoid run ENOEXEC in non compatibility mode (it - will be handled by maybe_script_execute). */ - return __spawnix (pid, file, acts, attrp, argv, envp, xflags, - xflags & SPAWN_XFLAGS_USE_PATH ? __execvpex : __execve); -} From patchwork Wed Sep 1 17:39:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 44830 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 132DC385AC3A for ; Wed, 1 Sep 2021 17:41:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 132DC385AC3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1630518069; bh=dXyteJjqqonflbWYYvWYguxFQ5JtsGVQBqxFApoMO3Y=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=tLqny2H3htJ7JLqk957IoEaXVpd605d3DhNw0jjLscyxmEpTw82lbv6qYkH8d4ZaF wp5FgoaYnCUGmFblApAa6Cj1bcuqTH/fw1vpHmfeyqfyCdIujWzP6qya8+7mEbvyjI f6XF9Ylqw7CUF9YQpaKyeZcL4TxoD5dYDbgOEvFs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by sourceware.org (Postfix) with ESMTPS id 8BEE83857036 for ; Wed, 1 Sep 2021 17:39:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8BEE83857036 Received: by mail-qk1-x734.google.com with SMTP id a66so282112qkc.1 for ; Wed, 01 Sep 2021 10:39:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dXyteJjqqonflbWYYvWYguxFQ5JtsGVQBqxFApoMO3Y=; b=DrSFlu99AqFgHiqbIwxR6l8l9IwBWA0zWjR1J3jGWmvJ66kO7JAXfDcwx4vcxaBrc/ QLYMeMEQksfdV6vno07gb2HFlH41/mJMijSj6cMEyucPekJnsNSwbJKz3jVekKNO6c/T RXYOamCx0tQmsNZEQzUp2keRZZTUMeFgYPI9Ite6PN9baQClgkKa7vx6PmxX9/BAzp4J KRGeWGbpSh1rJ4K7bzORR6uMQU245W0lzwYHk1/GtmCTxzdk02DJjBNqZC9ii2Iz16zK 5FeTEuiupvJkEW/eg/EASlVd6AI0qLtCCyTavt/H9n2JJbJmuFU6fjFHLfP10d30fCv4 76uA== X-Gm-Message-State: AOAM532XDTMkviVogAuoaRrNaShcSD+toayb6ajHrUYE4+d6oNPL3N+J qw2HUgrPOme8eG2H8b4MtGkN0QUkJzg0Pw== X-Google-Smtp-Source: ABdhPJxEvh3P8W5RMyWAgQyqShU9DCCEf5+CVK9QpWqKfzTo6/Ju35rnAFFGzBkem1rOE0GRsFzmAg== X-Received: by 2002:a05:620a:4042:: with SMTP id i2mr790421qko.336.1630517991461; Wed, 01 Sep 2021 10:39:51 -0700 (PDT) Received: from birita.. ([2804:18:8b5:79f6:6068:def9:ee5b:1e9]) by smtp.gmail.com with ESMTPSA id t194sm125847qka.72.2021.09.01.10.39.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 10:39:51 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v4 2/2] posix: Add terminal control setting support for posix_spawn Date: Wed, 1 Sep 2021 14:39:38 -0300 Message-Id: <20210901173938.1048607-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210901173938.1048607-1-adhemerval.zanella@linaro.org> References: <20210901173938.1048607-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Godmar Back Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Currently there is no proper way to set the controlling terminal through posix_spawn() in race free manner [1]. This forces shell implementations to keep using fork()+exec() when launching background process groups, even when using posix_spawn() yields better performance. This patch adds a new GNU extension so the creating process can configure the created process terminal group. This is done with a new flag, POSIX_SPAWN_TCSETPGROUP, along with two new attribute functions: posix_spawnattr_tcsetpgrp_np(), and posix_spawnattr_tcgetpgrp_np(). The function sets a new attribute, spawn-tcgroupfd, that references to the controlling terminal. The controlling terminal is set after the spawn-pgroup attribute, and uses the spawn-tcgroupfd along with current creating process group (so it is composable with POSIX_SPAWN_SETPGROUP). To create a process and set the controlling terminal, one can use the following sequence: posix_spawnattr_t attr; posix_spawnattr_init (&attr); posix_spawnattr_setflags (&attr, POSIX_SPAWN_TCSETPGROUP); posix_spawnattr_tcsetpgrp_np (&attr, tcfd); If the idea is also to create a new process groups: posix_spawnattr_t attr; posix_spawnattr_init (&attr); posix_spawnattr_setflags (&attr, POSIX_SPAWN_TCSETPGROUP | POSIX_SPAWN_SETPGROUP); posix_spawnattr_tcsetpgrp_np (&attr, tcfd); posix_spawnattr_setpgroup (&attr, 0); The controlling terminal file descriptor is ignored if the new flag is not set. This interface is slight different than the one provided by QNX [2], which only provides the POSIX_SPAWN_TCSETPGROUP flag. The QNX documentation does not specify how the controlling terminal is obtained nor how it iteracts with POSIX_SPAWN_SETPGROUP. Since a glibc implementation is library based, it is more straightforward and avoid requires additional file descriptor operations to request the caller to setup the controlling terminal file descriptor (and it also allows a bit less error handling by posix_spawn()). Checked on x86_64-linux-gnu and i686-linux-gnu. [1] https://github.com/ksh93/ksh/issues/79 [2] https://www.qnx.com/developers/docs/7.0.0/index.html#com.qnx.doc.neutrino.lib_ref/topic/p/posix_spawn.html --- NEWS | 5 +- include/unistd.h | 4 + posix/Makefile | 2 + posix/Versions | 4 + posix/spawn.h | 16 +- posix/spawnattr_setflags.c | 3 +- posix/spawnattr_tcgetpgrp.c | 26 +++ posix/spawnattr_tcsetpgrp.c | 26 +++ posix/tst-spawn6.c | 174 ++++++++++++++++++ sysdeps/mach/hurd/i386/libc.abilist | 2 + sysdeps/mach/hurd/spawni.c | 13 ++ sysdeps/unix/bsd/tcsetpgrp.c | 4 +- sysdeps/unix/sysv/linux/aarch64/libc.abilist | 2 + sysdeps/unix/sysv/linux/alpha/libc.abilist | 2 + sysdeps/unix/sysv/linux/arc/libc.abilist | 2 + sysdeps/unix/sysv/linux/arm/be/libc.abilist | 2 + sysdeps/unix/sysv/linux/arm/le/libc.abilist | 2 + sysdeps/unix/sysv/linux/csky/libc.abilist | 2 + sysdeps/unix/sysv/linux/hppa/libc.abilist | 2 + sysdeps/unix/sysv/linux/i386/libc.abilist | 2 + sysdeps/unix/sysv/linux/ia64/libc.abilist | 2 + .../sysv/linux/m68k/coldfire/libc.abilist | 2 + .../unix/sysv/linux/m68k/m680x0/libc.abilist | 2 + .../sysv/linux/microblaze/be/libc.abilist | 2 + .../sysv/linux/microblaze/le/libc.abilist | 2 + .../sysv/linux/mips/mips32/fpu/libc.abilist | 2 + .../sysv/linux/mips/mips32/nofpu/libc.abilist | 2 + .../sysv/linux/mips/mips64/n32/libc.abilist | 2 + .../sysv/linux/mips/mips64/n64/libc.abilist | 2 + sysdeps/unix/sysv/linux/nios2/libc.abilist | 2 + .../linux/powerpc/powerpc32/fpu/libc.abilist | 2 + .../powerpc/powerpc32/nofpu/libc.abilist | 2 + .../linux/powerpc/powerpc64/be/libc.abilist | 2 + .../linux/powerpc/powerpc64/le/libc.abilist | 2 + .../unix/sysv/linux/riscv/rv32/libc.abilist | 2 + .../unix/sysv/linux/riscv/rv64/libc.abilist | 2 + .../unix/sysv/linux/s390/s390-32/libc.abilist | 2 + .../unix/sysv/linux/s390/s390-64/libc.abilist | 2 + sysdeps/unix/sysv/linux/sh/be/libc.abilist | 2 + sysdeps/unix/sysv/linux/sh/le/libc.abilist | 2 + .../sysv/linux/sparc/sparc32/libc.abilist | 2 + .../sysv/linux/sparc/sparc64/libc.abilist | 2 + sysdeps/unix/sysv/linux/spawni.c | 11 ++ sysdeps/unix/sysv/linux/syscalls.list | 2 +- .../unix/sysv/linux/x86_64/64/libc.abilist | 2 + .../unix/sysv/linux/x86_64/x32/libc.abilist | 2 + termios/tcsetpgrp.c | 5 +- 47 files changed, 354 insertions(+), 7 deletions(-) create mode 100644 posix/spawnattr_tcgetpgrp.c create mode 100644 posix/spawnattr_tcsetpgrp.c create mode 100644 posix/tst-spawn6.c diff --git a/NEWS b/NEWS index 79c895e382..90c506ed51 100644 --- a/NEWS +++ b/NEWS @@ -9,7 +9,10 @@ Version 2.35 Major new features: - [Add new features here] +* The functions posix_spawnattr_tcsetpgrp_np and posix_spawnattr_tcgetpgrp_np + have been added, enabling posix_spawn and posix_spawnp to set the + controlling terminal in the new process in a non race manner. These + functions are GNU extensions. Deprecated and removed features, and other changes affecting compatibility: diff --git a/include/unistd.h b/include/unistd.h index 7849562c42..d7eaea3eef 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -173,6 +173,10 @@ extern int __truncate (const char *path, __off_t __length); extern void *__sbrk (intptr_t __delta); libc_hidden_proto (__sbrk) +extern int __tcsetpgrp (int fd, __pid_t pgrp); +libc_hidden_proto (__tcsetpgrp) +extern pid_t __getpgrp (void); +libc_hidden_proto (__getpgrp); /* This variable is set nonzero at startup if the process's effective IDs differ from its real IDs, or it is otherwise indicated that diff --git a/posix/Makefile b/posix/Makefile index 059efb3cd2..bbcbae22a7 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -64,6 +64,7 @@ routines := \ spawnattr_getpgroup spawnattr_setpgroup spawn spawnp spawni \ spawnattr_getsigmask spawnattr_getschedpolicy spawnattr_getschedparam \ spawnattr_setsigmask spawnattr_setschedpolicy spawnattr_setschedparam \ + spawnattr_tcgetpgrp spawnattr_tcsetpgrp \ posix_madvise \ get_child_max sched_cpucount sched_cpualloc sched_cpufree \ streams-compat \ @@ -276,6 +277,7 @@ tst-exec-ARGS = -- $(host-test-program-cmd) tst-exec-static-ARGS = $(tst-exec-ARGS) tst-execvpe5-ARGS = -- $(host-test-program-cmd) tst-spawn-ARGS = -- $(host-test-program-cmd) +tst-spawn5-ARGS = -- $(host-test-program-cmd) tst-spawn-static-ARGS = $(tst-spawn-ARGS) tst-spawn5-ARGS = -- $(host-test-program-cmd) tst-dir-ARGS = `pwd` `cd $(common-objdir)/$(subdir); pwd` `cd $(common-objdir); pwd` $(objpfx)tst-dir diff --git a/posix/Versions b/posix/Versions index a78792135f..e4f4f649b0 100644 --- a/posix/Versions +++ b/posix/Versions @@ -156,6 +156,10 @@ libc { execveat; posix_spawn_file_actions_addclosefrom_np; } + GLIBC_2.35 { + posix_spawnattr_tcgetpgrp_np; + posix_spawnattr_tcsetpgrp_np; + } GLIBC_PRIVATE { __libc_fork; __libc_pread; __libc_pwrite; __nanosleep_nocancel; __pause_nocancel; diff --git a/posix/spawn.h b/posix/spawn.h index 990d8a6ba2..742d4cb625 100644 --- a/posix/spawn.h +++ b/posix/spawn.h @@ -34,7 +34,8 @@ typedef struct sigset_t __ss; struct sched_param __sp; int __policy; - int __pad[16]; + int __ctty_fd; + int __pad[15]; } posix_spawnattr_t; @@ -59,6 +60,7 @@ typedef struct #ifdef __USE_GNU # define POSIX_SPAWN_USEVFORK 0x40 # define POSIX_SPAWN_SETSID 0x80 +# define POSIX_SPAWN_TCSETPGROUP 0x100 #endif @@ -166,6 +168,18 @@ extern int posix_spawnattr_setschedparam (posix_spawnattr_t *__restrict __attr, __restrict __schedparam) __THROW __nonnull ((1, 2)); +#ifdef __USE_GNU +/* Make the spawned process the foreground process group on the terminal + associated with FD (which must be a controlling terminal, and still be + associated with its session). */ +extern int posix_spawnattr_tcsetpgrp_np (posix_spawnattr_t *__attr, int fd) + __THROW __nonnull ((1)); + +/* Return the associated terminal FD in the attribute structure. */ +extern int posix_spawnattr_tcgetpgrp_np (const posix_spawnattr_t * + __restrict __attr, int *fd) + __THROW __nonnull ((1, 2)); +#endif /* Initialize data structure for file attribute for `spawn' call. */ extern int posix_spawn_file_actions_init (posix_spawn_file_actions_t * diff --git a/posix/spawnattr_setflags.c b/posix/spawnattr_setflags.c index 2b033a50fc..95f521d04d 100644 --- a/posix/spawnattr_setflags.c +++ b/posix/spawnattr_setflags.c @@ -26,7 +26,8 @@ | POSIX_SPAWN_SETSCHEDPARAM \ | POSIX_SPAWN_SETSCHEDULER \ | POSIX_SPAWN_SETSID \ - | POSIX_SPAWN_USEVFORK) + | POSIX_SPAWN_USEVFORK \ + | POSIX_SPAWN_TCSETPGROUP) /* Store flags in the attribute structure. */ int diff --git a/posix/spawnattr_tcgetpgrp.c b/posix/spawnattr_tcgetpgrp.c new file mode 100644 index 0000000000..6d5dcd438b --- /dev/null +++ b/posix/spawnattr_tcgetpgrp.c @@ -0,0 +1,26 @@ +/* Get the controlling terminal option. + Copyright (C) 2000-2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +int +posix_spawnattr_tcgetpgrp_np (const posix_spawnattr_t *attr, int *fd) +{ + *fd = attr->__ctty_fd; + return 0; +} diff --git a/posix/spawnattr_tcsetpgrp.c b/posix/spawnattr_tcsetpgrp.c new file mode 100644 index 0000000000..b1b5d5dba0 --- /dev/null +++ b/posix/spawnattr_tcsetpgrp.c @@ -0,0 +1,26 @@ +/* Set the controlling terminal option. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +int +posix_spawnattr_tcsetpgrp_np (posix_spawnattr_t *attr, int fd) +{ + attr->__ctty_fd = fd; + return 0; +} diff --git a/posix/tst-spawn6.c b/posix/tst-spawn6.c new file mode 100644 index 0000000000..67a1096a26 --- /dev/null +++ b/posix/tst-spawn6.c @@ -0,0 +1,174 @@ +/* Check posix_spawn set controlling terminal extension. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int +handle_restart (const char *argv1) +{ + bool setpgrp = strcmp (argv1, "setgrpr") == 0; + int fd = xopen (_PATH_TTY, O_RDONLY, 0600); + + /* If process group is not changed (POSIX_SPAWN_SETPGROUP), then check + the creating process one, otherwise check against the process group + itself. */ + pid_t pgrp; + if (!setpgrp) + TEST_COMPARE (sscanf (argv1, "%d", &pgrp), 1); + else + { + pgrp = getpgrp (); + /* Check if a new process group was actually created. */ + pid_t ppid = getppid (); + pid_t pgid = getpgid (ppid); + TEST_VERIFY (pgid != pgrp); + } + + TEST_COMPARE (tcgetpgrp (fd), pgrp); + + xclose (fd); + return 0; +} + +static int restart; +#define CMDLINE_OPTIONS \ + { "restart", no_argument, &restart, 1 }, + +static void +run_subprogram (int argc, char *argv[], const posix_spawnattr_t *attr, + int exp_err) +{ + short int flags; + TEST_COMPARE (posix_spawnattr_getflags (attr, &flags), 0); + bool setpgrp = flags & POSIX_SPAWN_SETPGROUP; + + char *spargv[9]; + char pgrp[INT_STRLEN_BOUND (pid_t)]; + + int i = 0; + for (; i < argc - 1; i++) + spargv[i] = argv[i + 1]; + spargv[i++] = (char *) "--direct"; + spargv[i++] = (char *) "--restart"; + if (setpgrp) + spargv[i++] = (char *) "setgrpr"; + else + { + snprintf (pgrp, sizeof pgrp, "%d", getpgrp ()); + spargv[i++] = pgrp; + } + spargv[i] = NULL; + + pid_t pid; + TEST_COMPARE (posix_spawn (&pid, argv[1], NULL, attr, spargv, environ), + exp_err); + if (exp_err != 0) + return; + + int status; + TEST_COMPARE (xwaitpid (pid, &status, WUNTRACED), pid); + TEST_VERIFY (WIFEXITED (status)); + TEST_VERIFY (!WIFSTOPPED (status)); + TEST_VERIFY (!WIFSIGNALED (status)); + TEST_COMPARE (WEXITSTATUS (status), 0); +} + +static int +do_test (int argc, char *argv[]) +{ + /* We must have either: + - One our fource parameters left if called initially: + + path to ld.so optional + + "--library-path" optional + + the library path optional + + the application name + - six parameters left if called through re-execution: + + --setgrpr optional + */ + + if (restart) + return handle_restart (argv[1]); + + int tcfd = xopen (_PATH_TTY, O_RDONLY, 0600); + + /* Check getters and setters. */ + { + posix_spawnattr_t attr; + TEST_COMPARE (posix_spawnattr_init (&attr), 0); + TEST_COMPARE (posix_spawnattr_tcsetpgrp_np (&attr, tcfd), 0); + + int fd; + TEST_COMPARE (posix_spawnattr_tcgetpgrp_np (&attr, &fd), 0); + TEST_COMPARE (tcfd, fd); + } + + /* Check setting the controlling terminal without changing the group. */ + { + posix_spawnattr_t attr; + TEST_COMPARE (posix_spawnattr_init (&attr), 0); + TEST_COMPARE (posix_spawnattr_setflags (&attr, POSIX_SPAWN_TCSETPGROUP), + 0); + TEST_COMPARE (posix_spawnattr_tcsetpgrp_np (&attr, tcfd), 0); + + run_subprogram (argc, argv, &attr, 0); + } + + /* Check setting both the controlling terminal and the create a new process + group. */ + { + posix_spawnattr_t attr; + TEST_COMPARE (posix_spawnattr_init (&attr), 0); + TEST_COMPARE (posix_spawnattr_setflags (&attr, POSIX_SPAWN_TCSETPGROUP + | POSIX_SPAWN_SETPGROUP), + 0); + TEST_COMPARE (posix_spawnattr_setpgroup (&attr, 0), 0); + TEST_COMPARE (posix_spawnattr_tcsetpgrp_np (&attr, tcfd), 0); + + run_subprogram (argc, argv, &attr, 0); + } + + /* Trying to set the controlling terminal after a setsid() incurs in a ENOTTY + from tcsetpgrp. */ + { + posix_spawnattr_t attr; + TEST_COMPARE (posix_spawnattr_init (&attr), 0); + TEST_COMPARE (posix_spawnattr_setflags (&attr, POSIX_SPAWN_TCSETPGROUP + | POSIX_SPAWN_SETSID), 0); + TEST_COMPARE (posix_spawnattr_tcsetpgrp_np (&attr, tcfd), 0); + + run_subprogram (argc, argv, &attr, ENOTTY); + } + + xclose (tcfd); + + return 0; +} + +#define TEST_FUNCTION_ARGV do_test +#include diff --git a/sysdeps/mach/hurd/i386/libc.abilist b/sysdeps/mach/hurd/i386/libc.abilist index c5da10a0cd..9db40e5dcc 100644 --- a/sysdeps/mach/hurd/i386/libc.abilist +++ b/sysdeps/mach/hurd/i386/libc.abilist @@ -2285,6 +2285,8 @@ GLIBC_2.34 res_send F GLIBC_2.34 shm_open F GLIBC_2.34 shm_unlink F GLIBC_2.34 timespec_getres F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/spawni.c index 060e389bbb..4d71181643 100644 --- a/sysdeps/mach/hurd/spawni.c +++ b/sysdeps/mach/hurd/spawni.c @@ -390,6 +390,19 @@ retry: if (!err && (flags & POSIX_SPAWN_SETPGROUP) != 0) err = __proc_setpgrp (proc, new_pid, attrp->__pgrp); + /* Set the controlling terminal. */ + if (!err && (flags & POSIX_SPAWN_TCSETPGROUP) != 0) + { + pid_t pgrp; + /* Check if it is possible to avoid an extra syscall. */ + if ((attrp->__flags & POSIX_SPAWN_SETPGROUP) != 0 && attrp->__pgrp != 0) + pgrp = attrp->__pgrp; + else + err = __proc_getpgrp (proc, new_pid, &pgrp); + if (!err) + err = __tcsetpgrp (attrp->__ctty_fd, pgrp); + } + /* Set the effective user and group IDs. */ if (!err && (flags & POSIX_SPAWN_RESETIDS) != 0) { diff --git a/sysdeps/unix/bsd/tcsetpgrp.c b/sysdeps/unix/bsd/tcsetpgrp.c index 98c88db3ae..3930b4f674 100644 --- a/sysdeps/unix/bsd/tcsetpgrp.c +++ b/sysdeps/unix/bsd/tcsetpgrp.c @@ -22,7 +22,9 @@ /* Set the foreground process group ID of FD set PGRP_ID. */ int -tcsetpgrp (int fd, pid_t pgrp_id) +__tcsetpgrp (int fd, pid_t pgrp_id) { return __ioctl (fd, TIOCSPGRP, &pgrp_id); } +weak_alias (__tcsetpgrp, tcsetpgrp) +libc_hidden_def (__tcsetpgrp) diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist index 21a2e50a88..618afab10e 100644 --- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist +++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist @@ -2612,3 +2612,5 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist index a201fd69ba..71c8723354 100644 --- a/sysdeps/unix/sysv/linux/alpha/libc.abilist +++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist @@ -2709,6 +2709,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 _IO_fprintf F GLIBC_2.4 _IO_printf F GLIBC_2.4 _IO_sprintf F diff --git a/sysdeps/unix/sysv/linux/arc/libc.abilist b/sysdeps/unix/sysv/linux/arc/libc.abilist index 2611436937..e5914da07a 100644 --- a/sysdeps/unix/sysv/linux/arc/libc.abilist +++ b/sysdeps/unix/sysv/linux/arc/libc.abilist @@ -2373,3 +2373,5 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F diff --git a/sysdeps/unix/sysv/linux/arm/be/libc.abilist b/sysdeps/unix/sysv/linux/arm/be/libc.abilist index a426241965..eb99b9daa5 100644 --- a/sysdeps/unix/sysv/linux/arm/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/be/libc.abilist @@ -491,6 +491,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 _Exit F GLIBC_2.4 _IO_2_1_stderr_ D 0xa0 GLIBC_2.4 _IO_2_1_stdin_ D 0xa0 diff --git a/sysdeps/unix/sysv/linux/arm/le/libc.abilist b/sysdeps/unix/sysv/linux/arm/le/libc.abilist index 02f80418cc..5d271973ad 100644 --- a/sysdeps/unix/sysv/linux/arm/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/le/libc.abilist @@ -488,6 +488,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 _Exit F GLIBC_2.4 _IO_2_1_stderr_ D 0xa0 GLIBC_2.4 _IO_2_1_stdin_ D 0xa0 diff --git a/sysdeps/unix/sysv/linux/csky/libc.abilist b/sysdeps/unix/sysv/linux/csky/libc.abilist index b7676eb372..4cfe377afb 100644 --- a/sysdeps/unix/sysv/linux/csky/libc.abilist +++ b/sysdeps/unix/sysv/linux/csky/libc.abilist @@ -2647,3 +2647,5 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist index f6965c9d95..f81a953a2f 100644 --- a/sysdeps/unix/sysv/linux/hppa/libc.abilist +++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist @@ -2596,6 +2596,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist index 2e7603d9ed..523656c240 100644 --- a/sysdeps/unix/sysv/linux/i386/libc.abilist +++ b/sysdeps/unix/sysv/linux/i386/libc.abilist @@ -2780,6 +2780,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/ia64/libc.abilist b/sysdeps/unix/sysv/linux/ia64/libc.abilist index dd3a56d3fe..5c8a61f3e0 100644 --- a/sysdeps/unix/sysv/linux/ia64/libc.abilist +++ b/sysdeps/unix/sysv/linux/ia64/libc.abilist @@ -2547,6 +2547,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist index c1e0ea9c10..16ea270119 100644 --- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist +++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist @@ -492,6 +492,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 _Exit F GLIBC_2.4 _IO_2_1_stderr_ D 0x98 GLIBC_2.4 _IO_2_1_stdin_ D 0x98 diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist index 93161048ca..47579d5f0a 100644 --- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist +++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist @@ -2723,6 +2723,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist index 0aaeec8a27..51d0575b7a 100644 --- a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist @@ -2696,3 +2696,5 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F diff --git a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist index bec5f456c9..2c78533f94 100644 --- a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist @@ -2693,3 +2693,5 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist index 97d2127f78..83352f77fe 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist @@ -2688,6 +2688,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist index acb0756c11..f94e2a3b96 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist @@ -2686,6 +2686,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist index ebc21dde1e..c4b949c476 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist @@ -2694,6 +2694,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist index c68f7e3c6c..027dd91a11 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist @@ -2598,6 +2598,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist index e5b6834f14..c7d4a091b3 100644 --- a/sysdeps/unix/sysv/linux/nios2/libc.abilist +++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist @@ -2735,3 +2735,5 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist index 132707c8ad..b79513af92 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist @@ -2750,6 +2750,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 _IO_fprintf F GLIBC_2.4 _IO_printf F GLIBC_2.4 _IO_sprintf F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist index 0af2be31a0..389203bef3 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist @@ -2783,6 +2783,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 _IO_fprintf F GLIBC_2.4 _IO_printf F GLIBC_2.4 _IO_sprintf F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist index cf864632d0..cf1a602c38 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist @@ -2506,6 +2506,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 _IO_fprintf F GLIBC_2.4 _IO_printf F GLIBC_2.4 _IO_sprintf F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist index d566d675d0..30d0e6f443 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist @@ -2808,3 +2808,5 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F diff --git a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist index c9a7eacb32..5305f972b6 100644 --- a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist +++ b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist @@ -2375,3 +2375,5 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist index 8299131cb2..d14578af93 100644 --- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist +++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist @@ -2575,3 +2575,5 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist index c3fe78f77f..cbb9b7a21e 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist +++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist @@ -2748,6 +2748,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 _IO_fprintf F GLIBC_2.4 _IO_printf F GLIBC_2.4 _IO_sprintf F diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist index 83e542aa8c..f79b4c9b08 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist +++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist @@ -2543,6 +2543,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 _IO_fprintf F GLIBC_2.4 _IO_printf F GLIBC_2.4 _IO_sprintf F diff --git a/sysdeps/unix/sysv/linux/sh/be/libc.abilist b/sysdeps/unix/sysv/linux/sh/be/libc.abilist index dc502f6833..418283101b 100644 --- a/sysdeps/unix/sysv/linux/sh/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/sh/be/libc.abilist @@ -2603,6 +2603,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/sh/le/libc.abilist b/sysdeps/unix/sysv/linux/sh/le/libc.abilist index cba1abb556..0aeb958a11 100644 --- a/sysdeps/unix/sysv/linux/sh/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/sh/le/libc.abilist @@ -2600,6 +2600,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist index d4a516fb47..9d311932b4 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist @@ -2743,6 +2743,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 _IO_fprintf F GLIBC_2.4 _IO_printf F GLIBC_2.4 _IO_sprintf F diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist index 6268875ba3..a84761b855 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist @@ -2570,6 +2570,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/spawni.c b/sysdeps/unix/sysv/linux/spawni.c index 6b0bade4d4..601850638d 100644 --- a/sysdeps/unix/sysv/linux/spawni.c +++ b/sysdeps/unix/sysv/linux/spawni.c @@ -164,6 +164,17 @@ __spawni_child (void *arguments) && __setpgid (0, attr->__pgrp) != 0) goto fail; + /* Set the controlling terminal. */ + if ((attr->__flags & POSIX_SPAWN_TCSETPGROUP) != 0) + { + /* Check if it is possible to avoid an extra syscall. */ + pid_t pgrp = (attr->__flags & POSIX_SPAWN_SETPGROUP) != 0 + && attr->__pgrp != 0 + ? attr->__pgrp : __getpgid (0); + if (__tcsetpgrp (attr->__ctty_fd, pgrp) != 0) + goto fail; + } + /* Set the effective user and group IDs. */ if ((attr->__flags & POSIX_SPAWN_RESETIDS) != 0 && (local_seteuid (__getuid ()) != 0 diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list index 29899eb264..c89c18e764 100644 --- a/sysdeps/unix/sysv/linux/syscalls.list +++ b/sysdeps/unix/sysv/linux/syscalls.list @@ -17,7 +17,7 @@ getpid - getpid Ei: __getpid getpid getegid - getegid Ei: __getegid getegid geteuid - geteuid Ei: __geteuid geteuid getpgid - getpgid i:i __getpgid getpgid -getpgrp - getpgrp Ei: getpgrp +getpgrp - getpgrp Ei: __getpgrp getpgrp getppid - getppid Ei: __getppid getppid getresuid - getresuid i:ppp getresuid getresgid - getresgid i:ppp getresgid diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist index 095e914b73..0ef949d649 100644 --- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist @@ -2521,6 +2521,8 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F GLIBC_2.4 __confstr_chk F GLIBC_2.4 __fgets_chk F GLIBC_2.4 __fgets_unlocked_chk F diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist index dd910f7fe9..11ec9f4fda 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist @@ -2627,3 +2627,5 @@ GLIBC_2.34 tss_create F GLIBC_2.34 tss_delete F GLIBC_2.34 tss_get F GLIBC_2.34 tss_set F +GLIBC_2.35 posix_spawnattr_tcgetpgrp_np F +GLIBC_2.35 posix_spawnattr_tcsetpgrp_np F diff --git a/termios/tcsetpgrp.c b/termios/tcsetpgrp.c index 05630cd04c..9bd94a70bc 100644 --- a/termios/tcsetpgrp.c +++ b/termios/tcsetpgrp.c @@ -21,7 +21,7 @@ /* Set the foreground process group ID of FD set PGRP_ID. */ int -tcsetpgrp (int fd, pid_t pgrp_id) +__tcsetpgrp (int fd, pid_t pgrp_id) { if (fd < 0) { @@ -32,6 +32,7 @@ tcsetpgrp (int fd, pid_t pgrp_id) __set_errno (ENOSYS); return -1; } - +weak_alias (__tcsetpgrp, tcsetpgrp); +libc_hidden_def (__tcsetpgrp) stub_warning (tcsetpgrp)