From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 04E753858D37 for ; Wed, 2 Feb 2022 22:23:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 04E753858D37 Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-640-w-4OS2DwNyyZ4oXLwPalZA-1; Wed, 02 Feb 2022 17:23:52 -0500 X-MC-Unique: w-4OS2DwNyyZ4oXLwPalZA-1 Received: by mail-io1-f72.google.com with SMTP id h1-20020a056602008100b0061152382337so465983iob.18 for ; Wed, 02 Feb 2022 14:23:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=a8geD7365xl7w+4508Usj5H1tr6IaBJ9Fcds+QRI2uE=; b=V/iSYOAl8iKOKevKHXBEPzhyY3jpAqZVDwwO3YlDwvNKru4IGCtarKsduD0c/kEuRk mz5CV124x6sOZ3TYo+4aAVCPcmn5mJlZ7q3wwwj7jO68wSxg+RakJ3qNIusq46so4u85 enKNGxeks1ALPjZaM7xLR8EN9agmJ/eYq6BDe+7PcOEh/cVVYa7HG+ObQN2/bPZYTsOs +iP1wJ5+F1Cla6Vu8aopGIQCtEW+QHIsQmX/SNuU7zxrbSqNFvNMFjZxdcDRMWNgk7Ag uIU9GCN5+0Fn7TZ2QNLDsMdR7HYoEEGNvdtgAIDR4jxEBgbrIYDuJGzLxMEPnEvDT72n OrCg== X-Gm-Message-State: AOAM531jT82X5TR2pFzuh4qOPFTryyBy+4hErI8Vxmj1IxlOHLCUA4za r5kWjoNQsoHKuWcaoA9XCra9GgEHKJjCJpgJQDpcsjWPCaNa57XbYyunjzOcn7+uIGhSFK1Rysv jG3M0cK9Y/WB0PnVNO21Q X-Received: by 2002:a02:6d52:: with SMTP id e18mr16200096jaf.248.1643840631766; Wed, 02 Feb 2022 14:23:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIqUj5xl7ssvOd5G5QS59+CYbaQJy38uF+DuX37hOdyELSRjj190kG+ngbaftrcVq5KlCOvw== X-Received: by 2002:a02:6d52:: with SMTP id e18mr16200094jaf.248.1643840631508; Wed, 02 Feb 2022 14:23:51 -0800 (PST) Received: from [192.168.0.241] (135-23-175-80.cpe.pppoe.ca. [135.23.175.80]) by smtp.gmail.com with ESMTPSA id i6sm10001747ilk.77.2022.02.02.14.23.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Feb 2022 14:23:50 -0800 (PST) Message-ID: Date: Wed, 2 Feb 2022 17:23:49 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH] posix: Fix tst-spawn6 terminal handling (BZ #28853) To: Adhemerval Zanella , libc-alpha@sourceware.org Cc: John David Anglin References: <20220202215911.3153490-1-adhemerval.zanella@linaro.org> From: Carlos O'Donell Organization: Red Hat In-Reply-To: <20220202215911.3153490-1-adhemerval.zanella@linaro.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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-List-Received-Date: Wed, 02 Feb 2022 22:23:56 -0000 On 2/2/22 16:59, Adhemerval Zanella wrote: > 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. OK for glibc 2.35, and this fixes the test issues reported in bug 28853. Tested on x86_64. 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]; OK. > > 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]); > + OK. In hindsight I think this can all be simplified using forkpty(). > + 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) > + ; OK. This connects to the ptm side of the terminal. > + TEST_VERIFY_EXIT (ptsname_r (ptmx, ptmxpath, sizeof ptmxpath) == 0); OK. This is OK as-is, but it fills ptmxpath with the pts side of the ptm/pts pair. So we end up operating on the pts side, but I think that's fine because it's the terminal that matters. > + 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 -- Cheers, Carlos.