]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsns.c: fix error return
authorYuriy M. Kaminskiy <yumkam@gmail.com>
Sat, 27 Feb 2016 16:14:44 +0000 (19:14 +0300)
committerKarel Zak <kzak@redhat.com>
Mon, 7 Mar 2016 14:11:06 +0000 (15:11 +0100)
If non-negative value returned, errno could be unset (especially 0).

Signed-off-by: Karel Zak <kzak@redhat.com>
lib/sysfs.c
sys-utils/lsns.c

index 53aba3af94b6d3ab9a4c1615a70ee03f37767e3b..9d761488090b6e391b7a54c12aad76becb63fe46 100644 (file)
@@ -464,7 +464,7 @@ int sysfs_write_u64(struct sysfs_cxt *cxt, const char *attr, uint64_t num)
 
        len = snprintf(buf, sizeof(buf), "%" PRIu64, num);
        if (len < 0 || (size_t) len + 1 > sizeof(buf))
-               rc = -errno;
+               rc = len < 0 ? -errno : -E2BIG;
        else
                rc = write_all(fd, buf, len);
 
index 71ae3f99e0bdf0cec93a720e138136035957eb80..83b07f5a8838301d35572bdfa14c1d394d7451b9 100644 (file)
@@ -255,7 +255,7 @@ static int read_process(struct lsns *ls, pid_t pid)
        }
        rc = fscanf(f, "%d %*s %c %d*[^\n]", &p->pid, &p->state, &p->ppid);
        if (rc != 3) {
-               rc = -errno;
+               rc = rc < 0 ? -errno : -EINVAL;
                goto done;
        }
        rc = 0;