From: Zbigniew Jędrzejewski-Szmek Date: Thu, 11 Apr 2013 22:57:42 +0000 (-0400) Subject: errno is positive X-Git-Tag: v202~140 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fsystemd.git;a=commitdiff_plain;h=bcb161b0230fdd1faf9176f95fee76a7db6afd59 errno is positive Make sure we compare errno against positive error codes. The ones in hwclock.c and install.c can have an impact, the rest are unlikely to be hit or in code that isn't widely used. Also check that errno > 0, to help gcc know that we are returning a negative error code. --- diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c index e5e3536ad07..b83dfcbc27b 100644 --- a/src/libsystemd-bus/bus-kernel.c +++ b/src/libsystemd-bus/bus-kernel.c @@ -339,7 +339,7 @@ int bus_kernel_read_message(sd_bus *bus, sd_bus_message **m) { if (errno == EAGAIN) return 0; - if (errno != -EMSGSIZE) + if (errno != EMSGSIZE) return -errno; sz *= 2; diff --git a/src/login/sd-login.c b/src/login/sd-login.c index 7513f76cb3f..f433e3e80b1 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -730,7 +730,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) { fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC); if (fd < 0) - return errno; + return -errno; if (!category || streq(category, "seat")) { k = inotify_add_watch(fd, "/run/systemd/seats/", IN_MOVED_TO|IN_DELETE); diff --git a/src/readahead/sd-readahead.c b/src/readahead/sd-readahead.c index 4a096eed427..675d82cdd18 100644 --- a/src/readahead/sd-readahead.c +++ b/src/readahead/sd-readahead.c @@ -65,7 +65,7 @@ static int touch(const char *path) { if (close(fd) >= 0) break; - if (errno != -EINTR) + if (errno != EINTR) return -errno; } diff --git a/src/shared/hwclock.c b/src/shared/hwclock.c index 488c30e93f6..55b0fa8a0f1 100644 --- a/src/shared/hwclock.c +++ b/src/shared/hwclock.c @@ -190,7 +190,7 @@ int hwclock_is_localtime(void) { truncate_nl(line); local = streq(line, "LOCAL"); - } else if (errno != -ENOENT) + } else if (errno != ENOENT) return -errno; return local; diff --git a/src/shared/install.c b/src/shared/install.c index 9e870392f23..b368b9f9ab1 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1637,7 +1637,7 @@ UnitFileState unit_file_get_state( return state; r = unit_file_can_install(&paths, root_dir, path, true); - if (r < 0 && errno != -ENOENT) + if (r < 0 && errno != ENOENT) return r; else if (r > 0) return UNIT_FILE_DISABLED; diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c index 53457886e27..4933fe08e2a 100644 --- a/src/shared/socket-util.c +++ b/src/shared/socket-util.c @@ -204,7 +204,7 @@ int socket_address_parse_netlink(SocketAddress *a, const char *s) { errno = 0; if (sscanf(s, "%ms %u", &sfamily, &group) < 1) - return errno ? -errno : -EINVAL; + return errno > 0 ? -errno : -EINVAL; family = netlink_family_from_string(sfamily); if (family < 0) diff --git a/src/shared/util.c b/src/shared/util.c index 57943b64117..5827f6c7a14 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -5259,7 +5259,7 @@ int get_home_dir(char **_h) { errno = 0; p = getpwuid(u); if (!p) - return errno ? -errno : -ESRCH; + return errno > 0 ? -errno : -ESRCH; if (!path_is_absolute(p->pw_dir)) return -EINVAL; diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index a9506055035..1c7edd5a583 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -5260,7 +5260,7 @@ static int talk_initctl(void) { r = loop_write(fd, &request, sizeof(request), false) != sizeof(request); if (r) { log_error("Failed to write to "INIT_FIFO": %m"); - return errno ? -errno : -EIO; + return errno > 0 ? -errno : -EIO; } return 1;