lib/libutil/kinfo_*: style cleanup
- Use nitems(mib) instead of hardcoding mib's length - Sort sys/ #includes MFC after: 3 days
This commit is contained in:
parent
074a0dcceb
commit
7adf46f0c6
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=311714
@ -31,8 +31,8 @@
|
|||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/user.h>
|
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
#include <sys/user.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -75,14 +75,14 @@ kinfo_getallproc(int *cntp)
|
|||||||
mib[2] = KERN_PROC_PROC;
|
mib[2] = KERN_PROC_PROC;
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
if (sysctl(mib, 3, NULL, &len, NULL, 0) < 0)
|
if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) < 0)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
kipp = malloc(len);
|
kipp = malloc(len);
|
||||||
if (kipp == NULL)
|
if (kipp == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
if (sysctl(mib, 3, kipp, &len, NULL, 0) < 0)
|
if (sysctl(mib, nitems(mib), kipp, &len, NULL, 0) < 0)
|
||||||
goto bad;
|
goto bad;
|
||||||
if (len % sizeof(*kipp) != 0)
|
if (len % sizeof(*kipp) != 0)
|
||||||
goto bad;
|
goto bad;
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/user.h>
|
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
#include <sys/user.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -26,14 +26,14 @@ kinfo_getfile(pid_t pid, int *cntp)
|
|||||||
mib[2] = KERN_PROC_FILEDESC;
|
mib[2] = KERN_PROC_FILEDESC;
|
||||||
mib[3] = pid;
|
mib[3] = pid;
|
||||||
|
|
||||||
error = sysctl(mib, 4, NULL, &len, NULL, 0);
|
error = sysctl(mib, nitems(mib), NULL, &len, NULL, 0);
|
||||||
if (error)
|
if (error)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
len = len * 4 / 3;
|
len = len * 4 / 3;
|
||||||
buf = malloc(len);
|
buf = malloc(len);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
error = sysctl(mib, 4, buf, &len, NULL, 0);
|
error = sysctl(mib, nitems(mib), buf, &len, NULL, 0);
|
||||||
if (error) {
|
if (error) {
|
||||||
free(buf);
|
free(buf);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
@ -30,8 +30,8 @@
|
|||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/user.h>
|
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
#include <sys/user.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -49,14 +49,14 @@ kinfo_getproc(pid_t pid)
|
|||||||
mib[1] = KERN_PROC;
|
mib[1] = KERN_PROC;
|
||||||
mib[2] = KERN_PROC_PID;
|
mib[2] = KERN_PROC_PID;
|
||||||
mib[3] = pid;
|
mib[3] = pid;
|
||||||
if (sysctl(mib, 4, NULL, &len, NULL, 0) < 0)
|
if (sysctl(mib, nitems(mib), NULL, &len, NULL, 0) < 0)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
kipp = malloc(len);
|
kipp = malloc(len);
|
||||||
if (kipp == NULL)
|
if (kipp == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
if (sysctl(mib, 4, kipp, &len, NULL, 0) < 0)
|
if (sysctl(mib, nitems(mib), kipp, &len, NULL, 0) < 0)
|
||||||
goto bad;
|
goto bad;
|
||||||
if (len != sizeof(*kipp))
|
if (len != sizeof(*kipp))
|
||||||
goto bad;
|
goto bad;
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/user.h>
|
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
#include <sys/user.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -26,14 +26,14 @@ kinfo_getvmmap(pid_t pid, int *cntp)
|
|||||||
mib[2] = KERN_PROC_VMMAP;
|
mib[2] = KERN_PROC_VMMAP;
|
||||||
mib[3] = pid;
|
mib[3] = pid;
|
||||||
|
|
||||||
error = sysctl(mib, 4, NULL, &len, NULL, 0);
|
error = sysctl(mib, nitems(mib), NULL, &len, NULL, 0);
|
||||||
if (error)
|
if (error)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
len = len * 4 / 3;
|
len = len * 4 / 3;
|
||||||
buf = malloc(len);
|
buf = malloc(len);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
error = sysctl(mib, 4, buf, &len, NULL, 0);
|
error = sysctl(mib, nitems(mib), buf, &len, NULL, 0);
|
||||||
if (error) {
|
if (error) {
|
||||||
free(buf);
|
free(buf);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user