From b4fcd6e378f30ffa36a87617d4c9e6113f70308d Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 19 Feb 2021 08:42:38 +0000 Subject: win32: add uptime to sysinfo(2), enable uptime applet Fill the uptime member of the sysinfo structure. With this change we can: - use sysinfo(2) in the 'ps' applet; - enable the 'uptime' applet (though without useful support for load averages). --- configs/mingw32_defconfig | 2 +- configs/mingw64_defconfig | 2 +- procps/ps.c | 4 +--- win32/mingw.c | 5 ++--- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/configs/mingw32_defconfig b/configs/mingw32_defconfig index 8c0e2ed42..7edc052ab 100644 --- a/configs/mingw32_defconfig +++ b/configs/mingw32_defconfig @@ -1070,7 +1070,7 @@ CONFIG_FEATURE_PS_TIME=y # CONFIG_FEATURE_TOP_DECIMALS is not set # CONFIG_FEATURE_TOP_SMP_PROCESS is not set # CONFIG_FEATURE_TOPMEM is not set -# CONFIG_UPTIME is not set +CONFIG_UPTIME=y # CONFIG_FEATURE_UPTIME_UTMP_SUPPORT is not set CONFIG_WATCH=y # CONFIG_FEATURE_SHOW_THREADS is not set diff --git a/configs/mingw64_defconfig b/configs/mingw64_defconfig index 89167b998..d3ff6d774 100644 --- a/configs/mingw64_defconfig +++ b/configs/mingw64_defconfig @@ -1070,7 +1070,7 @@ CONFIG_FEATURE_PS_TIME=y # CONFIG_FEATURE_TOP_DECIMALS is not set # CONFIG_FEATURE_TOP_SMP_PROCESS is not set # CONFIG_FEATURE_TOPMEM is not set -# CONFIG_UPTIME is not set +CONFIG_UPTIME=y # CONFIG_FEATURE_UPTIME_UTMP_SUPPORT is not set CONFIG_WATCH=y # CONFIG_FEATURE_SHOW_THREADS is not set diff --git a/procps/ps.c b/procps/ps.c index f84060447..801a6fdf3 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -120,13 +120,11 @@ enum { MAX_WIDTH = 2*1024 }; #if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG static unsigned long get_uptime(void) { -#ifdef __linux__ +#if defined __linux__ || ENABLE_PLATFORM_MINGW32 struct sysinfo info; if (sysinfo(&info) < 0) return 0; return info.uptime; -#elif ENABLE_PLATFORM_MINGW32 - return GetTickCount64()/1000; #elif 1 unsigned long uptime; char buf[sizeof(uptime)*3 + 2]; diff --git a/win32/mingw.c b/win32/mingw.c index 48d2eefa7..ddc64b43a 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -1389,6 +1389,8 @@ int sysinfo(struct sysinfo *info) info->totalswap = mem.ullTotalPageFile - mem.ullTotalPhys; info->freeswap = mem.ullAvailPageFile - mem.ullAvailPhys; + info->uptime = GetTickCount64() / 1000; + return 0; } @@ -1617,9 +1619,7 @@ off_t mingw_lseek(int fd, off_t offset, int whence) return _lseeki64(fd, offset, whence); } -#if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG #undef GetTickCount64 - ULONGLONG CompatGetTickCount64(void) { DECLARE_PROC_ADDR(ULONGLONG, GetTickCount64, void); @@ -1630,7 +1630,6 @@ ULONGLONG CompatGetTickCount64(void) return GetTickCount64(); } -#endif #if ENABLE_FEATURE_INSTALLER /* -- cgit v1.2.3-55-g6feb