aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/posix
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2020-03-23 15:23:20 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2020-03-23 18:00:38 -0300
commitf09542c584b121da0322fde4b55306d512b85d93 (patch)
tree7e7bc3c14acdb041b9f231e3caf430562fc936f6 /sysdeps/posix
parent03343699496edd866141a8bbdfeb19ae98537394 (diff)
downloadglibc-f09542c584b121da0322fde4b55306d512b85d93.zip
glibc-f09542c584b121da0322fde4b55306d512b85d93.tar.gz
glibc-f09542c584b121da0322fde4b55306d512b85d93.tar.bz2
posix: Fix system error return value [BZ #25715]
It fixes 5fb7fc9635 when posix_spawn fails. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'sysdeps/posix')
-rw-r--r--sysdeps/posix/system.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/sysdeps/posix/system.c b/sysdeps/posix/system.c
index e613e6a..a03f478 100644
--- a/sysdeps/posix/system.c
+++ b/sysdeps/posix/system.c
@@ -101,7 +101,8 @@ cancel_handler (void *arg)
static int
do_system (const char *line)
{
- int status;
+ int status = -1;
+ int ret;
pid_t pid;
struct sigaction sa;
#ifndef _LIBC_REENTRANT
@@ -144,14 +145,14 @@ do_system (const char *line)
__posix_spawnattr_setflags (&spawn_attr,
POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK);
- status = __posix_spawn (&pid, SHELL_PATH, 0, &spawn_attr,
- (char *const[]){ (char*) SHELL_NAME,
- (char*) "-c",
- (char *) line, NULL },
- __environ);
+ ret = __posix_spawn (&pid, SHELL_PATH, 0, &spawn_attr,
+ (char *const[]){ (char *) SHELL_NAME,
+ (char *) "-c",
+ (char *) line, NULL },
+ __environ);
__posix_spawnattr_destroy (&spawn_attr);
- if (status == 0)
+ if (ret == 0)
{
/* Cancellation results in cleanup handlers running as exceptions in
the block where they were installed, so it is safe to reference
@@ -186,6 +187,9 @@ do_system (const char *line)
}
DO_UNLOCK ();
+ if (ret != 0)
+ __set_errno (ret);
+
return status;
}