version 1.86, 2016/05/11 08:11:27 |
version 1.87, 2016/07/28 21:45:00 |
|
|
get_proc_args(struct kinfo_proc *kp) |
get_proc_args(struct kinfo_proc *kp) |
{ |
{ |
static char **s; |
static char **s; |
size_t siz = 100; |
static size_t siz = 1023; |
int mib[4]; |
int mib[4]; |
|
|
for (;; siz *= 2) { |
if (!s && !(s = malloc(siz))) |
if ((s = realloc(s, siz)) == NULL) |
err(1, NULL); |
err(1, NULL); |
|
mib[0] = CTL_KERN; |
mib[0] = CTL_KERN; |
mib[1] = KERN_PROC_ARGS; |
mib[1] = KERN_PROC_ARGS; |
mib[2] = kp->p_pid; |
mib[2] = kp->p_pid; |
mib[3] = KERN_PROC_ARGV; |
mib[3] = KERN_PROC_ARGV; |
if (sysctl(mib, 4, s, &siz, NULL, 0) == 0) |
for (;;) { |
|
size_t space = siz; |
|
if (sysctl(mib, 4, s, &space, NULL, 0) == 0) |
break; |
break; |
if (errno != ENOMEM) |
if (errno != ENOMEM) |
return NULL; |
return NULL; |
|
siz *= 2; |
|
if ((s = realloc(s, siz)) == NULL) |
|
err(1, NULL); |
} |
} |
return s; |
return s; |
} |
} |