ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

commit cd1a3d56980cb6345acbed7ed218f7191e781081
parent 0fbd4280f8e8daa6dbf2d4fe6f7807dd43904b22
Author: sin <sin@2f30.org>
Date:   Wed, 20 Aug 2014 20:37:12 +0100

Rework parsecmdline()

Diffstat:
Mutil/proc.c | 11+++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/util/proc.c b/util/proc.c @@ -19,13 +19,16 @@ parsecmdline(pid_t pid, char *buf, size_t siz) char path[PATH_MAX]; ssize_t n, i; - snprintf(path, sizeof(path), "/proc/%d/cmdline", pid); + snprintf(path, sizeof(path), "/proc/%ld/cmdline", (long)pid); fd = open(path, O_RDONLY); if (fd < 0) return -1; - n = read(fd, buf, siz - 1); - if (n < 0) - eprintf("read %s:", path); + n = read(fd, buf, siz > 0 ? siz - 1 : 0); + if (n < 0) { + weprintf("read %s:", path); + close(fd); + return -1; + } if (!n) { close(fd); return -1;