From 649d85b8e3bd3797baa68c405d33c5241f3fb70b Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 6 Feb 2018 18:12:36 -0500 Subject: exec: Avoid a warning when building with _FORTIFY_SOURCE Also, don't pass the address of errno itself to write(), since write() is allowed to modify it. --- exec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'exec.c') diff --git a/exec.c b/exec.c index 489953e..3fa5789 100644 --- a/exec.c +++ b/exec.c @@ -382,8 +382,13 @@ static int bfs_exec_spawn(const struct bfs_exec *execbuf) { } execvp(execbuf->argv[0], execbuf->argv); + + int error; child_err: - write(pipefd[1], &errno, sizeof(errno)); + error = errno; + if (write(pipefd[1], &error, sizeof(error)) != sizeof(error)) { + // Parent will still see that we exited unsuccessfully, but won't know why + } close(pipefd[1]); _Exit(EXIT_FAILURE); } -- cgit v1.2.3