[SIGAR-101] dont try using /usr/ucb/ps unless installed

This commit is contained in:
Doug MacEachern 2008-05-03 15:04:18 +00:00
parent 57bc553dbf
commit 2423a9d47c
1 changed files with 9 additions and 2 deletions

View File

@ -34,6 +34,7 @@
#include <dirent.h> #include <dirent.h>
#define PROC_ERRNO ((errno == ENOENT) ? ESRCH : errno) #define PROC_ERRNO ((errno == ENOENT) ? ESRCH : errno)
#define SIGAR_USR_UCB_PS "/usr/ucb/ps"
int sigar_os_open(sigar_t **sig) int sigar_os_open(sigar_t **sig)
{ {
@ -64,7 +65,13 @@ int sigar_os_open(sigar_t **sig)
sigar->use_ucb_ps = strEQ(ptr, "true"); sigar->use_ucb_ps = strEQ(ptr, "true");
} }
else { else {
sigar->use_ucb_ps = 1; struct stat sb;
if (stat(SIGAR_USR_UCB_PS, &sb) < 0) {
sigar->use_ucb_ps = 0;
}
else {
sigar->use_ucb_ps = 1;
}
} }
sigar->pagesize = 0; sigar->pagesize = 0;
@ -809,7 +816,7 @@ static int ucb_ps_args_get(sigar_t *sigar, sigar_pid_t pid,
} }
else { else {
snprintf(buffer, sizeof(buffer), snprintf(buffer, sizeof(buffer),
"/usr/ucb/ps -ww %ld", (long)pid); SIGAR_USR_UCB_PS " -ww %ld", (long)pid);
if (!(fp = popen(buffer, "r"))) { if (!(fp = popen(buffer, "r"))) {
return errno; return errno;