From 1a563a0cbd4926d0dfe9065a4fcd8771c5b292cc Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Tue, 19 Oct 2021 17:28:18 +0200 Subject: passt: Address gcc 11 warnings A mix of unchecked return values, a missing permission mask for open(2) with O_CREAT, and some false positives from -Wstringop-overflow and -Wmaybe-uninitialized. Reported-by: Martin Hauke Signed-off-by: Stefano Brivio --- passt.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'passt.c') diff --git a/passt.c b/passt.c index a5f9bf8..846ba7f 100644 --- a/passt.c +++ b/passt.c @@ -257,13 +257,16 @@ static void pid_file(struct ctx *c) { if (!*c->pid_file) return; - pid_fd = open(c->pid_file, O_CREAT | O_WRONLY); + pid_fd = open(c->pid_file, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); if (pid_fd < 0) return; n = snprintf(pid_buf, sizeof(pid_buf), "%i\n", getpid()); - write(pid_fd, pid_buf, n); + if (write(pid_fd, pid_buf, n) < 0) { + perror("PID file write"); + exit(EXIT_FAILURE); + } close(pid_fd); } @@ -365,8 +368,10 @@ int main(int argc, char **argv) else __setlogmask(LOG_UPTO(LOG_INFO)); - if (isatty(fileno(stdout)) && !c.foreground) - daemon(0, 0); + if (isatty(fileno(stdout)) && !c.foreground && daemon(0, 0)) { + perror("daemon"); + exit(EXIT_FAILURE); + } pid_file(&c); -- cgit v1.2.3