keep /dev/mem fd open

This commit is contained in:
Doug MacEachern 2005-02-23 17:29:10 +00:00
parent 3cd8cf7638
commit 37d68c8180
2 changed files with 13 additions and 7 deletions

View File

@ -120,6 +120,7 @@ int sigar_os_open(sigar_t **sigar)
(*sigar)->getvminfo = vminfo; (*sigar)->getvminfo = vminfo;
(*sigar)->getprocfd = NULL; /*XXX*/ (*sigar)->getprocfd = NULL; /*XXX*/
(*sigar)->kmem = kmem; (*sigar)->kmem = kmem;
(*sigar)->dmem = -1;
(*sigar)->pagesize = 0; (*sigar)->pagesize = 0;
(*sigar)->boot_time = 0; (*sigar)->boot_time = 0;
(*sigar)->last_pid = -1; (*sigar)->last_pid = -1;
@ -166,6 +167,9 @@ int sigar_os_close(sigar_t *sigar)
if (sigar->kmem > 0) { if (sigar->kmem > 0) {
close(sigar->kmem); close(sigar->kmem);
} }
if (sigar->dmem > 0) {
close(sigar->dmem);
}
if (sigar->pinfo) { if (sigar->pinfo) {
free(sigar->pinfo); free(sigar->pinfo);
} }
@ -1515,22 +1519,26 @@ static int get_disk_metrics(sigar_t *sigar,
sigar_file_system_usage_t *fsusage, sigar_file_system_usage_t *fsusage,
aix_diskio_t *diskio) aix_diskio_t *diskio)
{ {
int fd, i; int i, cnt, fd;
int cnt;
struct iostat iostat; struct iostat iostat;
struct dkstat dkstat, *dp; struct dkstat dkstat, *dp;
struct nlist nl[] = { struct nlist nl[] = {
{ "iostat" }, { "iostat" },
}; };
if ((fd = open("/dev/mem", O_RDONLY)) <= 0) { if (sigar->dmem == -1) {
return errno; if ((sigar->dmem = open("/dev/mem", O_RDONLY)) <= 0) {
return errno;
}
} }
fd = sigar->dmem;
if (diskio->addr != -1) { if (diskio->addr != -1) {
int status; int status;
lseek(fd, diskio->addr, SEEK_SET); lseek(fd, diskio->addr, SEEK_SET);
read(fd, &dkstat, sizeof(dkstat)); read(fd, &dkstat, sizeof(dkstat));
if (strEQ(diskio->name, dkstat.diskname)) { if (strEQ(diskio->name, dkstat.diskname)) {
fsusage->disk_reads = dkstat.dk_rblks; fsusage->disk_reads = dkstat.dk_rblks;
fsusage->disk_writes = dkstat.dk_wblks; fsusage->disk_writes = dkstat.dk_wblks;
@ -1539,14 +1547,12 @@ static int get_disk_metrics(sigar_t *sigar,
else { else {
status = ENOENT; status = ENOENT;
} }
close(fd);
return status; return status;
} }
i = knlist(nl, 1, sizeof(struct nlist)); i = knlist(nl, 1, sizeof(struct nlist));
if (i == -1) { if (i == -1) {
close(fd);
return errno; return errno;
} }
@ -1572,7 +1578,6 @@ static int get_disk_metrics(sigar_t *sigar,
} }
} }
close(fd);
return SIGAR_OK; return SIGAR_OK;
} }

View File

@ -44,6 +44,7 @@ typedef int (*thread_rusage_func_t)(struct rusage *, int);
struct sigar_t { struct sigar_t {
SIGAR_T_BASE; SIGAR_T_BASE;
int kmem; int kmem;
int dmem;
/* offsets for seeking on kmem */ /* offsets for seeking on kmem */
long koffsets[KOFFSET_MAX]; long koffsets[KOFFSET_MAX];
vminfo_func_t getvminfo; vminfo_func_t getvminfo;