From cb51ee7a6e537da5706b4eb4a6d673ebe9654ceb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 16 Feb 2018 07:00:22 +0100 Subject: [PATCH] Add some handling to remaining unlinkat calls Coverity now started warning about this ("Calling unlinkat without checking return value (as is done elsewhere 12 out of 15 times).", and it is right: most of the time we should at list print a log message so people can figure out something is wrong when this happens. v2: - use warning level in journald too (this is unlikely to happen ever, so it should be safe to something that is visible by default). --- src/journal/journald-stream.c | 4 +++- src/login/logind.c | 4 +++- src/udev/udev-watch.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 671ada718c2..bb7330f3db9 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -778,7 +778,9 @@ int server_restore_streams(Server *s, FDSet *fds) { if (!found) { /* No file descriptor? Then let's delete the state file */ log_debug("Cannot restore stream file %s", de->d_name); - unlinkat(dirfd(d), de->d_name, 0); + if (unlinkat(dirfd(d), de->d_name, 0) < 0) + log_warning("Failed to remove /run/systemd/journal/streams/%s: %m", + de->d_name); continue; } diff --git a/src/login/logind.c b/src/login/logind.c index 0a869ba447d..3fa7d2fed63 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -323,7 +323,9 @@ static int manager_enumerate_seats(Manager *m) { s = hashmap_get(m->seats, de->d_name); if (!s) { - unlinkat(dirfd(d), de->d_name, 0); + if (unlinkat(dirfd(d), de->d_name, 0) < 0) + log_warning("Failed to remove /run/systemd/seats/%s: %m", + de->d_name); continue; } diff --git a/src/udev/udev-watch.c b/src/udev/udev-watch.c index 351cb6345a4..61179ce03db 100644 --- a/src/udev/udev-watch.c +++ b/src/udev/udev-watch.c @@ -79,7 +79,7 @@ void udev_watch_restore(struct udev *udev) { udev_watch_begin(udev, dev); udev_device_unref(dev); unlink: - unlinkat(dirfd(dir), ent->d_name, 0); + (void) unlinkat(dirfd(dir), ent->d_name, 0); } closedir(dir); -- 2.47.3