diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2017-02-19 08:31:05 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2017-02-19 08:31:05 +0000 |
commit | 55e76edd3cc9bfa8aeac60b17d3344031097b1b6 (patch) | |
tree | 02403e27dad1e2015de93dda87e49e11c3f853b1 /osdep-netbsd.c | |
parent | 203d604bf7a439648707517c7dc4770fe7f4d8a3 (diff) | |
download | rtmux-55e76edd3cc9bfa8aeac60b17d3344031097b1b6.tar.gz rtmux-55e76edd3cc9bfa8aeac60b17d3344031097b1b6.tar.bz2 rtmux-55e76edd3cc9bfa8aeac60b17d3344031097b1b6.zip |
Improve NetBSD KERN_PROC2 bit, mostly from Kamil Rytarowski.
Diffstat (limited to 'osdep-netbsd.c')
-rw-r--r-- | osdep-netbsd.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/osdep-netbsd.c b/osdep-netbsd.c index d8aa41b5..823eeebf 100644 --- a/osdep-netbsd.c +++ b/osdep-netbsd.c @@ -80,30 +80,32 @@ osdep_get_name(int fd, __unused char *tty) return (NULL); buf = NULL; - len = sizeof(bestp); + len = sizeof bestp; + mib[0] = CTL_KERN; mib[1] = KERN_PROC2; mib[2] = KERN_PROC_PGRP; - mib[4] = sizeof (*buf); - mib[5] = 0; + mib[4] = sizeof *buf; retry: + mib[5] = 0; + if (sysctl(mib, __arraycount(mib), NULL, &len, NULL, 0) == -1) return (NULL); - if ((newbuf = realloc(buf, len * sizeof (*buf))) == NULL) + if ((newbuf = realloc(buf, len)) == NULL) goto error; buf = newbuf; - mib[5] = len / sizeof(*buf); + mib[5] = len / (sizeof *buf); if (sysctl(mib, __arraycount(mib), buf, &len, NULL, 0) == -1) { if (errno == ENOMEM) - goto retry; /* possible infinite loop? */ + goto retry; goto error; } bestp = NULL; - for (i = 0; i < len / sizeof (*buf); i++) { + for (i = 0; i < len / (sizeof *buf); i++) { if (buf[i].p_tdev != sb.st_rdev) continue; if (bestp == NULL) |