public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "pokogiv215 at sweatmail dot com" <sourceware-bugzilla@sourceware.org> To: glibc-bugs@sourceware.org Subject: [Bug libc/25715] New: system() returns wrong errors when posix_spawn fails Date: Mon, 23 Mar 2020 13:48:17 +0000 [thread overview] Message-ID: <bug-25715-131@http.sourceware.org/bugzilla/> (raw) https://sourceware.org/bugzilla/show_bug.cgi?id=25715 Bug ID: 25715 Summary: system() returns wrong errors when posix_spawn fails Product: glibc Version: 2.30 Status: UNCONFIRMED Severity: normal Priority: P2 Component: libc Assignee: unassigned at sourceware dot org Reporter: pokogiv215 at sweatmail dot com CC: drepper.fsp at gmail dot com Target Milestone: --- On linux, I observe a call to system() claiming it's killed by sigbus when really the underlying execv failed with E2BIG. See reproduction in [1]. What I expected to see is system() returning with exit code 127, as per `man system`: * If a shell could not be executed in the child process, then the return value is as though the child shell terminated by calling _exit(2) with the status 127. Less important, but what I also expected is for posix_spawn to return 0 in this case and to fill in the pid, but instead it returns E2BIG and doesn't fill in the pid, which is not the behavior described by posix_spawn's man page: The posix_spawn() and posix_spawnp() functions fail only in the case where the underlying fork(2) or vfork(2) call fails; in these cases, these functions return an error number, which will be one of the errors described for fork(2) or vfork(2). The bad return value from system() was introduced in 5fb7fc96350575c9adb1316833e48ca11553be49, which returns posix_spawn's result (an errno) from system (which returns a wait status). The posix_spawn handling of errors in the child seems to have changed unintentionally in 4b4d4056bb154603f36c6f8845757c1012758158 (because ec didn't use to be set). [1] $ cat a.c #include <stdio.h> #include <string.h> #include <signal.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <spawn.h> int main(int argc, char* argv[], char** env) { char cmd[150000]; memset(cmd, 'a', sizeof(cmd)); cmd[sizeof(cmd) - 1] = 0; int ret = posix_spawn(NULL, "/bin/sh", 0, NULL, (char *[]){"sh", "-c", (char *)cmd, 0}, env); printf("posix_spawn returns: %d = %s\n", ret, strerror(ret)); int wstatus = system(cmd); if (WIFEXITED(wstatus)) { printf("exited, status=%d\n", WEXITSTATUS(wstatus)); } else if (WIFSIGNALED(wstatus)) { printf("killed by signal %d = %s\n", WTERMSIG(wstatus), strsignal(WTERMSIG(wstatus))); } else if (WIFSTOPPED(wstatus)) { printf("stopped by signal %d\n", WSTOPSIG(wstatus)); } else if (WIFCONTINUED(wstatus)) { printf("continued\n"); } return 0; } $ gcc a.c && ./a.out posix_spawn returns: 7 = Argument list too long killed by signal 7 = Bus error -- You are receiving this mail because: You are on the CC list for the bug.
next reply other threads:[~2020-03-23 13:48 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-03-23 13:48 pokogiv215 at sweatmail dot com [this message] 2020-03-23 14:01 ` [Bug libc/25715] " adhemerval.zanella at linaro dot org 2020-03-23 16:24 ` adhemerval.zanella at linaro dot org 2020-03-23 21:05 ` cvs-commit at gcc dot gnu.org 2020-03-23 21:06 ` adhemerval.zanella at linaro dot org 2020-03-24 11:51 ` cvs-commit at gcc dot gnu.org 2020-03-24 12:16 ` cvs-commit at gcc dot gnu.org
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=bug-25715-131@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@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: linkBe 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).