public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Godmar Back <godmar@gmail.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: Libc-help <libc-help@sourceware.org>
Subject: Re: supporting terminal ownership assignment (tcsetpgrp()) in posix_spawn
Date: Tue, 8 Jun 2021 18:11:33 -0400	[thread overview]
Message-ID: <CAB4+JYJwW5i881HFgSwKG1ChcHjNpiBf-S3t=4JrFejCKwNxfw@mail.gmail.com> (raw)
In-Reply-To: <11145e53-3fbc-0f04-33f8-b2d9981f0ea8@linaro.org>

On Tue, Jun 8, 2021 at 12:42 PM Adhemerval Zanella <
adhemerval.zanella@linaro.org> wrote:

> >
> >
> >>
> >> If the caller already has group it want to use, it can issue instead:
> >>
> >>   posix_spawnattr_t attr;
> >>   posix_spawnattr_setpgroup (&attr, groupid);
> >>   posix_spawnattr_tcsetpgrp_np (&attr, fd, groupid);
> >>
> >> Which in turn will make the created process to issue:
> >>
> >>   setpgid (0, groupid);
> >>   tcsetpgrp (fd, groupid);
> >>
> >
> > For this use case, as long as it supports groupid == 0, this should work
> as
> > it is what shells currently do.
>
> So the my question is whether providing the groupid as an argument is
> really required (I would say yes so it can be combined with
> posix_spawnattr_setpgroup).
>

The Blackberry API does not pass an argument (as a point of reference).
In practice, when spawning a pipeline like a | b | c ... we pass group id 0
to the
first child, and then the pid if of the first child as the pgrp id to the
second and
third. This means that if the groupid is omitted, it needs to refer to the
group id that was given to POSIX_SPAWN_SETPGROUP, and thus
POSIX_SPAWN_SETPGROUP is a prerequisite for it.


>
> Another question is when to issue the tcsetpgrp related to
> POSIX_SPAWN_SETSID. I would say tcsetpgrp should be issued *before*
> setsid, so tcsetpgrp can return early if it fails. Otherwise tcsetpgrp
> will always fail if POSIX_SPAWN_SETSID is set (it would be a caller
> error, but I think from API viewpoint it should be better if we could
> minimize the possible error scenarios).
>

I haven't checked how the current implementation works. Do you use a pipe
or something
for the child to report back if something went wrong, or does the parent
somehow check if the
asked-for actions in the child will likely succeed?  If the former, doing
setsid first, and then,
if given, doing the tcsetpgrp call will fail as you say and this failure
would be reported back
to the caller. Then they know they've misused the API.

If you do tcsetpgrp first and then setsid, the tcsetpgrp will succeed, but
will be ineffective, and
the caller won't ever know.

  reply	other threads:[~2021-06-08 22:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-03 13:58 Godmar Back
2021-06-07 21:04 ` Adhemerval Zanella
2021-06-07 21:23   ` Godmar Back
2021-06-07 21:36     ` Adhemerval Zanella
2021-06-07 23:57       ` Godmar Back
2021-06-08 13:50         ` Adhemerval Zanella
2021-06-08 14:37           ` Godmar Back
2021-06-08 16:42             ` Adhemerval Zanella
2021-06-08 22:11               ` Godmar Back [this message]
2021-06-09  6:41                 ` Florian Weimer
2021-06-09 12:00                 ` Adhemerval Zanella
2021-06-09 13:12                   ` Godmar Back
2021-06-11 13:45                     ` Adhemerval Zanella
2021-06-11 23:58                       ` Godmar Back

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='CAB4+JYJwW5i881HFgSwKG1ChcHjNpiBf-S3t=4JrFejCKwNxfw@mail.gmail.com' \
    --to=godmar@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-help@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).