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

This commit is contained in:
Marc André Tanner 2014-06-17 15:59:17 +02:00
parent f4d3f21f00
commit 3e4485642b
1 changed files with 7 additions and 2 deletions

View File

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