Implement proc_env for Darwin

This commit is contained in:
Doug MacEachern 2006-08-25 20:23:56 +00:00
parent a0a31eb6e3
commit 457212edcb
2 changed files with 61 additions and 1 deletions

View File

@ -1,3 +1,7 @@
2006-08-25 Doug MacEachern <dougm@hyperic.com>
* Implement proc_env for Darwin
2006-08-24 Doug MacEachern <dougm@hyperic.com> 2006-08-24 Doug MacEachern <dougm@hyperic.com>
* Sigar.getProc*(String) methods now convert PTQL queries * Sigar.getProc*(String) methods now convert PTQL queries

View File

@ -1046,7 +1046,63 @@ int sigar_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_env_t *procenv) sigar_proc_env_t *procenv)
{ {
#ifdef DARWIN #ifdef DARWIN
return SIGAR_ENOTIMPL; int status, count;
sigar_kern_proc_args_t kargs;
char *ptr, *end;
status = sigar_kern_proc_args_get(pid, &kargs);
if (status != SIGAR_OK) {
return status;
}
count = kargs.count;
ptr = kargs.ptr;
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 */
while (ptr < end) {
char *val = strchr(ptr, '=');
int klen, vlen, status;
char key[256]; /* XXX is there a max key size? */
if (val == NULL) {
/* not key=val format */
break;
}
klen = val - ptr;
SIGAR_SSTRCPY(key, ptr);
key[klen] = '\0';
++val;
vlen = strlen(val);
status = procenv->env_getter(procenv->data,
key, klen, val, vlen);
if (status != SIGAR_OK) {
/* not an error; just stop iterating */
break;
}
ptr += (klen + 1 + vlen + 1);
if (*ptr == '\0') {
break;
}
}
return SIGAR_OK;
#else #else
char **env; char **env;
struct kinfo_proc *pinfo; struct kinfo_proc *pinfo;