public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Jeremy Drake <cygwin@jdrake.com>
To: cygwin@cygwin.com
Subject: Re: posix_spawn issues on i686
Date: Tue, 11 Jan 2022 10:45:00 -0800 (PST)	[thread overview]
Message-ID: <alpine.BSO.2.21.2201111042390.11760@resin.csoft.net> (raw)
In-Reply-To: <alpine.BSO.2.21.2201101132030.11760@resin.csoft.net>

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

On Mon, 10 Jan 2022, Jeremy Drake wrote:

> From https://github.com/msys2/MSYS2-packages/issues/2801
>
> MSYS2 recently rebuilt GNU make 4.3, and I found that after rebuilding, it
> broke rather horribly on i686, where any attempt to run a command resulted
> in "Invalid argument" errors.  Some debugging revealed that rebuilding
> make resulted in it using posix_spawn now instead of vfork.  Passing
> --disable-posix-spawn to make's configure script results in a working i686
> make.
>

> Can you create a simple, self-contained testcase in plain C?


Sorry, I am not subscribed to the list so don't have the message to reply
to for threading purposes, but attached please find a C reproducer that
works on x86_64 but fails on i686.  The particular issue seems to be the
POSIX_SPAWN_RESETIDS flag - not setting that allows i686 to succeed too.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-c; name=posix_spawn.c, Size: 1148 bytes --]

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <unistd.h>
#include <spawn.h>
#include <sys/wait.h>

extern char **environ;

int main()
{
    pid_t pid;
    char *argv[] = {"sh", "-c", "echo hi", NULL};
    posix_spawnattr_t attr;
    int status;
    short flags = POSIX_SPAWN_RESETIDS;

    if ((status = posix_spawnattr_init(&attr)) != 0) {
        printf("posix_spawnattr_init: %s\n", strerror(status));
	return status;
    }
    if ((status = posix_spawnattr_setflags(&attr, flags)) != 0) {
        printf("posix_spawnattr_setflags: %s\n", strerror(status));
	return status;
    }

    status = posix_spawn(&pid, "/bin/sh", NULL, &attr, argv, environ);
    if (status == 0) {
        printf("Child pid: %i\n", pid);
        do {
          if (waitpid(pid, &status, 0) != -1) {
            printf("Child status %d\n", WEXITSTATUS(status));
          } else {
            perror("waitpid");
            return 1;
          }
        } while (!WIFEXITED(status) && !WIFSIGNALED(status));
    } else {
        printf("posix_spawn: %s\n", strerror(status));
    }
    return status;
}

  parent reply	other threads:[~2022-01-11 18:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-10 19:38 Jeremy Drake
2022-01-11 10:07 ` Corinna Vinschen
2022-01-11 18:45 ` Jeremy Drake [this message]
2022-01-11 21:08   ` Ken Brown
2022-01-12 10:41     ` Corinna Vinschen
2022-01-12 11:24       ` Corinna Vinschen
2022-01-12 16:32       ` Ken Brown
2022-01-12 21:25     ` Jeremy Drake
2022-01-14  9:15       ` Corinna Vinschen

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=alpine.BSO.2.21.2201111042390.11760@resin.csoft.net \
    --to=cygwin@jdrake.com \
    --cc=cygwin@cygwin.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.
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).