aboutgitcodebugslistschat
path: root/passt.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-10-19 17:28:18 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-10-20 08:29:30 +0200
commit1a563a0cbd4926d0dfe9065a4fcd8771c5b292cc (patch)
tree13ee3b6da82e5eb53a89bb881ccf3a7092dab9fe /passt.c
parent087b5f4dbb9e3f767a8afbb6c1001c509965940b (diff)
downloadpasst-1a563a0cbd4926d0dfe9065a4fcd8771c5b292cc.tar
passt-1a563a0cbd4926d0dfe9065a4fcd8771c5b292cc.tar.gz
passt-1a563a0cbd4926d0dfe9065a4fcd8771c5b292cc.tar.bz2
passt-1a563a0cbd4926d0dfe9065a4fcd8771c5b292cc.tar.lz
passt-1a563a0cbd4926d0dfe9065a4fcd8771c5b292cc.tar.xz
passt-1a563a0cbd4926d0dfe9065a4fcd8771c5b292cc.tar.zst
passt-1a563a0cbd4926d0dfe9065a4fcd8771c5b292cc.zip
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 <mardnh@gmx.de> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'passt.c')
-rw-r--r--passt.c13
1 files changed, 9 insertions, 4 deletions
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);