From ad433cf37515976dd784a5703b85e7b930587ff3 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 22 Apr 2007 03:54:04 +0000 Subject: [PATCH] make sigar_proc_list_get a wrapper --- include/sigar_private.h | 3 ++- src/os/aix/aix_sigar.c | 6 ++---- src/os/darwin/darwin_sigar.c | 7 ++----- src/os/hpux/hpux_sigar.c | 6 ++---- src/os/linux/linux_sigar.c | 6 ++---- src/os/osf1/osf1_sigar.c | 6 ++---- src/os/solaris/solaris_sigar.c | 4 ++-- src/os/win32/win32_sigar.c | 14 +++++--------- src/sigar.c | 9 ++++++++- src/sigar_ptql.c | 4 +--- src/sigar_util.c | 2 -- 11 files changed, 28 insertions(+), 39 deletions(-) diff --git a/include/sigar_private.h b/include/sigar_private.h index 8c21abbb..09c9b6d5 100644 --- a/include/sigar_private.h +++ b/include/sigar_private.h @@ -164,7 +164,8 @@ int sigar_sys_info_get_uname(sigar_sys_info_t *sysinfo); int sigar_os_sys_info_get(sigar_t *sigar, sigar_sys_info_t *sysinfo); -int sigar_proc_list_create(sigar_proc_list_t *proclist); +int sigar_os_proc_list_get(sigar_t *sigar, + sigar_proc_list_t *proclist); int sigar_proc_list_grow(sigar_proc_list_t *proclist); diff --git a/src/os/aix/aix_sigar.c b/src/os/aix/aix_sigar.c index a241c451..d54d8106 100644 --- a/src/os/aix/aix_sigar.c +++ b/src/os/aix/aix_sigar.c @@ -962,14 +962,12 @@ int sigar_loadavg_get(sigar_t *sigar, return SIGAR_OK; } -int sigar_proc_list_get(sigar_t *sigar, - sigar_proc_list_t *proclist) +int sigar_os_proc_list_get(sigar_t *sigar, + sigar_proc_list_t *proclist) { pid_t pid = 0; struct procsinfo info; - sigar_proc_list_create(proclist); - for (;;) { int num = getprocs(&info, sizeof(info), NULL, 0, &pid, 1); diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 32401710..cf41fb03 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -613,8 +613,8 @@ int sigar_loadavg_get(sigar_t *sigar, #define KERN_PROC_PROC KERN_PROC_ALL #endif -int sigar_proc_list_get(sigar_t *sigar, - sigar_proc_list_t *proclist) +int sigar_os_proc_list_get(sigar_t *sigar, + sigar_proc_list_t *proclist) { #if defined(DARWIN) || defined(SIGAR_FREEBSD5) int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PROC, 0 }; @@ -634,7 +634,6 @@ int sigar_proc_list_get(sigar_t *sigar, } num = len/sizeof(*proc); - sigar_proc_list_create(proclist); for (i=0; ikmem, KERN_PROC_PROC, 0, &num); - - sigar_proc_list_create(proclist); for (i=0; i 0) { diff --git a/src/os/linux/linux_sigar.c b/src/os/linux/linux_sigar.c index 148cbe9f..97ba3db2 100644 --- a/src/os/linux/linux_sigar.c +++ b/src/os/linux/linux_sigar.c @@ -618,8 +618,8 @@ static SIGAR_INLINE int proc_isthread(sigar_t *sigar, char *pidstr, int len) return 1; } -int sigar_proc_list_get(sigar_t *sigar, - sigar_proc_list_t *proclist) +int sigar_os_proc_list_get(sigar_t *sigar, + sigar_proc_list_t *proclist) { DIR *dirp = opendir(PROCP_FS_ROOT); struct dirent *ent, dbuf; @@ -632,8 +632,6 @@ int sigar_proc_list_get(sigar_t *sigar, sigar->proc_signal_offset = get_proc_signal_offset(); } - sigar_proc_list_create(proclist); - while (readdir_r(dirp, &dbuf, &ent) == 0) { if (!ent) { break; diff --git a/src/os/osf1/osf1_sigar.c b/src/os/osf1/osf1_sigar.c index cdc8b94d..caa09dc2 100644 --- a/src/os/osf1/osf1_sigar.c +++ b/src/os/osf1/osf1_sigar.c @@ -165,8 +165,8 @@ int sigar_loadavg_get(sigar_t *sigar, #define PROC_ELTS 16 -int sigar_proc_list_get(sigar_t *sigar, - sigar_proc_list_t *proclist) +int sigar_os_proc_list_get(sigar_t *sigar, + sigar_proc_list_t *proclist) { struct tbl_procinfo procinfo[PROC_ELTS]; int offset; @@ -176,8 +176,6 @@ int sigar_proc_list_get(sigar_t *sigar, sigar->nproc = table(TBL_PROCINFO, 0, NULL, INT_MAX, 0); } - sigar_proc_list_create(proclist); - for (offset=0; offsetnproc; offset+=PROC_ELTS) { int i; int elts = table(TBL_PROCINFO, offset, &procinfo, diff --git a/src/os/solaris/solaris_sigar.c b/src/os/solaris/solaris_sigar.c index f7a97d46..253ad88c 100644 --- a/src/os/solaris/solaris_sigar.c +++ b/src/os/solaris/solaris_sigar.c @@ -631,8 +631,8 @@ static int sigar_dlinfo_get(sigar_t *sigar, const char *func, return SIGAR_OK; } -int sigar_proc_list_get(sigar_t *sigar, - sigar_proc_list_t *proclist) +int sigar_os_proc_list_get(sigar_t *sigar, + sigar_proc_list_t *proclist) { return sigar_proc_list_procfs_get(sigar, proclist); } diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index aa9c33b7..8ceed133 100644 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -904,8 +904,6 @@ static int sigar_proc_list_get_perf(sigar_t *sigar, } } - sigar_proc_list_create(proclist); - for (i=0, inst = PdhFirstInstance(object); iNumInstances; i++, inst = PdhNextInstance(inst)) @@ -928,8 +926,8 @@ static int sigar_proc_list_get_perf(sigar_t *sigar, #define sigar_EnumProcesses \ sigar->psapi.enum_processes.func -SIGAR_DECLARE(int) sigar_proc_list_get(sigar_t *sigar, - sigar_proc_list_t *proclist) +int sigar_os_proc_list_get(sigar_t *sigar, + sigar_proc_list_t *proclist) { DLLMOD_INIT(psapi, FALSE); @@ -956,16 +954,14 @@ SIGAR_DECLARE(int) sigar_proc_list_get(sigar_t *sigar, pids = (DWORD *)sigar->perfbuf; - proclist->number = 0; - proclist->size = retval / sizeof(DWORD); - proclist->data = - malloc(sizeof(*(proclist->data)) * proclist->size); + size = retval / sizeof(DWORD); - for (i=0; isize; i++) { + for (i=0; idata[proclist->number++] = pid; } diff --git a/src/sigar.c b/src/sigar.c index 98680382..ae9b643e 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -500,7 +500,7 @@ sigar_proc_cred_name_get(sigar_t *sigar, sigar_pid_t pid, #endif /* WIN32 */ -int sigar_proc_list_create(sigar_proc_list_t *proclist) +static int sigar_proc_list_create(sigar_proc_list_t *proclist) { proclist->number = 0; proclist->size = SIGAR_PROC_LIST_MAX; @@ -530,6 +530,13 @@ SIGAR_DECLARE(int) sigar_proc_list_destroy(sigar_t *sigar, return SIGAR_OK; } +SIGAR_DECLARE(int) sigar_proc_list_get(sigar_t *sigar, + sigar_proc_list_t *proclist) +{ + sigar_proc_list_create(proclist); + return sigar_os_proc_list_get(sigar, proclist); +} + int sigar_proc_args_create(sigar_proc_args_t *procargs) { procargs->number = 0; diff --git a/src/sigar_ptql.c b/src/sigar_ptql.c index af45729f..fd2b66ae 100644 --- a/src/sigar_ptql.c +++ b/src/sigar_ptql.c @@ -1424,8 +1424,6 @@ SIGAR_DECLARE(int) sigar_ptql_query_find(sigar_t *sigar, return status; } - sigar_proc_list_create(proclist); - for (i=0; i