diff --git a/src/plat/bsd/detect.c b/src/plat/bsd/detect.c index 81c4e3b..f98f222 100644 --- a/src/plat/bsd/detect.c +++ b/src/plat/bsd/detect.c @@ -39,6 +39,7 @@ void detect_distro(char *str) { struct utsname distro_info; + uname(&distro_info); snprintf(str, MAX_STRLEN, "%s", distro_info.sysname); @@ -52,6 +53,7 @@ void detect_distro(char *str) void detect_arch(char *str) { struct utsname arch_info; + uname(&arch_info); safe_strncpy(str, arch_info.machine, MAX_STRLEN); @@ -66,10 +68,10 @@ void detect_host(char *str) { char *given_user = "Unknown"; char given_host[MAX_STRLEN] = "Unknown"; + struct utsname host_info; given_user = getlogin(); - struct utsname host_info; uname(&host_info); safe_strncpy(given_host, host_info.nodename, MAX_STRLEN); @@ -85,6 +87,7 @@ void detect_host(char *str) void detect_kernel(char *str) { struct utsname kern_info; + uname(&kern_info); snprintf(str, MAX_STRLEN, "%s", kern_info.release); @@ -98,39 +101,36 @@ void detect_kernel(char *str) void detect_uptime(char *str) { long uptime = 0; - - #if !defined(__NetBSD__) - long currtime = 0, boottime = 0; - #endif - +#if !defined(__NetBSD__) + long currtime = 0, boottime = 0; +#endif FILE *uptime_file; - int secs = 0; int mins = 0; int hrs = 0; int days = 0; - #if defined(__NetBSD__) - uptime_file = popen("cut -d ' ' -f 1 < /proc/uptime", "r"); - fscanf(uptime_file, "%ld", &uptime); - pclose(uptime_file); - #elif defined(__FreeBSD__) || defined(__DragonFly__) - uptime_file = popen("sysctl -n kern.boottime | cut -d '=' -f 2 | cut -d ',' -f 1", "r"); - fscanf(uptime_file, "%ld", &boottime); /* get boottime in secs */ - pclose(uptime_file); +#if defined(__NetBSD__) + uptime_file = popen("cut -d ' ' -f 1 < /proc/uptime", "r"); + fscanf(uptime_file, "%ld", &uptime); + pclose(uptime_file); +#elif defined(__FreeBSD__) || defined(__DragonFly__) + uptime_file = popen("sysctl -n kern.boottime | cut -d '=' -f 2 | cut -d ',' -f 1", "r"); + fscanf(uptime_file, "%ld", &boottime); /* get boottime in secs */ + pclose(uptime_file); - currtime = time(NULL); + currtime = time(NULL); - uptime = currtime - boottime; - #elif defined(__OpenBSD__) - uptime_file = popen("sysctl -n kern.boottime", "r"); - fscanf(uptime_file, "%ld", &boottime); /* get boottime in secs */ - pclose(uptime_file); + uptime = currtime - boottime; +#elif defined(__OpenBSD__) + uptime_file = popen("sysctl -n kern.boottime", "r"); + fscanf(uptime_file, "%ld", &boottime); /* get boottime in secs */ + pclose(uptime_file); - currtime = time(NULL); + currtime = time(NULL); - uptime = currtime - boottime; - #endif + uptime = currtime - boottime; +#endif split_uptime(uptime, &secs, &mins, &hrs, &days); @@ -149,23 +149,25 @@ void detect_uptime(char *str) void detect_pkgs(char *str, const char *distro_str) { int packages = 0; +#if defined(__FreeBSD__) || defined(__OpenBSD__) + FILE *pkgs_file; +#endif - #if defined(__FreeBSD__) - FILE *pkgs_file; - pkgs_file = popen("pkg info | wc -l", "r"); - fscanf(pkgs_file, "%d", &packages); - pclose(pkgs_file); - #elif defined(__OpenBSD__) - FILE *pkgs_file; - pkgs_file = popen("pkg_info | wc -l", "r"); - fscanf(pkgs_file, "%d", &packages); - pclose(pkgs_file); - #else - safe_strncpy(str, "Not Found", MAX_STRLEN); - if (error) - ERROR_OUT("Error: ", "Could not find packages on current OS."); - #endif +#if defined(__FreeBSD__) + pkgs_file = popen("pkg info | wc -l", "r"); + fscanf(pkgs_file, "%d", &packages); + pclose(pkgs_file); +#elif defined(__OpenBSD__) + pkgs_file = popen("pkg_info | wc -l", "r"); + fscanf(pkgs_file, "%d", &packages); + pclose(pkgs_file); +#else + safe_strncpy(str, "Not Found", MAX_STRLEN); + + if (error) + ERROR_OUT("Error: ", "Could not find packages on current OS."); +#endif snprintf(str, MAX_STRLEN, "%d", packages); @@ -180,15 +182,15 @@ void detect_cpu(char *str) { FILE *cpu_file; - #if defined(__NetBSD__) - cpu_file = popen("awk 'BEGIN{FS=\":\"} /model name/ { print $2; exit }' /proc/cpuinfo | sed -e 's/ @/\\n/' -e 's/^ *//g' -e 's/ *$//g' | head -1 | tr -d '\\n'", "r"); - fgets(str, MAX_STRLEN, cpu_file); - pclose(cpu_file); - #else - cpu_file = popen("sysctl -n hw.model | tr -d '\\n'", "r"); - fgets(str, MAX_STRLEN, cpu_file); - pclose(cpu_file); - #endif +#if defined(__NetBSD__) + cpu_file = popen("awk 'BEGIN{FS=\":\"} /model name/ { print $2; exit }' /proc/cpuinfo | sed -e 's/ @/\\n/' -e 's/^ *//g' -e 's/ *$//g' | head -1 | tr -d '\\n'", "r"); + fgets(str, MAX_STRLEN, cpu_file); + pclose(cpu_file); +#else + cpu_file = popen("sysctl -n hw.model | tr -d '\\n'", "r"); + fgets(str, MAX_STRLEN, cpu_file); + pclose(cpu_file); +#endif return; } @@ -239,7 +241,6 @@ void detect_disk(char *str) void detect_mem(char *str) { FILE *mem_file; - long long total_mem = 0; mem_file = popen("sysctl -n hw.physmem", "r"); @@ -433,7 +434,6 @@ void detect_wm_theme(char *str, const char *wm_str) void detect_gtk(char *str) { FILE *gtk_file; - char gtk2_str[MAX_STRLEN] = "Unknown"; char gtk3_str[MAX_STRLEN] = "Unknown"; char gtk_icons_str[MAX_STRLEN] = "Unknown"; diff --git a/src/plat/darwin/detect.c b/src/plat/darwin/detect.c index d767b4d..d2d4a84 100644 --- a/src/plat/darwin/detect.c +++ b/src/plat/darwin/detect.c @@ -39,26 +39,29 @@ */ void detect_distro(char *str) { +#if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1070 + int ver_maj, ver_min, ver_bug; +#else + FILE *distro_file; +#endif + /* Use this: https://www.opensource.apple.com/source/DarwinTools/DarwinTools-1/sw_vers.c */ - #if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1070 - int ver_maj, ver_min, ver_bug; - Gestalt(gestaltSystemVersionMajor, (SInt32 *) &ver_maj); - Gestalt(gestaltSystemVersionMinor, (SInt32 *) &ver_min); - Gestalt(gestaltSystemVersionBugFix, (SInt32 *) &ver_bug); - - snprintf(str, MAX_STRLEN, "Max OS X %d.%d.%d", ver_maj, ver_min, ver_bug); - #else - FILE *distro_file; +#if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1070 + Gestalt(gestaltSystemVersionMajor, (SInt32 *) &ver_maj); + Gestalt(gestaltSystemVersionMinor, (SInt32 *) &ver_min); + Gestalt(gestaltSystemVersionBugFix, (SInt32 *) &ver_bug); - distro_file = popen("sw_vers -productVersion | tr -d '\\n'", "r"); - fgets(distro_name_str, MAX_STRLEN, distro_file); - pclose(distro_file); + snprintf(str, MAX_STRLEN, "Max OS X %d.%d.%d", ver_maj, ver_min, ver_bug); +#else + distro_file = popen("sw_vers -productVersion | tr -d '\\n'", "r"); + fgets(distro_name_str, MAX_STRLEN, distro_file); + pclose(distro_file); - snprintf(str, MAX_STRLEN, "Mac OS X %s", distro_name_str); - #endif + snprintf(str, MAX_STRLEN, "Mac OS X %s", distro_name_str); +#endif return; } @@ -70,6 +73,7 @@ void detect_distro(char *str) void detect_arch(char *str) { struct utsname arch_info; + uname(&arch_info); safe_strncpy(str, arch_info.machine, MAX_STRLEN); @@ -84,10 +88,9 @@ void detect_host(char *str) { char *given_user = "Unknown"; char given_host[MAX_STRLEN] = "Unknown"; + struct utsname host_info; given_user = getlogin(); - - struct utsname host_info; uname(&host_info); safe_strncpy(given_host, host_info.nodename, MAX_STRLEN); @@ -103,6 +106,7 @@ void detect_host(char *str) void detect_kernel(char *str) { struct utsname kern_info; + uname(&kern_info); snprintf(str, MAX_STRLEN, "%s %s", kern_info.sysname, kern_info.release); @@ -116,7 +120,6 @@ void detect_kernel(char *str) void detect_uptime(char *str) { long long uptime = 0; - int secs = 0; int mins = 0; int hrs = 0; @@ -210,7 +213,6 @@ void detect_gpu(char *str) void detect_disk(char *str) { struct statfs disk_info; - long disk_total = 0, disk_used = 0, disk_percentage = 0; if (!(statfs(getenv("HOME"), &disk_info))) @@ -235,7 +237,6 @@ void detect_disk(char *str) void detect_mem(char *str) { FILE *mem_file; - long long total_mem = 0; long long free_mem = 0; long long used_mem = 0; diff --git a/src/plat/sun/detect.c b/src/plat/sun/detect.c index 6b09a88..b2c38df 100644 --- a/src/plat/sun/detect.c +++ b/src/plat/sun/detect.c @@ -37,6 +37,7 @@ void detect_distro(char *str) { struct utsname distro_info; + uname(&distro_info); snprintf(str, MAX_STRLEN, "%s", distro_info.sysname); @@ -50,6 +51,7 @@ void detect_distro(char *str) void detect_arch(char *str) { struct utsname arch_info; + uname(&arch_info); safe_strncpy(str, arch_info.machine, MAX_STRLEN); @@ -64,10 +66,9 @@ void detect_host(char *str) { char *given_user = "Unknown"; char given_host[MAX_STRLEN] = "Unknown"; - - given_user = getlogin(); /* getlogin is apparently buggy on linux, so this might be changed */ - struct utsname host_info; + + given_user = getlogin(); uname(&host_info); safe_strncpy(given_host, host_info.nodename, MAX_STRLEN); @@ -83,6 +84,7 @@ void detect_host(char *str) void detect_kernel(char *str) { struct utsname kern_info; + uname(&kern_info); snprintf(str, MAX_STRLEN, "%s", kern_info.release); @@ -96,14 +98,13 @@ void detect_kernel(char *str) void detect_uptime(char *str) { long uptime = 0, currtime = 0, boottime = 0; - int secs = 0; int mins = 0; int hrs = 0; int days = 0; + struct utmpx *ent; currtime = time(NULL); - struct utmpx *ent; while ((ent = getutxent())) { @@ -289,12 +290,12 @@ void detect_res(char *str) { int width = 0; int height = 0; - Display *disp; + Screen *screen; if ((disp = XOpenDisplay(NULL))) { - Screen *screen = XDefaultScreenOfDisplay(disp); + screen = XDefaultScreenOfDisplay(disp); width = WidthOfScreen(screen); height = HeightOfScreen(screen); snprintf(str, MAX_STRLEN, "%dx%d", width, height); diff --git a/src/plat/win32/detect.c b/src/plat/win32/detect.c index 5406cf2..d3eba1e 100644 --- a/src/plat/win32/detect.c +++ b/src/plat/win32/detect.c @@ -123,6 +123,7 @@ void detect_host(char *str) void detect_kernel(char *str) { OSVERSIONINFO kern_info; + ZeroMemory(&kern_info, sizeof(OSVERSIONINFO)); kern_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&kern_info); @@ -139,7 +140,6 @@ void detect_kernel(char *str) void detect_uptime(char *str) { long uptime = 0; - int secs = 0; int mins = 0; int hrs = 0; @@ -185,6 +185,7 @@ void detect_cpu(char *str) { HKEY hkey; DWORD str_size = MAX_STRLEN; + RegOpenKey(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", &hkey); RegQueryValueEx(hkey, "ProcessorNameString", 0, NULL, (BYTE *) str, &str_size); @@ -199,6 +200,7 @@ void detect_gpu(char *str) { HKEY hkey; DWORD str_size = MAX_STRLEN; + RegOpenKey(HKEY_LOCAL_MACHINE, "SYSTEM\\ControlSet001\\Control\\Class\\{4D36E968-E325-11CE-BFC1-08002BE10318}\\0000\\Settings", &hkey); RegQueryValueEx(hkey, "Device Description", 0, NULL, (BYTE *) str, &str_size); @@ -212,12 +214,11 @@ void detect_gpu(char *str) void detect_disk(char *str) { FILE *disk_file; - int disk_total = 0; int disk_used = 0; int disk_percentage = 0; - /* Cygwin -- GetDiskFreeSpaceEx? */ + /* GetDiskFreeSpaceEx? */ disk_file = popen("df -H 2> /dev/null | grep -vE '^[A-Z]\\:\\/|File' | awk '{ print $2 }' | head -1 | tr -d '\\r\\n G'", "r"); fscanf(disk_file, "%d", &disk_total); @@ -251,8 +252,8 @@ void detect_mem(char *str) { long long total_mem = 0; long long used_mem = 0; - MEMORYSTATUSEX mem_stat; + mem_stat.dwLength = sizeof(mem_stat); GlobalMemoryStatusEx(&mem_stat); @@ -355,7 +356,6 @@ void detect_res(char *str) void detect_de(char *str) { FILE *de_file; - int version; de_file = popen("wmic os get version | grep -o '^[0-9]'", "r");