]> git.ipfire.org Git - thirdparty/systemd.git/commit
basic/log: force log_*_errno() to return negative
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 14 Apr 2021 10:05:47 +0000 (06:05 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 14 Apr 2021 14:19:54 +0000 (16:19 +0200)
commitcbe97b9c92728e96c9987314a7e1e05bbdffda16
tree7d514b60e098d2b27e38f78aefe4ae82b1327597
parent111a3aae71fa019710216cc5b7aa95b7c8db0937
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.
src/basic/log.h