Merged trunk. SVN SUCKS.

Merged trunk.
SVN SUCKS.

svn path=/branches/affinity/; revision=2661
This commit is contained in:
Benoît Dejean
2007-09-21 21:29:17 +00:00
parent 4c6b506488
commit fcee021a2d
72 changed files with 2066 additions and 2041 deletions

View File

@@ -368,17 +368,3 @@ glibtop_get_proc_wd(glibtop_proc_wd *buf, pid_t pid)
}
/**
* glibtop_get_proc_affinity:
* @buf:
* @pid: Process id to get the affinity
*
* Get the processor affinity list for a process
*
* Returns: A list of processor ID of 'buf.number' elements.
*/
guint16 *
glibtop_get_proc_affinity(glibtop_proc_affinity *buf, pid_t pid)
{
return glibtop_get_proc_affinity_l(glibtop_global_server, buf, pid);
}

View File

@@ -1,3 +1,11 @@
2007-07-01 Benoît Dejean <benoit@placenet.org>
Fixe some problems as well as implements procwd and procopenfiles
for FreeBSD using a wrapper around lsof. This same backend should
also work on kFreeBSD.
Patch by Joe Marcus Clarke <marcus@freebsd.org>
2007-02-18 Benoît Dejean <benoit@placenet.org>
* AUTHORS:

View File

@@ -5,7 +5,9 @@ noinst_LTLIBRARIES = libgtop_sysdeps-2.0.la libgtop_sysdeps_suid-2.0.la
libgtop_sysdeps_2_0_la_SOURCES = nosuid.c siglist.c sysinfo.c shm_limits.c \
cpu.c msg_limits.c sem_limits.c loadavg.c \
uptime.c netlist.c fsusage.c mem.c
uptime.c netlist.c fsusage.c mem.c \
procopenfiles.c procwd.c \
glibtop_private.c
libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
@@ -14,11 +16,11 @@ libgtop_sysdeps_suid_2_0_la_SOURCES = open.c close.c swap.c \
proclist.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c \
prockernel.c procsegment.c procargs.c \
procmap.c netload.c ppp.c procopenfiles.c
procmap.c netload.c ppp.c
libgtop_sysdeps_suid_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
libgtopinclude_HEADERS = glibtop_server.h glibtop_machine.h \
glibtop_suid.h
glibtop_suid.h glibtop_private.h
libgtopincludedir = $(includedir)/libgtop-2.0

View File

@@ -0,0 +1,54 @@
#include <config.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include "glibtop_private.h"
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <glib.h>
#include <errno.h>
char *
execute_lsof(pid_t pid) {
char *output = NULL;
char *lsof;
char *command;
int exit_status;
lsof = g_find_program_in_path("lsof");
if (lsof == NULL)
return NULL;
command = g_strdup_printf("%s -n -P -Fftn -p %d", lsof, pid);
g_free(lsof);
if (g_spawn_command_line_sync (command, &output, NULL, &exit_status, NULL)) {
if (exit_status != 0) {
g_warning("Could not execute \"%s\" (%i)", command,
exit_status);
output = NULL;
}
}
g_free(command);
return output;
}
/* Ported from linux/glibtop_private.c */
gboolean
safe_readlink(const char *path, char *buf, int bufsiz)
{
int ret;
ret = readlink(path, buf, bufsiz - 1);
if (ret == -1) {
g_warning("Could not read link %s : %s", path, strerror(errno));
return FALSE;
}
buf[ret] = '\0';
return TRUE;
}

View File

@@ -0,0 +1,40 @@
/* Copyright (C) 2007 Joe Marcus Clarke
This file is part of LibGTop 2.0.
LibGTop is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
LibGTop is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LibGTop; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef __FREEBSD__GLIBTOP_PRIVATE_H__
#define __FREEBSD__GLIBTOP_PRIVATE_H__
#include <glibtop.h>
#include <glibtop/error.h>
#include <glib.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
G_BEGIN_DECLS
char *execute_lsof(pid_t pid);
gboolean safe_readlink(const char *path, char *buf, int bufsiz);
G_END_DECLS
#endif /* __FREEBSD__GLIBTOP_PRIVATE_H__ */

View File

@@ -45,6 +45,7 @@ G_BEGIN_DECLS
#define GLIBTOP_SUID_MSG_LIMITS 0
#define GLIBTOP_SUID_SEM_LIMITS 0
#define GLIBTOP_SUID_NETLIST 0
#define GLIBTOP_SUID_PROC_WD 0
G_END_DECLS

View File

@@ -40,7 +40,7 @@ static const unsigned long _glibtop_sysdeps_proclist =
* buf->flags is only set if the call succeeded, in this case pids_chain,
* a list of the pids of all currently running processes is returned,
* buf->number is the number of elements of this list and buf->size is
* the size of one single element (sizeof (unsigned)). The total size is
* the size of one single element (sizeof (pid_t)). The total size is
* stored in buf->total.
*
* The calling function has to free the memory to which a pointer is returned.
@@ -61,7 +61,7 @@ _glibtop_init_proclist_p (glibtop *server)
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
}
unsigned *
pid_t *
glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
gint64 which, gint64 arg)
{
@@ -90,18 +90,18 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
len /= sizeof (struct kinfo_proc);
pids = g_array_sized_new (FALSE, FALSE, sizeof (unsigned), len);
pids = g_array_sized_new (FALSE, FALSE, sizeof (pid_t), len);
for (i = 0; i < len; i++) {
unsigned pid;
pid_t pid;
pid = (unsigned) pinfo[i].ki_pid;
pid = (pid_t) pinfo[i].ki_pid;
switch (which & GLIBTOP_KERN_PROC_MASK) {
case GLIBTOP_KERN_PROC_ALL:
break;
case GLIBTOP_KERN_PROC_PID:
if ((unsigned) arg != pid)
if ((pid_t) arg != pid)
continue;
break;
case GLIBTOP_KERN_PROC_UID:
@@ -144,9 +144,9 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
g_free (pinfo);
buf->flags = _glibtop_sysdeps_proclist;
buf->size = sizeof (unsigned);
buf->size = sizeof (pid_t);
buf->number = pids->len;
buf->total = buf->number * buf->size;
return (unsigned *) g_array_free (pids, FALSE);
return (pid_t *) g_array_free (pids, FALSE);
}

View File

@@ -1,5 +1,6 @@
/* Copyright (C) 1998-99 Martin Baulig
Copyright (C) 2004 Nicol<6F>s Lichtmaier
Copyright (C) 2007 Joe Marcus Clarke
This file is part of LibGTop 1.0.
Modified by Nicol<6F>s Lichtmaier to give a process open files.
@@ -26,8 +27,11 @@
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procopenfiles.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <glibtop_suid.h>
#include "glibtop_private.h"
static const unsigned long _glibtop_sysdeps_proc_open_files =
(1L << GLIBTOP_PROC_OPEN_FILES_NUMBER)|
@@ -42,10 +46,139 @@ _glibtop_init_proc_open_files_s (glibtop *server)
server->sysdeps.proc_open_files = _glibtop_sysdeps_proc_open_files;
}
static GArray *
parse_output(const char *output) {
GArray *entries;
char **lines;
char *ftype = NULL;
char *fname = NULL;
guint i;
guint len;
int fd = -1;
entries = g_array_new(FALSE, FALSE, sizeof(glibtop_open_files_entry));
lines = g_strsplit(output, "\n", 0);
len = g_strv_length(lines);
for (i = 0; i < len && lines[i]; i++) {
glibtop_open_files_entry entry = {0};
if (strlen(lines[i]) < 2)
continue;
if (!g_str_has_prefix(lines[i], "f") &&
!g_str_has_prefix(lines[i], "t") &&
!g_str_has_prefix(lines[i], "n"))
continue;
if (g_str_has_prefix(lines[i], "f")) {
if (!g_ascii_isdigit(*(lines[i] + 1)))
i += 2;
else
fd = atoi(lines[i] + 1);
continue;
}
if (g_str_has_prefix(lines[i], "t")) {
ftype = lines[i];
ftype++;
continue;
} else {
fname = lines[i];
fname++;
}
if (ftype == NULL || fname == NULL)
continue;
if (!strcmp(ftype, "unix")) {
entry.type = GLIBTOP_FILE_TYPE_LOCALSOCKET;
g_strlcpy(entry.info.localsock.name, fname,
sizeof(entry.info.localsock.name));
} else if (!strcmp(ftype, "PIPE")) {
entry.type = GLIBTOP_FILE_TYPE_PIPE;
} else if (!strcmp(ftype, "VREG") ||
!strcmp(ftype, "GDIR") ||
!strcmp(ftype, "GREG") ||
!strcmp(ftype, "VCHR") ||
!strcmp(ftype, "VBLK") ||
!strcmp(ftype, "DIR") ||
!strcmp(ftype, "LINK") ||
!strcmp(ftype, "REG") ||
!strcmp(ftype, "VDIR")) {
entry.type = GLIBTOP_FILE_TYPE_FILE;
g_strlcpy(entry.info.file.name, fname,
sizeof(entry.info.file.name));
} else if (!strcmp(ftype, "IPv4")) {
char **hosts;
char **remote_host;
if (!strstr(fname, "->")) {
remote_host = g_strsplit(fname, ":", 0);
} else {
hosts = g_strsplit(fname, "->", 0);
if (g_strv_length(hosts) < 2) {
g_strfreev(hosts);
continue;
}
remote_host = g_strsplit(hosts[1], ":", 0);
g_strfreev(hosts);
}
if (g_strv_length(remote_host) < 2) {
g_strfreev(remote_host);
continue;
}
entry.type = GLIBTOP_FILE_TYPE_INETSOCKET;
if (!strcmp(remote_host[0], "*"))
g_strlcpy(entry.info.sock.dest_host, "0.0.0.0",
sizeof(entry.info.sock.dest_host));
else
g_strlcpy(entry.info.sock.dest_host,
remote_host[0],
sizeof(entry.info.sock.dest_host));
entry.info.sock.dest_port = atoi(remote_host[1]);
g_strfreev(remote_host);
} else
continue;
entry.fd = fd;
fd = -1;
ftype = NULL;
fname = NULL;
g_array_append_val(entries, entry);
}
g_strfreev(lines);
return entries;
}
/* XXX Unimplemented on FreeBSD */
glibtop_open_files_entry *
glibtop_get_proc_open_files_s (glibtop *server, glibtop_proc_open_files *buf, pid_t pid)
{
return NULL;
char *output;
GArray *entries;
memset(buf, 0, sizeof (glibtop_proc_open_files));
output = execute_lsof(pid);
if (output == NULL) return NULL;
entries = parse_output(output);
g_free(output);
buf->flags = _glibtop_sysdeps_proc_open_files;
buf->number = entries->len;
buf->size = sizeof(glibtop_open_files_entry);
buf->total = buf->number * buf->size;
return (glibtop_open_files_entry*)g_array_free(entries, FALSE);
}

121
sysdeps/freebsd/procwd.c Normal file
View File

@@ -0,0 +1,121 @@
/* Copyright (C) 2007 Joe Marcus Clarke
This file is part of LibGTop 2.
LibGTop is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
LibGTop is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LibGTop; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include <glibtop/procwd.h>
#include <glibtop/error.h>
#include <glibtop_private.h>
#include <sys/types.h>
#include <sys/param.h>
#include <string.h>
static const unsigned long _glibtop_sysdeps_proc_wd =
(1 << GLIBTOP_PROC_WD_EXE) |
(1 << GLIBTOP_PROC_WD_ROOT) |
(1 << GLIBTOP_PROC_WD_NUMBER);
void
_glibtop_init_proc_wd_s(glibtop *server)
{
server->sysdeps.proc_wd = _glibtop_sysdeps_proc_wd;
}
static GPtrArray *
parse_output(const char *output, glibtop_proc_wd *buf)
{
GPtrArray *dirs;
char **lines;
gboolean nextwd = FALSE;
gboolean nextrtd = FALSE;
gboolean havertd = FALSE;
guint i;
guint len;
dirs = g_ptr_array_sized_new(1);
lines = g_strsplit(output, "\n", 0);
len = g_strv_length(lines);
for (i = 0; i < len && lines[i]; i++) {
if (strlen(lines[i]) < 2)
continue;
if (!strcmp(lines[i], "fcwd")) {
nextwd = TRUE;
continue;
}
if (!strcmp(lines[i], "frtd")) {
nextrtd = TRUE;
continue;
}
if (!g_str_has_prefix(lines[i], "n"))
continue;
if (nextwd) {
g_ptr_array_add(dirs, g_strdup(lines[i] + 1));
nextwd = FALSE;
}
if (nextrtd && !havertd) {
g_strlcpy(buf->root, lines[i] + 1,
sizeof(buf->root));
buf->flags |= (1 << GLIBTOP_PROC_WD_ROOT);
nextrtd = FALSE;
havertd = TRUE;
}
}
g_strfreev(lines);
return dirs;
}
char**
glibtop_get_proc_wd_s(glibtop *server, glibtop_proc_wd *buf, pid_t pid)
{
char path[MAXPATHLEN];
char *output;
memset (buf, 0, sizeof (glibtop_proc_wd));
g_snprintf(path, sizeof(path), "/proc/%u/file", pid);
if (safe_readlink(path, buf->exe, sizeof(buf->exe)))
buf->flags |= (1 << GLIBTOP_PROC_WD_EXE);
output = execute_lsof(pid);
if (output != NULL) {
GPtrArray *dirs;
dirs = parse_output(output, buf);
g_free(output);
buf->number = dirs->len;
buf->flags |= (1 << GLIBTOP_PROC_WD_NUMBER);
g_ptr_array_add(dirs, NULL);
return (char **)g_ptr_array_free(dirs, FALSE);
}
return NULL;
}

View File

@@ -8,8 +8,7 @@ libgtop_sysdeps_2_0_la_SOURCES = open.c close.c cpu.c mem.c swap.c \
proctime.c procmem.c procsignal.c prockernel.c \
procsegment.c procargs.c procmap.c siglist.c \
sysinfo.c netload.c ppp.c glibtop_private.c \
fsusage.c netlist.c procopenfiles.c procwd.c \
procaffinity.c
fsusage.c netlist.c procopenfiles.c procwd.c
libgtop_sysdeps_2_0_la_LIBADD = @GLIB_LIBS@

View File

@@ -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

View File

@@ -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;

View File

@@ -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");

View File

@@ -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);
}

View File

@@ -43,7 +43,6 @@
#define GLIBTOP_SUID_NETLOAD 0
#define GLIBTOP_SUID_NETLIST 0
#define GLIBTOP_SUID_PROC_WD 0
#define GLIBTOP_SUID_PROC_AFFINITY 0
#define GLIBTOP_SUID_PPP 0
#define GLIBTOP_SUID_PROC_FILE 0

View File

@@ -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);

View File

@@ -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:");

View File

@@ -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))

View File

@@ -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 */

View File

@@ -1,69 +0,0 @@
/* Copyright (C) 2007 Benoît Dejean
This file is part of LibGTop 2.
LibGTop is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
LibGTop is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LibGTop; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include <glibtop/procaffinity.h>
#include <glibtop/error.h>
#include <glibtop_private.h>
#include <sched.h>
void
_glibtop_init_proc_affinity_s(glibtop *server)
{
server->sysdeps.proc_affinity =
(1 << GLIBTOP_PROC_AFFINITY_NUMBER) |
(1 << GLIBTOP_PROC_AFFINITY_ALL);
}
guint16 *
glibtop_get_proc_affinity_s(glibtop *server, glibtop_proc_affinity *buf, pid_t pid)
{
cpu_set_t set;
size_t i;
GArray* cpus;
memset(buf, 0, sizeof *buf);
if (sched_getaffinity(pid, sizeof set, &set) == -1) {
glibtop_error_r(server, "sched_getaffinity failed");
return NULL;
}
cpus = g_array_new(FALSE, FALSE, sizeof(guint16));
for (i = 0; i < MIN(CPU_SETSIZE, (size_t)(server->ncpu + 1)); i++) {
if (CPU_ISSET(i, &set)) {
guint16 n = i;
g_array_append_val(cpus, n);
}
}
buf->number = cpus->len;
buf->all = (cpus->len == (size_t)(server->ncpu + 1));
buf->flags = (1 << GLIBTOP_PROC_AFFINITY_NUMBER)
| (1 << GLIBTOP_PROC_AFFINITY_ALL);
return (guint16*) g_array_free(cpus, FALSE);
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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");

View File

@@ -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);

View File

@@ -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);