diff options
author | Michael McConville <mmcco@mykolab.com> | 2016-01-02 22:05:20 -0500 |
---|---|---|
committer | Michael McConville <mmcco@mykolab.com> | 2016-01-02 22:05:20 -0500 |
commit | 918cfd54d6ea3794f412ab891acd40bb6e555127 (patch) | |
tree | 6b1757534d7f328659509a3fbed70510e0ccf8d0 /openbsd | |
parent | 3da36bbc61dbd27f717188a0a742bb637ca4f5bc (diff) |
Fall back to sysctl's command name, and a bugfix
This is what OpenBSD's top(1) does when the libkvm call fails, and it's
a good idea.
This commit also fixes process name construction. The space was being
written one character too far.
Diffstat (limited to 'openbsd')
-rw-r--r-- | openbsd/OpenBSDProcessList.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index cbb90c91..25f63349 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -130,28 +130,34 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in size_t cpsz, len = 0, n; int i; + /* + * We attempt to fall back to just the command name (argv[0]) if we + * fail to construct the full command at any point. + */ arg = kvm_getargv(kd, kproc, 500); if (arg == NULL) { - // the FreeBSD port uses ki_comm, but we don't have it - //return strndup(kproc->ki_comm); - if ((s = strdup("[zombie]")) == NULL) { - err(1, NULL); + if ((s = strdup(kproc->p_comm)) == NULL) { + err(1, NULL); } return s; } for (i = 0; arg[i] != NULL; i++) { len += strlen(arg[i]) + 1; } - if ((buf = s = malloc(len)) == NULL) - err(1, NULL); + if ((buf = s = malloc(len)) == NULL) { + if ((s = strdup(kproc->p_comm)) == NULL) { + err(1, NULL); + } + return s; + } for (i = 0; arg[i] != NULL; i++) { n = strlcpy(buf, arg[i], (s + len) - buf); buf += n; if (i == 0) { - *basenameEnd = n; + *basenameEnd = n; } - buf++; *buf = ' '; + buf++; } *(buf - 1) = '\0'; return s; |