some checks for /proc

This commit is contained in:
Doug MacEachern 2005-02-13 05:46:10 +00:00
parent 00580471d5
commit 2d375e1f3f
2 changed files with 16 additions and 0 deletions

View File

@ -118,6 +118,9 @@ int sigar_os_open(sigar_t **sigar)
int ncpu;
size_t len;
struct timeval boottime;
#ifndef DARWIN
struct stat sb;
#endif
len = sizeof(ncpu);
mib[0] = CTL_HW;
@ -139,6 +142,12 @@ int sigar_os_open(sigar_t **sigar)
(*sigar)->mach_port = mach_host_self();
#else
(*sigar)->kmem = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open");
if (stat("/proc/curproc", &sb) < 0) {
(*sigar)->proc_mounted = 0;
}
else {
(*sigar)->proc_mounted = 1;
}
#endif
get_koffsets(*sigar);
@ -170,6 +179,8 @@ char *sigar_os_error_string(int err)
switch (err) {
case SIGAR_EPERM_KMEM:
return "Failed to open /dev/kmem for reading";
case SIGAR_EPROC_NOENT:
return "/proc filesystem is not mounted";
default:
return NULL;
}
@ -688,6 +699,9 @@ int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
#ifdef DARWIN
return SIGAR_ENOTIMPL;
#else
if (!sigar->proc_mounted) {
return SIGAR_EPROC_NOENT;
}
return sigar_procfs_args_get(sigar, pid, procargs);
#endif
}

View File

@ -28,9 +28,11 @@ struct sigar_t {
kvm_t *kmem;
/* offsets for seeking on kmem */
unsigned long koffsets[KOFFSET_MAX];
int proc_mounted;
#endif
};
#define SIGAR_EPERM_KMEM (SIGAR_OS_START_ERROR+1)
#define SIGAR_EPROC_NOENT (SIGAR_OS_START_ERROR+2)
#endif /* SIGAR_OS_H */