Rework parsecmdline()
This commit is contained in:
parent
0fbd4280f8
commit
cd1a3d5698
11
util/proc.c
11
util/proc.c
@ -19,13 +19,16 @@ parsecmdline(pid_t pid, char *buf, size_t siz)
|
|||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
ssize_t n, i;
|
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);
|
fd = open(path, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
n = read(fd, buf, siz - 1);
|
n = read(fd, buf, siz > 0 ? siz - 1 : 0);
|
||||||
if (n < 0)
|
if (n < 0) {
|
||||||
eprintf("read %s:", path);
|
weprintf("read %s:", path);
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (!n) {
|
if (!n) {
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user