abduco

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 3e4485642bd79f6a047c27bc494ad69918eedcd6
parent f4d3f21f00384a2ec1ac80a4240888824ae7e298
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue, 17 Jun 2014 15:59:17 +0200

Do not start server main loop if execvp(3) failed

Diffstat:
abduco.c | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/abduco.c b/abduco.c @@ -22,6 +22,7 @@ #include <stdbool.h> #include <stddef.h> #include <signal.h> +#include <poll.h> #include <libgen.h> #include <string.h> #include <limits.h> @@ -298,6 +299,9 @@ static bool create_session(const char *name, char * const argv[]) { dup2(fd, 2); #endif /* NDEBUG */ close(pipefds[1]); + struct pollfd pipe_status = { .fd = pipefds[0], .events = POLLIN }; + if (poll(&pipe_status, 1, -1) == 1 && pipe_status.revents == POLLHUP) + exit(EXIT_FAILURE); server_mainloop(); break; } @@ -314,8 +318,9 @@ static bool create_session(const char *name, char * const argv[]) { close(pipefds[1]); int status; wait(&status); /* wait for first fork */ - if ((status = read_all(pipefds[0], errormsg, sizeof(errormsg))) > 0) { - write_all(STDERR_FILENO, errormsg, status); + ssize_t len = read_all(pipefds[0], errormsg, sizeof(errormsg)); + if (len > 0) { + write_all(STDERR_FILENO, errormsg, len); unlink(sockaddr.sun_path); exit(EXIT_FAILURE); }