From patchwork Wed Feb 2 21:59:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 50685 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 9A3BE3857C42 for ; Wed, 2 Feb 2022 21:59:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A3BE3857C42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1643839178; bh=uyJSEjhhtfw3f6lcpBpSo3ls1ygatHMJqmsisrGDNgw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=imD42IsQ3sKfq9wRLEgM+lKxceomKScoQAYgZhBBkBwoz0Kt4Ysho/Z68eixeovjV 9i1zjlb2ehZhyPYbi4W/o5UzZHHRm76/wW6rs/qMWX621lIDOZIUnd+/m8ZCcAWo9P mNkP2CHr0DCXHnRjNexBhyd4YMMsh7jCwSbsbLFA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id C7F7A3858C2C for ; Wed, 2 Feb 2022 21:59:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C7F7A3858C2C Received: by mail-oi1-x232.google.com with SMTP id q8so973397oiw.7 for ; Wed, 02 Feb 2022 13:59:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uyJSEjhhtfw3f6lcpBpSo3ls1ygatHMJqmsisrGDNgw=; b=fe8fB57Ehd/FurtuflMseSZfvS7DdGEydriv91ey4qqVkYXjkF6InH6mtEM68KTI07 Uxjn/f0faKWh2GTN5gHnNExvjjonRhQEDj0isjtVI/FXyKhrvXGQ/tHrSeExVIlhY78d LHBn8RZg7lj1GwL6h5draI0ypsawWhECfVi0qgvRIIHvhGaozqf+tM0dUc/vAkA6vgc0 +3rCk23J6o3fIdotvP2PkLkqbLemvXCp6HKSe7boXCxrjtW4QZ/tyqDM95a4AX9BDRox o8AUF9DY1a6Xw00cRu/1eZt7AlXAD2NkpA5osbMudTX8rjnBQpDfkHOgmFPXsmyi5QNJ mm3g== X-Gm-Message-State: AOAM530i4Pb2UiBNOitIaRbAn7XqtZkEX4XoIrZuaRB1ln0HdgASmKA4 Cbvr3DSuSC0x8otDBGe6A3PaIUdg3KNaaQ== X-Google-Smtp-Source: ABdhPJydNzXUqf0qAAr+5nCzGOGYDvlTewDHv1aiRW/uI9m3RshunTXopof87p+LN+eQU9OSz43DNw== X-Received: by 2002:a05:6808:56d:: with SMTP id j13mr5530436oig.153.1643839156056; Wed, 02 Feb 2022 13:59:16 -0800 (PST) Received: from birita.. ([2804:431:c7ca:709a:f76b:4912:74b6:67e1]) by smtp.gmail.com with ESMTPSA id h17sm14242397otn.60.2022.02.02.13.59.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 13:59:15 -0800 (PST) To: libc-alpha@sourceware.org, Carlos O'Donell Subject: [PATCH] posix: Fix tst-spawn6 terminal handling (BZ #28853) Date: Wed, 2 Feb 2022 18:59:11 -0300 Message-Id: <20220202215911.3153490-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: John David Anglin Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The test changes the current foreground process group, which might break testing depending of how the make check is issued. For instance: nohup make -j1 test t=posix/tst-spawn6 | less Will set 'make' and 'less' to be in the foreground process group in the current session. When tst-spawn6 new child takes over it becomes the foreground process and 'less' is stopped and backgrounded which interrupts the 'make check' command. To fix it a pseudo-terminal is allocated, the test starts in new session (so there is no controlling terminal associated), and the pseudo-terminal is set as the controlling one (similar to what login_tty does). Checked on x86_64-linux-gnu. Tested-by: Carlos O'Donell Reviewed-by: Carlos O'Donell --- posix/tst-spawn6.c | 62 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/posix/tst-spawn6.c b/posix/tst-spawn6.c index 911e90a461..044abd8535 100644 --- a/posix/tst-spawn6.c +++ b/posix/tst-spawn6.c @@ -29,7 +29,14 @@ #include #include #include +#include #include +#include + +#ifndef PATH_MAX +# define PATH_MAX 1024 +#endif +static char ptmxpath[PATH_MAX]; static int handle_restart (const char *argv1, const char *argv2) @@ -115,7 +122,7 @@ run_subprogram (int argc, char *argv[], const posix_spawnattr_t *attr, } static int -do_test (int argc, char *argv[]) +run_test (int argc, char *argv[]) { /* We must have either: - four parameters left if called initially: @@ -127,16 +134,7 @@ do_test (int argc, char *argv[]) + --setgrpr optional */ - if (restart) - return handle_restart (argv[1], argv[2]); - - int tcfd = open64 (_PATH_TTY, O_RDONLY, 0600); - if (tcfd == -1) - { - if (errno == ENXIO) - FAIL_UNSUPPORTED ("terminal not available, skipping test"); - FAIL_EXIT1 ("open64 (\"%s\", 0x%x, 0600): %m", _PATH_TTY, O_RDONLY); - } + int tcfd = xopen (ptmxpath, O_RDONLY, 0600); /* Check setting the controlling terminal without changing the group. */ { @@ -198,5 +196,47 @@ do_test (int argc, char *argv[]) return 0; } +static int +do_test (int argc, char *argv[]) +{ + if (restart) + return handle_restart (argv[1], argv[2]); + + pid_t pid = xfork (); + if (pid == 0) + { + /* Create a pseudo-terminal to avoid interfering with the one using by + test itself, creates a new session (so there is no controlling + terminal), and set the pseudo-terminal as the controlling one. */ + int ptmx = posix_openpt (0); + if (ptmx == -1) + { + if (errno == ENXIO) + FAIL_UNSUPPORTED ("terminal not available, skipping test"); + FAIL_EXIT1 ("posix_openpt (0): %m"); + } + TEST_VERIFY_EXIT (grantpt (ptmx) == 0); + TEST_VERIFY_EXIT (unlockpt (ptmx) == 0); + + TEST_VERIFY_EXIT (setsid () != -1); + TEST_VERIFY_EXIT (ioctl (ptmx, TIOCSCTTY, NULL) == 0); + while (dup2 (ptmx, STDIN_FILENO) == -1 && errno == EBUSY) + ; + while (dup2 (ptmx, STDOUT_FILENO) == -1 && errno == EBUSY) + ; + while (dup2 (ptmx, STDERR_FILENO) == -1 && errno == EBUSY) + ; + TEST_VERIFY_EXIT (ptsname_r (ptmx, ptmxpath, sizeof ptmxpath) == 0); + xclose (ptmx); + + run_test (argc, argv); + _exit (0); + } + int status; + xwaitpid (pid, &status, 0); + TEST_VERIFY (WIFEXITED (status)); + exit (0); +} + #define TEST_FUNCTION_ARGV do_test #include