From f09542c584b121da0322fde4b55306d512b85d93 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Mon, 23 Mar 2020 15:23:20 -0300 Subject: 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 --- sysdeps/posix/system.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'sysdeps/posix') 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; } -- cgit v1.1