summaryrefslogtreecommitdiff
path: root/sysdeps/linux
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/linux')
-rw-r--r--sysdeps/linux/cpu.c2
-rw-r--r--sysdeps/linux/fsusage.c2
-rw-r--r--sysdeps/linux/glibtop_private.c13
-rw-r--r--sysdeps/linux/glibtop_private.h20
-rw-r--r--sysdeps/linux/loadavg.c2
-rw-r--r--sysdeps/linux/mem.c2
-rw-r--r--sysdeps/linux/netload.c1
-rw-r--r--sysdeps/linux/open.c2
-rw-r--r--sysdeps/linux/prockernel.c2
-rw-r--r--sysdeps/linux/procmem.c4
-rw-r--r--sysdeps/linux/procsegment.c4
-rw-r--r--sysdeps/linux/procsignal.c2
-rw-r--r--sysdeps/linux/procstate.c2
-rw-r--r--sysdeps/linux/proctime.c4
-rw-r--r--sysdeps/linux/procuid.c4
-rw-r--r--sysdeps/linux/swap.c6
-rw-r--r--sysdeps/linux/sysinfo.c6
-rw-r--r--sysdeps/linux/uptime.c2
18 files changed, 42 insertions, 38 deletions
diff --git a/sysdeps/linux/cpu.c b/sysdeps/linux/cpu.c
index 5ef07315..bedeab59 100644
--- a/sysdeps/linux/cpu.c
+++ b/sysdeps/linux/cpu.c
@@ -75,7 +75,7 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
memset (buf, 0, sizeof (glibtop_cpu));
- file_to_buffer(server, buffer, FILENAME);
+ file_to_buffer(server, buffer, sizeof buffer, FILENAME);
/*
* GLOBAL
diff --git a/sysdeps/linux/fsusage.c b/sysdeps/linux/fsusage.c
index 435b98e1..d66fcc5e 100644
--- a/sysdeps/linux/fsusage.c
+++ b/sysdeps/linux/fsusage.c
@@ -107,7 +107,7 @@ static void linux_2_6_0(glibtop *server, glibtop_fsusage *buf, const char *path)
get_sys_path(device, &filename, &format);
g_free(device);
- ret = try_file_to_buffer(buffer, filename);
+ ret = try_file_to_buffer(buffer, sizeof buffer, filename);
if(ret < 0) return;
diff --git a/sysdeps/linux/glibtop_private.c b/sysdeps/linux/glibtop_private.c
index 8526f694..ac1a0e19 100644
--- a/sysdeps/linux/glibtop_private.c
+++ b/sysdeps/linux/glibtop_private.c
@@ -63,13 +63,16 @@ enum TRY_FILE_TO_BUFFER
TRY_FILE_TO_BUFFER_READ = -2
};
-int try_file_to_buffer(char *buffer, const char *format, ...)
+int try_file_to_buffer(char *buffer, size_t bufsiz, const char *format, ...)
{
char path[4096];
int fd;
ssize_t len;
va_list pa;
+ if (bufsiz <= sizeof(char*))
+ g_warning("Huhu, bufsiz of %lu looks bad", (gulong)bufsiz);
+
va_start(pa, format);
/* C99 also provides vsnprintf */
@@ -82,7 +85,7 @@ int try_file_to_buffer(char *buffer, const char *format, ...)
if((fd = open (path, O_RDONLY)) < 0)
return TRY_FILE_TO_BUFFER_OPEN;
- len = read (fd, buffer, BUFSIZ-1);
+ len = read (fd, buffer, bufsiz - 1);
close (fd);
if (len < 0)
@@ -95,9 +98,9 @@ int try_file_to_buffer(char *buffer, const char *format, ...)
void
-file_to_buffer(glibtop *server, char *buffer, const char *filename)
+file_to_buffer(glibtop *server, char *buffer, size_t bufsiz, const char *filename)
{
- switch(try_file_to_buffer(buffer, filename))
+ switch(try_file_to_buffer(buffer, bufsiz, filename))
{
case TRY_FILE_TO_BUFFER_OPEN:
glibtop_error_io_r (server, "open (%s)", filename);
@@ -115,7 +118,7 @@ read_boot_time(glibtop *server)
char buffer[BUFSIZ];
char *btime;
- file_to_buffer(server, buffer, "/proc/stat");
+ file_to_buffer(server, buffer, sizeof buffer, "/proc/stat");
btime = strstr(buffer, "btime");
diff --git a/sysdeps/linux/glibtop_private.h b/sysdeps/linux/glibtop_private.h
index f24f35f0..8acfa2fa 100644
--- a/sysdeps/linux/glibtop_private.h
+++ b/sysdeps/linux/glibtop_private.h
@@ -68,11 +68,11 @@ get_scaled(const char *buffer, const char *key);
/* aborts on error */
void
-file_to_buffer(glibtop *server, char *buffer, const char *filename);
+file_to_buffer(glibtop *server, char *buffer, size_t bufsiz, const char *filename);
/* return < 0 on error, otherwise 0 on success */
int
-try_file_to_buffer(char *buffer, const char *format, ...) G_GNUC_PRINTF(2, 3);
+try_file_to_buffer(char *buffer, size_t bufsiz, const char *format, ...) G_GNUC_PRINTF(3, 4);
/* some inline functions that wrap proc path
@@ -80,27 +80,27 @@ try_file_to_buffer(char *buffer, const char *format, ...) G_GNUC_PRINTF(2, 3);
*/
static inline int
-proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid)
+proc_file_to_buffer (char *buffer, size_t bufsiz, const char *fmt, pid_t pid)
{
- return try_file_to_buffer(buffer, fmt, pid);
+ return try_file_to_buffer(buffer, bufsiz, fmt, pid);
}
static inline int
-proc_stat_to_buffer (char *buffer, pid_t pid)
+proc_stat_to_buffer (char *buffer, size_t bufsiz, pid_t pid)
{
- return proc_file_to_buffer (buffer, "/proc/%d/stat", pid);
+ return proc_file_to_buffer(buffer, bufsiz, "/proc/%d/stat", pid);
}
static inline int
-proc_status_to_buffer (char *buffer, pid_t pid)
+proc_status_to_buffer (char *buffer, size_t bufsiz, pid_t pid)
{
- return proc_file_to_buffer (buffer, "/proc/%d/status", pid);
+ return proc_file_to_buffer(buffer, bufsiz, "/proc/%d/status", pid);
}
static inline int
-proc_statm_to_buffer (char *buffer, pid_t pid)
+proc_statm_to_buffer (char *buffer, size_t bufsiz, pid_t pid)
{
- return proc_file_to_buffer (buffer, "/proc/%d/statm", pid);
+ return proc_file_to_buffer(buffer, bufsiz, "/proc/%d/statm", pid);
}
diff --git a/sysdeps/linux/loadavg.c b/sysdeps/linux/loadavg.c
index 1c1e15da..98a612b0 100644
--- a/sysdeps/linux/loadavg.c
+++ b/sysdeps/linux/loadavg.c
@@ -52,7 +52,7 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
memset (buf, 0, sizeof (glibtop_loadavg));
- file_to_buffer(server, buffer, FILENAME);
+ file_to_buffer(server, buffer, sizeof buffer, FILENAME);
buf->loadavg [0] = g_ascii_strtod (buffer, &p);
buf->loadavg [1] = g_ascii_strtod (p, &p);
diff --git a/sysdeps/linux/mem.c b/sysdeps/linux/mem.c
index d9964a4c..7b081de1 100644
--- a/sysdeps/linux/mem.c
+++ b/sysdeps/linux/mem.c
@@ -50,7 +50,7 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
memset(buf, 0, sizeof *buf);
- file_to_buffer(server, buffer, FILENAME);
+ file_to_buffer(server, buffer, sizeof buffer, FILENAME);
buf->total = get_scaled(buffer, "MemTotal:");
buf->free = get_scaled(buffer, "MemFree:");
diff --git a/sysdeps/linux/netload.c b/sysdeps/linux/netload.c
index 5ea9c487..c275db2e 100644
--- a/sysdeps/linux/netload.c
+++ b/sysdeps/linux/netload.c
@@ -193,6 +193,7 @@ read_value(glibtop *server,
char buffer[BUFSIZ];
if(try_file_to_buffer(buffer,
+ sizeof buffer,
"/sys/class/net/%s/statistics/%s",
device,
filename))
diff --git a/sysdeps/linux/open.c b/sysdeps/linux/open.c
index 45802695..b39b99ee 100644
--- a/sysdeps/linux/open.c
+++ b/sysdeps/linux/open.c
@@ -73,7 +73,7 @@ glibtop_open_s (glibtop *server, const char *program_name,
set_linux_version(server);
- file_to_buffer(server, buffer, FILENAME);
+ file_to_buffer(server, buffer, sizeof buffer, FILENAME);
p = skip_line(p); /* cpu */
diff --git a/sysdeps/linux/prockernel.c b/sysdeps/linux/prockernel.c
index a682b72b..258fa7e8 100644
--- a/sysdeps/linux/prockernel.c
+++ b/sysdeps/linux/prockernel.c
@@ -49,7 +49,7 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
memset (buf, 0, sizeof (glibtop_proc_kernel));
- if (proc_stat_to_buffer (buffer, pid))
+ if (proc_stat_to_buffer(buffer, sizeof buffer, pid))
return;
p = proc_stat_after_cmd (buffer);
diff --git a/sysdeps/linux/procmem.c b/sysdeps/linux/procmem.c
index f81e26d5..18666435 100644
--- a/sysdeps/linux/procmem.c
+++ b/sysdeps/linux/procmem.c
@@ -54,7 +54,7 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
memset (buf, 0, sizeof (glibtop_proc_mem));
- if (proc_stat_to_buffer (buffer, pid))
+ if (proc_stat_to_buffer(buffer, sizeof buffer, pid))
return;
p = proc_stat_after_cmd (buffer);
@@ -68,7 +68,7 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
buf->flags = _glibtop_sysdeps_proc_mem;
- if (proc_statm_to_buffer (buffer, pid))
+ if (proc_statm_to_buffer(buffer, sizeof buffer, pid))
return;
buf->size = strtoull (buffer, &p, 0);
diff --git a/sysdeps/linux/procsegment.c b/sysdeps/linux/procsegment.c
index 3c1abaf3..9da2c6a8 100644
--- a/sysdeps/linux/procsegment.c
+++ b/sysdeps/linux/procsegment.c
@@ -57,7 +57,7 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
memset (buf, 0, sizeof (glibtop_proc_segment));
- if (proc_stat_to_buffer (buffer, pid))
+ if (proc_stat_to_buffer(buffer, sizeof buffer, pid))
return;
p = proc_stat_after_cmd (buffer);
@@ -71,7 +71,7 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
buf->flags = _glibtop_sysdeps_proc_segment;
- if (proc_statm_to_buffer (buffer, pid))
+ if (proc_statm_to_buffer(buffer, sizeof buffer, pid))
return;
p = skip_multiple_token (buffer, 3);
diff --git a/sysdeps/linux/procsignal.c b/sysdeps/linux/procsignal.c
index ed355d0f..87a4156c 100644
--- a/sysdeps/linux/procsignal.c
+++ b/sysdeps/linux/procsignal.c
@@ -47,7 +47,7 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
memset (buf, 0, sizeof (glibtop_proc_signal));
- if (proc_stat_to_buffer (buffer, pid))
+ if (proc_stat_to_buffer(buffer, sizeof buffer, pid))
return;
p = proc_stat_after_cmd (buffer);
diff --git a/sysdeps/linux/procstate.c b/sysdeps/linux/procstate.c
index 1bb99afc..4c124a53 100644
--- a/sysdeps/linux/procstate.c
+++ b/sysdeps/linux/procstate.c
@@ -73,7 +73,7 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
/* Now we read the remaining fields. */
- if (proc_stat_to_buffer (buffer, pid))
+ if (proc_stat_to_buffer(buffer, sizeof buffer, pid))
return;
p = proc_stat_after_cmd(buffer);
diff --git a/sysdeps/linux/proctime.c b/sysdeps/linux/proctime.c
index 1c630466..706290c5 100644
--- a/sysdeps/linux/proctime.c
+++ b/sysdeps/linux/proctime.c
@@ -58,7 +58,7 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
memset (buf, 0, sizeof (glibtop_proc_time));
- if (proc_stat_to_buffer (buffer, pid))
+ if (proc_stat_to_buffer(buffer, sizeof buffer, pid))
return;
p = proc_stat_after_cmd (buffer);
@@ -113,7 +113,7 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
return;
/* FIXME: doesn't work with 2.6 */
- if (proc_file_to_buffer (buffer, "/proc/%d/cpu", pid))
+ if (proc_file_to_buffer(buffer, sizeof buffer, "/proc/%d/cpu", pid))
return;
p = skip_multiple_token (p, 3);
diff --git a/sysdeps/linux/procuid.c b/sysdeps/linux/procuid.c
index b0d6e49e..9cb1b4d3 100644
--- a/sysdeps/linux/procuid.c
+++ b/sysdeps/linux/procuid.c
@@ -55,7 +55,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
memset (buf, 0, sizeof (glibtop_proc_uid));
- if (proc_status_to_buffer (buffer, pid))
+ if (proc_status_to_buffer(buffer, sizeof buffer, pid))
return;
/* Search substring 'Pid:' */
@@ -89,7 +89,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
buf->flags = _glibtop_sysdeps_proc_uid;
- if (proc_stat_to_buffer (buffer, pid))
+ if (proc_stat_to_buffer(buffer, sizeof buffer, pid))
return;
p = proc_stat_after_cmd (buffer);
diff --git a/sysdeps/linux/swap.c b/sysdeps/linux/swap.c
index 65d8763c..91832ad8 100644
--- a/sysdeps/linux/swap.c
+++ b/sysdeps/linux/swap.c
@@ -56,7 +56,7 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
memset (buf, 0, sizeof (glibtop_swap));
- file_to_buffer(server, buffer, MEMINFO);
+ file_to_buffer(server, buffer, sizeof buffer, MEMINFO);
/* Kernel 2.6 with multiple lines */
@@ -69,7 +69,7 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
if(server->os_version_code >= LINUX_VERSION_CODE(2, 6, 0))
{
- file_to_buffer (server, buffer, PROC_VMSTAT);
+ file_to_buffer (server, buffer, sizeof buffer, PROC_VMSTAT);
p = strstr (buffer, "\npswpin");
@@ -86,7 +86,7 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
}
else /* Linux 2.4 */
{
- file_to_buffer (server, buffer, PROC_STAT);
+ file_to_buffer (server, buffer, sizeof buffer, PROC_STAT);
p = strstr (buffer, "\nswap");
diff --git a/sysdeps/linux/sysinfo.c b/sysdeps/linux/sysinfo.c
index 3e4f9695..9b3747de 100644
--- a/sysdeps/linux/sysinfo.c
+++ b/sysdeps/linux/sysinfo.c
@@ -26,7 +26,7 @@
#include "glibtop_private.h"
-#define FILENAME "/proc/cpuinfo"
+#define FILENAME "/home/benoit/Desktop/libgtop/cpuinfo8.txt"
static const unsigned long _glibtop_sysdeps_sysinfo =
(1L << GLIBTOP_SYSINFO_CPUINFO);
@@ -36,12 +36,12 @@ static glibtop_sysinfo sysinfo = { .flags = 0 };
static void
init_sysinfo (glibtop *server)
{
- char buffer [BUFSIZ];
+ char buffer [16384];
gchar ** processors;
if(G_LIKELY(sysinfo.flags)) return;
- file_to_buffer(server, buffer, FILENAME);
+ file_to_buffer(server, buffer, sizeof buffer, FILENAME);
/* cpuinfo records are seperated by a blank line */
processors = g_strsplit(buffer, "\n\n", 0);
diff --git a/sysdeps/linux/uptime.c b/sysdeps/linux/uptime.c
index 997947d8..a48d8760 100644
--- a/sysdeps/linux/uptime.c
+++ b/sysdeps/linux/uptime.c
@@ -51,7 +51,7 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
memset (buf, 0, sizeof (glibtop_uptime));
- file_to_buffer(server, buffer, FILENAME);
+ file_to_buffer(server, buffer, sizeof buffer, FILENAME);
buf->uptime = g_ascii_strtod (buffer, &p);
buf->idletime = g_ascii_strtod (p, &p);