]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: check if errno is greater then zero
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 11 Jan 2016 17:47:14 +0000 (12:47 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 13 Jan 2016 20:09:55 +0000 (15:09 -0500)
gcc is confused by the common idiom of
  return errno ? -errno : -ESOMETHING
and thinks a positive value may be returned. Replace this condition
with errno > 0 to help gcc and avoid many spurious warnings. I filed
a gcc rfe a long time ago, but it hard to say if it will ever be
implemented [1].

Both conventions were used in the codebase, this change makes things
more consistent. This is a follow up to bcb161b0230f.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61846

14 files changed:
src/basic/cgroup-util.c
src/basic/fileio.c
src/basic/glob-util.c
src/basic/in-addr-util.c
src/basic/terminal-util.c
src/core/execute.c
src/firstboot/firstboot.c
src/getty-generator/getty-generator.c
src/import/aufs-util.c
src/locale/localed.c
src/login/logind-core.c
src/login/logind-dbus.c
src/sysusers/sysusers.c
src/udev/udev-builtin-blkid.c

index 3945d37c8d2884df654eff20980c4baca12b5ad2..18d23bc57e39ae2241609e3b6aa68382f871a379 100644 (file)
@@ -93,7 +93,7 @@ int cg_read_pid(FILE *f, pid_t *_pid) {
                 if (feof(f))
                         return 0;
 
-                return errno ? -errno : -EIO;
+                return errno > 0 ? -errno : -EIO;
         }
 
         if (ul <= 0)
index 3a237252b5ffe2e02663a4d3fc476f4bd29e9eaa..5ed5460904b4207d960ac4b11d7e94eca6997a99 100644 (file)
@@ -165,7 +165,7 @@ int read_one_line_file(const char *fn, char **line) {
         if (!fgets(t, sizeof(t), f)) {
 
                 if (ferror(f))
-                        return errno ? -errno : -EIO;
+                        return errno > 0 ? -errno : -EIO;
 
                 t[0] = 0;
         }
@@ -1064,7 +1064,7 @@ int fflush_and_check(FILE *f) {
         fflush(f);
 
         if (ferror(f))
-                return errno ? -errno : -EIO;
+                return errno > 0 ? -errno : -EIO;
 
         return 0;
 }
index a0be0efd407e7e5f95485f16c1a45cdd6886ed96..811ab6ec36d204c2145a5c08719debb94fd4d490 100644 (file)
@@ -40,7 +40,7 @@ int glob_exists(const char *path) {
         if (k == GLOB_NOSPACE)
                 return -ENOMEM;
         if (k != 0)
-                return errno ? -errno : -EIO;
+                return errno > 0 ? -errno : -EIO;
 
         return !strv_isempty(g.gl_pathv);
 }
@@ -58,7 +58,7 @@ int glob_extend(char ***strv, const char *path) {
         if (k == GLOB_NOSPACE)
                 return -ENOMEM;
         if (k != 0)
-                return errno ? -errno : -EIO;
+                return errno > 0 ? -errno : -EIO;
         if (strv_isempty(g.gl_pathv))
                 return -ENOENT;
 
index 5143dddf8f4e7db5c6b98a8d904ee19c5cd6dbaf..8609ffb3c99998ac4be1a1420e9ef35312e2057e 100644 (file)
@@ -219,7 +219,7 @@ int in_addr_to_string(int family, const union in_addr_union *u, char **ret) {
         errno = 0;
         if (!inet_ntop(family, u, x, l)) {
                 free(x);
-                return errno ? -errno : -EINVAL;
+                return errno > 0 ? -errno : -EINVAL;
         }
 
         *ret = x;
@@ -236,7 +236,7 @@ int in_addr_from_string(int family, const char *s, union in_addr_union *ret) {
 
         errno = 0;
         if (inet_pton(family, s, ret) <= 0)
-                return errno ? -errno : -EINVAL;
+                return errno > 0 ? -errno : -EINVAL;
 
         return 0;
 }
index a39764472b89f8e3fe9c42ed02a0dc72f4e64c3e..7c9de72bb748fb0413f783b8d3cd9dbc53913263 100644 (file)
@@ -128,7 +128,7 @@ int read_one_char(FILE *f, char *ret, usec_t t, bool *need_nl) {
 
         errno = 0;
         if (!fgets(line, sizeof(line), f))
-                return errno ? -errno : -EIO;
+                return errno > 0 ? -errno : -EIO;
 
         truncate_nl(line);
 
@@ -212,7 +212,7 @@ int ask_string(char **ret, const char *text, ...) {
 
                 errno = 0;
                 if (!fgets(line, sizeof(line), stdin))
-                        return errno ? -errno : -EIO;
+                        return errno > 0 ? -errno : -EIO;
 
                 if (!endswith(line, "\n"))
                         putchar('\n');
index ac91568b6349d77a7a7a8ee9b38bae797d8b73c8..90d37feb01ed2bb420580ab5398a4faf89d6e2e3 100644 (file)
@@ -2319,7 +2319,7 @@ int exec_context_load_environment(Unit *unit, const ExecContext *c, char ***l) {
                                 continue;
 
                         strv_free(r);
-                        return errno ? -errno : -EINVAL;
+                        return errno > 0 ? -errno : -EINVAL;
                 }
                 count = pglob.gl_pathc;
                 if (count == 0) {
index 469ee7af681d30490ca4b6515b4708f91aa3e8f7..cc5e9741fe990df18287fe616408ded3cfc9cc89 100644 (file)
@@ -502,7 +502,7 @@ static int write_root_shadow(const char *path, const struct spwd *p) {
 
         errno = 0;
         if (putspent(p, f) != 0)
-                return errno ? -errno : -EIO;
+                return errno > 0 ? -errno : -EIO;
 
         return fflush_and_check(f);
 }
index 03df7365b56d2683a0cf8cef5a23b10b11929c7d..bddc0c441a4b461dd05ab7578cb76bdbaa3945ae 100644 (file)
@@ -112,7 +112,7 @@ static int verify_tty(const char *name) {
 
         errno = 0;
         if (isatty(fd) <= 0)
-                return errno ? -errno : -EIO;
+                return errno > 0 ? -errno : -EIO;
 
         return 0;
 }
index 82f519958cc83a9cacd56d7735ef21b94f537d63..b44dbb14ea43bc23c0c38d18a40981f1ba4d3dd1 100644 (file)
@@ -69,7 +69,7 @@ int aufs_resolve(const char *path) {
         errno = 0;
         r = nftw(path, nftw_cb, 64, FTW_MOUNT|FTW_PHYS|FTW_ACTIONRETVAL);
         if (r == FTW_STOP)
-                return errno ? -errno : -EIO;
+                return errno > 0 ? -errno : -EIO;
 
         return 0;
 }
index 5ca41331bdb487c868b9c9b4758d452a772bf6b0..8ab845eb803cd41d16bb26abb9a99809286acaf9 100644 (file)
@@ -539,7 +539,7 @@ static int read_next_mapping(const char* filename,
                 if (!fgets(line, sizeof(line), f)) {
 
                         if (ferror(f))
-                                return errno ? -errno : -EIO;
+                                return errno > 0 ? -errno : -EIO;
 
                         return 0;
                 }
index d51330fb85a227c1dbaa36a05c95a353a89ec953..2e14aa2d951846e33326c7ef0a1195a07b1b82e6 100644 (file)
@@ -139,7 +139,7 @@ int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user) {
         errno = 0;
         p = getpwuid(uid);
         if (!p)
-                return errno ? -errno : -ENOENT;
+                return errno > 0 ? -errno : -ENOENT;
 
         return manager_add_user(m, uid, p->pw_gid, p->pw_name, _user);
 }
index 4631f5fc90301dcbe04b7be89fcd8fb21de51107..81e40082a71a2c496413caad83ba95a0f2b5ce92 100644 (file)
@@ -1111,7 +1111,7 @@ static int method_set_user_linger(sd_bus_message *message, void *userdata, sd_bu
         errno = 0;
         pw = getpwuid(uid);
         if (!pw)
-                return errno ? -errno : -ENOENT;
+                return errno > 0 ? -errno : -ENOENT;
 
         r = bus_verify_polkit_async(
                         message,
index 675f94906b2dd89eae7e22ae82ada54ff972fe00..a7e8187f4f65169159cc4a4461a9019ccf957db6 100644 (file)
@@ -280,7 +280,7 @@ static int putgrent_with_members(const struct group *gr, FILE *group) {
 
                         errno = 0;
                         if (putgrent(&t, group) != 0)
-                                return errno ? -errno : -EIO;
+                                return errno > 0 ? -errno : -EIO;
 
                         return 1;
                 }
@@ -288,7 +288,7 @@ static int putgrent_with_members(const struct group *gr, FILE *group) {
 
         errno = 0;
         if (putgrent(gr, group) != 0)
-                return errno ? -errno : -EIO;
+                return errno > 0 ? -errno : -EIO;
 
         return 0;
 }
@@ -330,7 +330,7 @@ static int putsgent_with_members(const struct sgrp *sg, FILE *gshadow) {
 
                         errno = 0;
                         if (putsgent(&t, gshadow) != 0)
-                                return errno ? -errno : -EIO;
+                                return errno > 0 ? -errno : -EIO;
 
                         return 1;
                 }
@@ -338,7 +338,7 @@ static int putsgent_with_members(const struct sgrp *sg, FILE *gshadow) {
 
         errno = 0;
         if (putsgent(sg, gshadow) != 0)
-                return errno ? -errno : -EIO;
+                return errno > 0 ? -errno : -EIO;
 
         return 0;
 }
index 0b1ae706e70607a39f7c77a7c29d9f49f558b8d4..018b4dc5961b3f01f3941ec8330e435b900b6a08 100644 (file)
@@ -124,7 +124,7 @@ static int find_gpt_root(struct udev_device *dev, blkid_probe pr, bool test) {
         errno = 0;
         pl = blkid_probe_get_partitions(pr);
         if (!pl)
-                return errno ? -errno : -ENOMEM;
+                return errno > 0 ? -errno : -ENOMEM;
 
         nvals = blkid_partlist_numof_partitions(pl);
         for (i = 0; i < nvals; i++) {