mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rasmus Andersson <rasmus@notion.se>
To: musl@lists.openwall.com
Subject: Re: [musl] waitpid (wait4) on Linux 5 returns invalid values
Date: Tue, 19 Jan 2021 12:28:05 -0800	[thread overview]
Message-ID: <CADFzTtd-47-iNo-YxqEH5UD3vCuCWd5c-EypK3XTQV3aqG94=Q@mail.gmail.com> (raw)
In-Reply-To: <CADFzTtcDTEy-Z7npnG=_BFBoFDfr_02tUn9apmvySSSVX69yLQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1852 bytes --]

In the meantime, in case you're curious, here's a program that
reproduces the issue. I've attached a statically-compiled version too
that can be disassembled. Running it:
$ gcc -static a.c && ./a.out
waitpid returned -10, wstat=0

#include <sys/wait.h>
#include <stdio.h>
int main(int argc, char **argv) {
        int wstat = 0;
        pid_t child = waitpid(-1, &wstat, WNOHANG);
        printf("waitpid returned %d, wstat=%d\n", child, wstat);
        return 0;
}

On Tue, Jan 19, 2021 at 12:17 PM Rasmus Andersson <rasmus@notion.se> wrote:
>
> On Tue, Jan 19, 2021 at 11:33 AM Markus Wichmann <nullplan@gmx.net> wrote:
> >
> > On Tue, Jan 19, 2021 at 10:18:04AM -0800, Rasmus Andersson wrote:
> > > However the wait4 syscall[3] in Linux 5 returns other values,
> > > specifically it returns errors as negative values. The error that
> > > trips up programs like runit's runsv is ECHILD (-10) which wait4
> > > returns when there are no children (i.e. they have exited.)
> > >
> >
> > Hmm... that is very weird. That should not happen. Because the
> > syscall_cp macro already contains a call to __syscall_ret(), which does
> > exactly what you propose. So that means, there is something else going
> > on in your copy of the code. Did you change anything about the source
> > code? Or can you disassemble the function to see what it does?
> >
> Strange! You are right of course; looking at src/internal/syscall.h I
> indeed see that syscall_cp calls __syscall_ret(__syscall_cp(args))
> The musl I'm building with comes from https://musl.cc/#binaries which
> is created from these scripts according to the author:
> https://git.zv.io/xstatic/mcm It doesn't seem to apply any patches.
> Anyhow, I'm currently building musl & gcc myself using
> musl-cross-make. I will see how that pans out and report back.
> Thank you for your quick response Markus!

[-- Attachment #2: a.tar.gz --]
[-- Type: application/x-gzip, Size: 9769 bytes --]

  reply	other threads:[~2021-01-19 20:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-19 18:18 Rasmus Andersson
2021-01-19 19:33 ` Markus Wichmann
2021-01-19 20:17   ` Rasmus Andersson
2021-01-19 20:28     ` Rasmus Andersson [this message]
2021-01-19 20:35       ` Rasmus Andersson
2021-01-19 20:56         ` Rasmus Andersson
2021-01-19 21:16         ` Rich Felker
2021-01-19 22:00           ` Rasmus Andersson
2021-01-19 22:02             ` Rasmus Andersson
2021-01-19 23:01               ` Zach van Rijn
2021-01-19 23:07                 ` Rasmus Andersson

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='CADFzTtd-47-iNo-YxqEH5UD3vCuCWd5c-EypK3XTQV3aqG94=Q@mail.gmail.com' \
    --to=rasmus@notion.se \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).