From 3e4485642bd79f6a047c27bc494ad69918eedcd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Tue, 17 Jun 2014 15:59:17 +0200 Subject: [PATCH] Do not start server main loop if execvp(3) failed --- abduco.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/abduco.c b/abduco.c index bf1f45e..56fcad8 100644 --- a/abduco.c +++ b/abduco.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -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); }