From 5af13a2a6a1a42a2e634b58a16eba517e74096fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Dejean?= Date: Wed, 26 May 2004 16:52:32 +0000 Subject: [PATCH] Cleaned whitespaces. * cpu.c: (glibtop_get_cpu_s): Cleaned whitespaces. * open.c: (get_linux_version), (glibtop_open_s): Removed get_linux_version() Cleaned. Remove static struct utsname. --- sysdeps/linux/ChangeLog | 11 +++++++++-- sysdeps/linux/cpu.c | 12 +++++------ sysdeps/linux/open.c | 44 ++++++++++++++++++++++------------------- 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/sysdeps/linux/ChangeLog b/sysdeps/linux/ChangeLog index 54f80b69..d85eebfc 100644 --- a/sysdeps/linux/ChangeLog +++ b/sysdeps/linux/ChangeLog @@ -1,3 +1,10 @@ +2004-05-26 Benoît Dejean + + * cpu.c: (glibtop_get_cpu_s): Cleaned whitespaces. + + * open.c: (get_linux_version), (glibtop_open_s): Removed get_linux_version() + Cleaned. Remove static struct utsname. + 2004-05-26 Benoît Dejean * glibtop_server.h: @@ -45,14 +52,14 @@ * procsignal.c: (glibtop_get_proc_signal_s): * proctime.c: (glibtop_get_proc_time_s): * procuid.c: (glibtop_get_proc_uid_s): - * swap.c: (glibtop_get_swap_s): Apply patch from Benoît Dejean + * swap.c: (glibtop_get_swap_s): Apply patch from Benoît Dejean to fix overflow issues using strtol (Closes: #129881) 2003-12-23 Bastien Nocera * mem.c: (glibtop_get_mem_s): Fix calculation of used memory, - patch by Benoît Dejea, (Closes: #129863) + patch by Benoît Dejean, (Closes: #129863) 2003-12-07 Jon K Hellan diff --git a/sysdeps/linux/cpu.c b/sysdeps/linux/cpu.c index 0a94f832..87f923c5 100644 --- a/sysdeps/linux/cpu.c +++ b/sysdeps/linux/cpu.c @@ -55,7 +55,7 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf) { char buffer [BUFSIZ], *p; int fd, len; - guint i; + int i; glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0); @@ -87,19 +87,19 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf) /* 2.6 kernel */ buf->idle += strtoull(p, &p, 0); /* "iowait" */ buf->sys += strtoull(p, &p, 0); /* "irq" */ - buf->sys += strtoull(p, &p, 0); /* "softirq" */ + buf->sys += strtoull(p, &p, 0); /* "softirq" */ - buf->total = buf->user + buf->nice + buf->sys + buf->idle; + buf->total = buf->user + buf->nice + buf->sys + buf->idle; buf->frequency = 100; buf->flags = _glibtop_sysdeps_cpu; - /* + /* * PER CPU */ - + for (i = 0; i < GLIBTOP_NCPU && i < server->ncpu; i++) { - + p = skip_line(p); /* move to ^ */ if (strncmp (p, "cpu", 3) || !isdigit (p [3])) diff --git a/sysdeps/linux/open.c b/sysdeps/linux/open.c index 4390420f..b9c594d0 100644 --- a/sysdeps/linux/open.c +++ b/sysdeps/linux/open.c @@ -31,22 +31,27 @@ */ #include +static unsigned get_linux_version(void) { -static int linux_version_code = 0; + static unsigned linux_version_code = 0; -static void set_linux_version(void) { - static struct utsname uts; - int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */ - - if (linux_version_code) return; - if (uname(&uts) == -1) /* failure most likely implies impending death */ - exit(1); - if (sscanf(uts.release, "%d.%d.%d", &x, &y, &z) < 3) - fprintf(stderr, /* *very* unlikely to happen by accident */ - "Non-standard uts for running kernel:\n" - "release %s=%d.%d.%d gives version code %d\n", - uts.release, x, y, z, LINUX_VERSION(x,y,z)); - linux_version_code = LINUX_VERSION(x, y, z); + if(!linux_version_code) { + struct utsname uts; + unsigned x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */ + + if (uname(&uts) == -1) /* failure most likely implies impending death */ + exit(1); + + if (sscanf(uts.release, "%u.%u.%u", &x, &y, &z) < 3) + fprintf(stderr, /* *very* unlikely to happen by accident */ + "Non-standard uts for running kernel:\n" + "release %s=%u.%u.%u gives version code %d\n", + uts.release, x, y, z, LINUX_VERSION(x,y,z)); + + linux_version_code = LINUX_VERSION(x, y, z); + } + + return linux_version_code; } /* ======================================================= */ @@ -65,8 +70,7 @@ glibtop_open_s (glibtop *server, const char *program_name, server->name = program_name; - set_linux_version (); - server->os_version_code = (unsigned long) linux_version_code; + server->os_version_code = get_linux_version(); fd = open (FILENAME, O_RDONLY); if (fd < 0) @@ -79,16 +83,16 @@ glibtop_open_s (glibtop *server, const char *program_name, close (fd); buffer [len] = '\0'; - + for (server->ncpu = 0; server->ncpu < GLIBTOP_NCPU; server->ncpu++) { - + p = skip_line(p); - + if (strncmp (p, "cpu", 3) || !isdigit (p [3])) break; } -#if DEBUG +#if DEBUG printf ("\nThis machine has %d CPUs.\n\n", server->ncpu); #endif }