add/use kern_proc_args_skip_argv

This commit is contained in:
Doug MacEachern 2006-08-29 01:36:42 +00:00
parent 0af0a9d75a
commit 73aa5252e8
1 changed files with 29 additions and 11 deletions

View File

@ -972,6 +972,30 @@ static int sigar_kern_proc_args_get(sigar_pid_t pid,
return SIGAR_OK; return SIGAR_OK;
} }
static int kern_proc_args_skip_argv(sigar_kern_proc_args_t *kargs)
{
char *ptr = kargs->ptr;
char *end = kargs->end;
int count = kargs->count;
/* skip over argv */
while ((ptr < end) && (count-- > 0)) {
int alen = strlen(ptr)+1;
ptr += alen;
}
kargs->ptr = ptr;
kargs->end = end;
kargs->count = 0;
if (ptr >= end) {
return ENOENT;
}
return SIGAR_OK;
}
#endif #endif
int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid, int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
@ -1075,21 +1099,15 @@ int sigar_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
return status; return status;
} }
status = kern_proc_args_skip_argv(&kargs);
if (status != SIGAR_OK) {
return status;
}
count = kargs.count; count = kargs.count;
ptr = kargs.ptr; ptr = kargs.ptr;
end = kargs.end; end = kargs.end;
/* skip over argv */
while ((ptr < end) && (count-- > 0)) {
int alen = strlen(ptr)+1;
ptr += alen;
}
if (ptr >= end) {
return ENOENT;
}
/* into environ */ /* into environ */
while (ptr < end) { while (ptr < end) {
char *val = strchr(ptr, '='); char *val = strchr(ptr, '=');