freebsd proc_args using sysctl

This commit is contained in:
Doug MacEachern 2005-02-16 18:33:00 +00:00
parent 54b12212fa
commit 2b26862c45
1 changed files with 34 additions and 1 deletions

View File

@ -783,8 +783,41 @@ int sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid, int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_args_t *procargs) sigar_proc_args_t *procargs)
{ {
#ifdef DARWIN #if defined(DARWIN)
return SIGAR_ENOTIMPL; return SIGAR_ENOTIMPL;
#elif defined (__FreeBSD__) && (__FreeBSD_version >= 500013)
char buffer[8096], *ptr=buffer;
size_t len = sizeof(buffer);
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ARGS, 0 };
mib[3] = pid;
if (sysctl(mib, NMIB(mib), buffer, &len, NULL, 0) < 0) {
return errno;
}
sigar_proc_args_create(procargs);
if (len == 0) {
procargs->number = 0;
return SIGAR_OK;
}
buffer[len] = '\0';
while (*ptr) {
int alen = strlen(ptr)+1;
char *arg = malloc(alen);
SIGAR_PROC_ARGS_GROW(procargs);
memcpy(arg, ptr, alen);
procargs->data[procargs->number++] = arg;
ptr += alen;
}
return SIGAR_OK;
#else #else
return PROCFS_STATUS(sigar_procfs_args_get(sigar, pid, procargs)); return PROCFS_STATUS(sigar_procfs_args_get(sigar, pid, procargs));
#endif #endif