Add sigar_proc_list_t to sigar_t for internal re-use

This commit is contained in:
Doug MacEachern 2007-12-21 22:42:31 +00:00
parent 9ff8308a35
commit 71635f2c1c
2 changed files with 21 additions and 1 deletions

View File

@ -63,6 +63,7 @@
char *ifconf_buf; \ char *ifconf_buf; \
int ifconf_len; \ int ifconf_len; \
char *self_path; \ char *self_path; \
sigar_proc_list_t *pids; \
sigar_cache_t *fsdev; \ sigar_cache_t *fsdev; \
sigar_cache_t *proc_cpu; \ sigar_cache_t *proc_cpu; \
sigar_cache_t *net_listen; \ sigar_cache_t *net_listen; \

View File

@ -51,6 +51,7 @@ SIGAR_DECLARE(int) sigar_open(sigar_t **sigar)
(*sigar)->ptql_re_data = NULL; (*sigar)->ptql_re_data = NULL;
(*sigar)->self_path = NULL; (*sigar)->self_path = NULL;
(*sigar)->fsdev = NULL; (*sigar)->fsdev = NULL;
(*sigar)->pids = NULL;
(*sigar)->proc_cpu = NULL; (*sigar)->proc_cpu = NULL;
(*sigar)->net_listen = NULL; (*sigar)->net_listen = NULL;
(*sigar)->net_services_tcp = NULL; (*sigar)->net_services_tcp = NULL;
@ -68,6 +69,10 @@ SIGAR_DECLARE(int) sigar_close(sigar_t *sigar)
if (sigar->self_path) { if (sigar->self_path) {
free(sigar->self_path); free(sigar->self_path);
} }
if (sigar->pids) {
sigar_proc_list_destroy(sigar, sigar->pids);
free(sigar->pids);
}
if (sigar->fsdev) { if (sigar->fsdev) {
sigar_cache_destroy(sigar->fsdev); sigar_cache_destroy(sigar->fsdev);
} }
@ -304,7 +309,21 @@ SIGAR_DECLARE(int) sigar_proc_list_destroy(sigar_t *sigar,
SIGAR_DECLARE(int) sigar_proc_list_get(sigar_t *sigar, SIGAR_DECLARE(int) sigar_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist) sigar_proc_list_t *proclist)
{ {
sigar_proc_list_create(proclist); if (proclist == NULL) {
/* internal re-use */
if (sigar->pids == NULL) {
sigar->pids = malloc(sizeof(*sigar->pids));
sigar_proc_list_create(sigar->pids);
}
else {
sigar->pids->number = 0;
}
proclist = sigar->pids;
}
else {
sigar_proc_list_create(proclist);
}
return sigar_os_proc_list_get(sigar, proclist); return sigar_os_proc_list_get(sigar, proclist);
} }