From e1df8ebafd92fc444689fdf94b2d052a80b3da9a Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 24 Mar 2013 11:38:09 +0100 Subject: [PATCH] my_system: cleanup and propagate exitstatus --- src/system/helpers.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 637fd295f..d340a35f0 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -103,7 +103,7 @@ int my_system(int argc, const char *arg, ...) case -1: /* can't vfork */ perror("vfork"); ret = -errno; - goto out; + break; case 0: /* child process */ for(i = 3; i < maxfd; i++) close(i); @@ -111,21 +111,17 @@ int my_system(int argc, const char *arg, ...) perror("my_system setsid"); if (execvp(argv[0], (char * const *)argv)) { - if (errno != ENOENT) { /* don't complain if argv[0] only does not exist */ - std::string txt = "ERROR: my_system \"" + (std::string) argv[0] + "\""; - perror(txt.c_str()); - } ret = -errno; + if (errno != ENOENT) /* don't complain if argv[0] only does not exist */ + fprintf(stderr, "ERROR: my_system \"%s\": %m\n", argv[0]); } - _exit (0); // terminate c h i l d proces s only + _exit(ret); // terminate c h i l d proces s only default: /* parent returns to calling process */ + waitpid(pid, &childExit, 0); + if (WEXITSTATUS(childExit) != 0) + ret = (signed char)WEXITSTATUS(childExit); break; } - /* it is probably pure luck that ret gets propagated back from child to parent */ - waitpid(pid, &childExit, 0); - if(childExit != 0) - ret = childExit; - out: va_end(args); return ret; }