From: Zbigniew Jędrzejewski-Szmek Date: Wed, 14 Apr 2021 10:05:47 +0000 (-0400) Subject: basic/log: force log_*_errno() to return negative X-Git-Tag: v249-rc1~407^2~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cbe97b9c92728e96c9987314a7e1e05bbdffda16;p=thirdparty%2Fsystemd.git basic/log: force log_*_errno() to return negative This silences some warnigns where gcc thinks that some variables are unitialized. One particular case: ../src/journal/journald-server.c: In function 'ache_space_refresh': ../src/journal/journald-server.c:136:28: error: 'vfs_avail' may be used uninitialized in this function [-Werror=maybe-uninitialized] 136 | uint64_t vfs_used, vfs_avail, avail; | ^~~~~~~~~ ../src/journal/journald-server.c:136:18: error: 'vfs_used' may be used uninitialized in this function [-Werror=maybe-uninitialized] 136 | uint64_t vfs_used, vfs_avail, avail; | ^~~~~~~~ cc1: all warnings being treated as errors which is caused by d = opendir(path); if (!d) return log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR, errno, "Failed to open %s: %m", path); if (fstatvfs(dirfd(d), &ss) < 0) return log_error_errno(errno, "Failed to fstatvfs(%s): %m", path); For some reason on aarch64 gcc thinks we might return non-negative here. In principle errno must be set in both cases, but it's hard to say for certain. So let's make sure that our code flow is correct, even if somebody forgot to set the global variable somewhere. --- diff --git a/src/basic/log.h b/src/basic/log.h index b3d32abfc84..4b621097d45 100644 --- a/src/basic/log.h +++ b/src/basic/log.h @@ -191,9 +191,10 @@ void log_assert_failed_return( #define log_full_errno(level, error, ...) \ ({ \ int _level = (level), _e = (error); \ - (log_get_max_level() >= LOG_PRI(_level)) \ + _e = (log_get_max_level() >= LOG_PRI(_level)) \ ? log_internal(_level, _e, PROJECT_FILE, __LINE__, __func__, __VA_ARGS__) \ : -ERRNO_VALUE(_e); \ + _e < 0 ? _e : -EIO; \ }) #define log_full(level, ...) (void) log_full_errno((level), 0, __VA_ARGS__)