public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: libc-alpha@sourceware.org
Subject: Re: [glibc] posix: Add terminal control setting support for posix_spawn
Date: Thu, 27 Jan 2022 11:49:17 +0100	[thread overview]
Message-ID: <87bkzxpi6q.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20220125180124.B88AC3857C70@sourceware.org> (Adhemerval Zanella via Glibc-cvs's message of "Tue, 25 Jan 2022 18:01:24 +0000 (GMT)")

* Adhemerval Zanella via Glibc-cvs:

> commit 342cc934a3bf74ac618e2318d738f22ac93257ba
> Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> Date:   Mon Jun 14 14:41:31 2021 -0300
>
>     posix: Add terminal control setting support for posix_spawn
>     
>     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);

Sorry, I did not look at this in detail so far.  A file descriptor
outside the file actions API makes me quite nervous.

Advanced Programming in the UNIX Environment says (like POSIX), “If the
process has a controlling terminal, the process can call tcsetpgrp to
set the foreground process group ID […]”.  This suggests to me that a
file action may be required to establish a controlling terminal.
Callers of posix_spawn might restrict that to the spawned process.  As
far as I know, Linux follows SVR4, and opening the terminal device under
/dev/pts/ in a session leader that has no controlling terminal
establishes one.  This translate to a posix_spawn file action.  So the
action established by posix_spawnattr_tcsetpgrp_np must come after the
file actions.

But the descriptor used by posix_spawnattr_tcsetpgrp_np must still be
open.  So it would have to come before a closefrom file action (or a
regular close).

I think this means that the action established by
posix_spawnattr_tcsetpgrp_np needs to be sequenced among the file
actions, and needs to be a file action itself.

Thanks,
Florian


       reply	other threads:[~2022-01-27 10:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220125180124.B88AC3857C70@sourceware.org>
2022-01-27 10:49 ` Florian Weimer [this message]
2022-01-27 11:38   ` Adhemerval Zanella
2022-01-27 11:57     ` Florian Weimer
2022-01-27 12:02       ` Adhemerval Zanella
2022-01-27 12:15         ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bkzxpi6q.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).