diff --git a/src/os/linux/linux_sigar.c b/src/os/linux/linux_sigar.c index 24efe243..e8db44b0 100644 --- a/src/os/linux/linux_sigar.c +++ b/src/os/linux/linux_sigar.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "sigar.h" #include "sigar_private.h" @@ -45,9 +46,6 @@ #define PROC_PARTITIONS PROC_FS_ROOT "partitions" #define PROC_DISKSTATS PROC_FS_ROOT "diskstats" -/* Native POSIX Thread Library 2.6+ kernel */ -#define SIGAR_HAS_NPTL (sigar->iostat == IOSTAT_DISKSTATS) - /* * /proc/self/stat fields: * 1 - pid @@ -157,7 +155,9 @@ static int sigar_boot_time_get(sigar_t *sigar) int sigar_os_open(sigar_t **sigar) { int i, status; + int kernel_rev, has_nptl; struct stat sb; + struct utsname name; *sigar = malloc(sizeof(**sigar)); @@ -199,6 +199,17 @@ int sigar_os_open(sigar_t **sigar) /* hook for using mirrored /proc/net/tcp file */ (*sigar)->proc_net = getenv("SIGAR_PROC_NET"); + uname(&name); + /* 2.X.y.z -> just need X (unless there is ever a kernel version 3!) */ + kernel_rev = atoi(&name.release[2]); + if (kernel_rev >= 6) { + has_nptl = 1; + } + else { + has_nptl = getenv("SIGAR_HAS_NPTL") ? 1 : 0; + } + (*sigar)->has_nptl = has_nptl; + return SIGAR_OK; } @@ -585,7 +596,7 @@ int sigar_os_proc_list_get(sigar_t *sigar, { DIR *dirp = opendir(PROCP_FS_ROOT); struct dirent *ent, dbuf; - register const int threadbadhack = !SIGAR_HAS_NPTL; + register const int threadbadhack = !sigar->has_nptl; if (!dirp) { return errno; diff --git a/src/os/linux/sigar_os.h b/src/os/linux/sigar_os.h index 79f6ed60..f8c65e84 100644 --- a/src/os/linux/sigar_os.h +++ b/src/os/linux/sigar_os.h @@ -67,6 +67,8 @@ struct sigar_t { int lcpu; linux_iostat_e iostat; char *proc_net; + /* Native POSIX Thread Library 2.6+ kernel */ + int has_nptl; }; #define HAVE_STRERROR_R