From 12fe73d2ed9c10ee5fa9b2e9fe00a2a27fe77e22 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Sat, 22 Apr 2023 20:00:03 +0000 Subject: SunOS: fix some C compilation warnings Signed-off-by: Giampaolo Rodola --- Makefile | 2 +- psutil/_psutil_sunos.c | 4 ++-- psutil/arch/solaris/environ.c | 8 ++++---- psutil/tests/test_posix.py | 11 +++++++---- psutil/tests/test_sunos.py | 7 +++---- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index ba62aa98..a82940d9 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,7 @@ INSTALL_OPTS = `$(PYTHON) -c \ TEST_PREFIX = PSUTIL_SCRIPTS_DIR=`pwd`/scripts PYTHONWARNINGS=always PSUTIL_DEBUG=1 # if make is invoked with no arg, default to `make help` -.DEFAULT_GOAL := help +# .DEFAULT_GOAL := help # =================================================================== # Install diff --git a/psutil/_psutil_sunos.c b/psutil/_psutil_sunos.c index e2e7c018..5422005f 100644 --- a/psutil/_psutil_sunos.c +++ b/psutil/_psutil_sunos.c @@ -129,7 +129,7 @@ psutil_proc_basic_info(PyObject *self, PyObject *args) { */ static int cstrings_array_to_string(char **joined, char ** array, size_t count, char dm) { - int i; + size_t i; size_t total_length = 0; size_t item_length = 0; char *result = NULL; @@ -353,7 +353,7 @@ psutil_proc_cpu_times(PyObject *self, PyObject *args) { */ static PyObject * psutil_proc_cpu_num(PyObject *self, PyObject *args) { - int fd = NULL; + int fd = -1; int pid; char path[1000]; struct prheader header; diff --git a/psutil/arch/solaris/environ.c b/psutil/arch/solaris/environ.c index 58afd63a..dd627eb0 100644 --- a/psutil/arch/solaris/environ.c +++ b/psutil/arch/solaris/environ.c @@ -55,7 +55,7 @@ open_address_space(pid_t pid, const char *procfs_path) { * @return amount of bytes stored to the buffer or -1 in case of * error. */ -static int +static size_t read_offt(int fd, off_t offset, char *buf, size_t buf_size) { size_t to_read = buf_size; size_t stored = 0; @@ -161,7 +161,7 @@ read_cstrings_block(int fd, off_t offset, size_t ptr_size, size_t count) { char **result = NULL; char *pblock = NULL; size_t pblock_size; - int i; + size_t i; assert(ptr_size == 4 || ptr_size == 8); @@ -247,7 +247,7 @@ ptr_size_by_psinfo(psinfo_t info) { static int search_pointers_vector_size_offt(int fd, off_t offt, size_t ptr_size) { int count = 0; - int r; + size_t r; char buf[8]; static const char zeros[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -391,7 +391,7 @@ psutil_read_raw_env(psinfo_t info, const char *procfs_path, ssize_t *count) { */ void psutil_free_cstrings_array(char **array, size_t count) { - int i; + size_t i; if (!array) return; diff --git a/psutil/tests/test_posix.py b/psutil/tests/test_posix.py index 9ce82cae..c789ee87 100755 --- a/psutil/tests/test_posix.py +++ b/psutil/tests/test_posix.py @@ -62,10 +62,7 @@ def ps(fmt, pid=None): cmd.append('ax') if SUNOS: - # XXX: set() has not get() method so this cannot work; not sure - # what I meant in here. - fmt_map = set(('command', 'comm', 'start', 'stime')) - fmt = fmt_map.get(fmt, fmt) + fmt = fmt.replace("start", "stime") cmd.extend(['-o', fmt]) @@ -373,6 +370,12 @@ class TestSystemAPIs(PsutilTestCase): started = re.findall(r"[A-Z][a-z][a-z] \d\d", out) if started: tstamp = "%b %d" + else: + # 'apr 10' (sunOS) + started = re.findall(r"[a-z][a-z][a-z] \d\d", out) + if started: + tstamp = "%b %d" + started = [x.capitalize() for x in started] if not tstamp: raise ValueError( diff --git a/psutil/tests/test_sunos.py b/psutil/tests/test_sunos.py index dd74a49b..274584d6 100755 --- a/psutil/tests/test_sunos.py +++ b/psutil/tests/test_sunos.py @@ -25,10 +25,9 @@ class SunOSSpecificTestCase(PsutilTestCase): raise ValueError('no swap device(s) configured') total = free = 0 for line in lines: - line = line.split() - t, f = line[-2:] - total += int(int(t) * 512) - free += int(int(f) * 512) + fields = line.split() + total = int(fields[3]) * 512 + free = int(fields[4]) * 512 used = total - free psutil_swap = psutil.swap_memory() -- cgit v1.2.1