chiark / gitweb /
errno is positive
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 11 Apr 2013 22:57:42 +0000 (18:57 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 11 Apr 2013 23:13:18 +0000 (19:13 -0400)
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.

src/libsystemd-bus/bus-kernel.c
src/login/sd-login.c
src/readahead/sd-readahead.c
src/shared/hwclock.c
src/shared/install.c
src/shared/socket-util.c
src/shared/util.c
src/systemctl/systemctl.c

index e5e3536ad076aefd508c50e76a31e38b3638c28b..b83dfcbc27bca1b37ecde52840b3302437d7b872 100644 (file)
@@ -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;
index 7513f76cb3fc3397da3389dd81208abc3d14e12c..f433e3e80b15fc5b87f742d0f6a6627876a6dbf9 100644 (file)
@@ -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);
index 4a096eed427779c3b326c3bef08daa903d5dc419..675d82cdd18bf9c87dc64006c64ca77e2c5ffa77 100644 (file)
@@ -65,7 +65,7 @@ static int touch(const char *path) {
                 if (close(fd) >= 0)
                         break;
 
-                if (errno != -EINTR)
+                if (errno != EINTR)
                         return -errno;
         }
 
index 488c30e93f6c8ce04dfb2da451b4c60022b0c9c4..55b0fa8a0f1c855ade2f9ee26bbc141aaf1f6cf2 100644 (file)
@@ -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;
index 9e870392f232c0c620b429351793ba2c2e5deb28..b368b9f9ab1eae2fa952b458669b500f633ab2d1 100644 (file)
@@ -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;
index 53457886e27ea58cf2d87fe2d12bcef0567e1c42..4933fe08e2ae20c0c83bd94d0aa62fdf3d3a33b9 100644 (file)
@@ -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)
index 57943b64117f9afa5ac99f13599d46254e45f26b..5827f6c7a14dfa3afbebc0e0befd601d5f6ca277 100644 (file)
@@ -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;
index a95060550359d1f8cdeb67934a7b1bbe8bf6add5..1c7edd5a5833d153dca97f29e6174b4a253b91cd 100644 (file)
@@ -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;