All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Brauner <christian.brauner@ubuntu.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: Elichai Turkel <elichai.turkel@gmail.com>,
	linux-api@vger.kernel.org, libc-alpha <libc-alpha@sourceware.org>,
	dhowells@redhat.com
Subject: Re: Continuing the UAPI split
Date: Thu, 7 Nov 2019 15:05:59 +0100	[thread overview]
Message-ID: <20191107140558.kgbgnfihvmssm7sj@wittgenstein> (raw)
In-Reply-To: <87v9rvhk6t.fsf@oldenburg2.str.redhat.com>

On Thu, Nov 07, 2019 at 02:47:54PM +0100, Florian Weimer wrote:
> * Christian Brauner:
> 
> > A problem I recently ran into that is related are problems with
> > sys/wait.h and linux/wait.h.
> > How P_{PID,PGID,PIDFD} used by the waitid() syscall are defined is
> > different for the two headers.
> > linux/wait.h uses #define for P_{PID,PGID,PIDFD} whereas sys/wait.h
> > uses an enum.
> > The problem is that if I simply don't rely on sys/wait.h and just do
> > #ifndef P_PID
> > #define P_PID <value>
> > #endif
> > where value is what the syscall expects then technically I need to call
> > the waitid() syscall directly since it's not at all guaranteed - afaict
> > - that the P_PID enum == P_PID define that glibc uses for its waitid()
> > syscall wrapper.
> 
> Right, and this is where POSIX mandates that there is a type idtype_t
> which is an enum, an that it has members P_PID etc.
> 
> What we could do is:
> 
> typedef enum
> {
>   P_ALL,		/* Wait for any child.  */
> #define P_ALL P_ALL
>   P_PID,		/* Wait for specified process.  */
> #define P_PID P_PID
>   P_PGID		/* Wait for members of process group.  */
> #define P_PGID P_PGID
> } idtype_t;

Right, that sounds feasible.
(Nit/slightly off-topic: David (forgot to Cc him...) once reminded me
 that we do prefer to explicitly set the enum value so that there are no
 accidental changes, e.g.:

typedef enum
{
  P_ALL = 0,		/* Wait for any child.  */
#define P_ALL P_ALL
  P_PID = 1,		/* Wait for specified process.  */
#define P_PID P_PID
  P_PGID = 2,		/* Wait for members of process group.  */
#define P_PGID P_PGID
  P_PIDFD = 3,		/* Wait via pidfds.  */
#define P_PIDFD P_PIDFD
} idtype_t;

)

> 
> The other header can then use #ifdef.  You'll see that pattern in some
> cases already.
> 
> But that will only work if you include glibc headers first.  The generic
> approach uses some shared macro for the coordination so that things work
> both ways.

We saw a conflict at least on Fedora for the pidfd-tests with the new
P_PIDFD type defined in linux/wait.h but not yet in sys/wait.h and it
was exactly caused by wrong inclusion order. :)

> 
> The other issue here is that it gets rather iffy from a language point
> of view if the kernel wants to add additional constants and glibc has
> still the old idtype_t definition.
> 
> > So I'm now in a scenario where I can't call the glibc wrapper for
> > waitid() with the linux/wait.h defines and I can't call the syscall
> > directly (e.g. because I want to make use of the syscall's rusage
> > argument that glibc doesn't expose) with sys/wait.h's P_PID enum.
> > I'm not sure what the right solution is here...
> 
> Yes, it's a hard problem.  waitid is particularly annoying because POSIX
> and the kernel have such different function prototypes.  We could
> perhaps expose the actual waitid system call under a different name, and

Wouldn't be the worst idea.

> use int for the ID type parameter.  But that needs someone to write a
> patch.  (My efforts to add syscall wrappers have stalled unfortunately.)

This could be a good Google Summer of Code or Outreachy project or
something tbh. In general, some more noise around this would probably
help. Especially with the ability to use Gerrit to submit patches that
might make it easier for people to contribute...
Do we officially document somewhere how to add glibc syscall wrappers?

Christian

  reply	other threads:[~2019-11-07 14:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CALN7hCK0EXLXjPRPr+tuuF2-uQvkLMCFDNzGhv9HS-jrAz6Hmg@mail.gmail.com>
2019-11-07 12:05 ` Continuing the UAPI split Christian Brauner
2019-11-07 12:10   ` Florian Weimer
2019-11-07 13:03     ` Elichai Turkel
2019-11-07 13:23       ` Florian Weimer
2019-11-07 13:36         ` Christian Brauner
2019-11-07 13:47           ` Florian Weimer
2019-11-07 14:05             ` Christian Brauner [this message]
2019-11-07 18:02         ` Carlos O'Donell
2019-11-07 16:21       ` Szabolcs Nagy
2019-11-07 18:05         ` Carlos O'Donell
2019-11-07 20:32           ` Florian Weimer
2019-11-07 22:32             ` Carlos O'Donell
2019-11-08  7:28               ` 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=20191107140558.kgbgnfihvmssm7sj@wittgenstein \
    --to=christian.brauner@ubuntu.com \
    --cc=dhowells@redhat.com \
    --cc=elichai.turkel@gmail.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-api@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.