[hackers] [ubase] Rework parsecmdline() || sin

From: <git_AT_suckless.org>
Date: Wed, 20 Aug 2014 21:38:43 +0200

commit cd1a3d56980cb6345acbed7ed218f7191e781081
Author: sin <sin_AT_2f30.org>
Date: Wed Aug 20 20:37:12 2014 +0100

    Rework parsecmdline()

diff --git a/util/proc.c b/util/proc.c
index 09597b5..9c4b503 100644
--- a/util/proc.c
+++ b/util/proc.c
_AT_@ -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;
Received on Wed Aug 20 2014 - 21:38:43 CEST

This archive was generated by hypermail 2.3.0 : Wed Aug 20 2014 - 21:48:08 CEST