version 2.6.1

* configure.in: version 2.6.1
This commit is contained in:
Benoît Dejean
2004-07-11 21:01:27 +00:00
parent de7fd9e85b
commit c73d0eb3c9
54 changed files with 731 additions and 648 deletions

View File

@@ -1,48 +1,3 @@
2004-07-07 Benoît Dejean <tazforever@dlfp.org>
* procargs.c: (glibtop_get_proc_args_s): Fixed. error is now correctly
set to NULL before is's used. Fixed max_len behaviour.
2004-07-03 Benoît Dejean <tazforever@dlfp.org>
* sysinfo.c: (init_sysinfo): Removed useless memset.
2004-07-03 Benoît Dejean <tazforever@dlfp.org>
* glibtop_server.h:
* glibtop_server.c: (try_file_to_buffer), (file_to_buffer): Added. These
functions are commonly used. Misc cleanups.
* cpu.c: (glibtop_get_cpu_s):
* loadavg.c: (glibtop_get_loadavg_s):
* mem.c: (glibtop_get_mem_s):
* open.c: (glibtop_open_s):
* swap.c: (glibtop_get_swap_s):
* sysinfo.c: (init_sysinfo):
* uptime.c: (glibtop_get_uptime_s): Replaced open/read/close by file_to_buffer().
2004-06-18 Benoît Dejean <tazforever@dlfp.org>
* loadavg.c: (glibtop_get_loadavg_s): Whitespace cleanup.
* ppp.c: (get_ISDN_stats), (is_ISDN_on): Replace g_malloc by an
array.
* glibtop_server.c: (get_pageshift):
* glibtop_server.h:
* procmem.c: (glibtop_init_proc_mem_s), (glibtop_get_proc_mem_s):
* procsegment.c: (glibtop_init_proc_segment_s),
(glibtop_get_proc_segment_s): Moved the pageshift calculation to
glibtop_server.[ch]
* procstate.c: (glibtop_get_proc_state_s):
* procuid.c: (glibtop_get_proc_uid_s):
* sysinfo.c: (init_sysinfo): Minor cleanups.
2004-06-18 Benoît Dejean <tazforever@dlfp.org>
* netload.c: (glibtop_get_netload_s): Implemented new IPv6 feature.
2004-06-13 Benoît Dejean <tazforever@dlfp.org>
* procargs.c: (glibtop_get_proc_args_s): Replaced by g_file_get_contents.
@@ -51,8 +6,8 @@
* glibtop_server.h:
* glibtop_server.c: (get_scaled): Cleaned.
(proc_file_to_buffer): Uninlined.
(proc_file_to_buffer): Uninlined.
* sysinfo.c: (init_sysinfo): Re-implemented.
Fixed segfault on SMP.
Stores keys in cpuinfo->labels.
@@ -61,21 +16,21 @@
* Makefile.am:
* glibtop_server.c: Added to repository.
* glibtop_server.h: (get_scaled): Uninlined and moved it to glibtop_server.c.
(skip_token) : Fixed indentation.
(skip_token) : Fixed indentation.
* procmap.c: (glibtop_get_proc_map_s): Big cleanup. Better allocation
algorithm.
* procmem.c:
* procsegment.c: Added missing initializations.
* sem_limits.c:
* shm_limits.c: (glibtop_get_shm_limits_s):
* swap.c:
* uptime.c: Added missing const qualifiers.
* sysinfo.c: (init_sysinfo): Added missing 0 initialization.
Saved 1 gboolean :D.
@@ -108,7 +63,7 @@
* glibtop_server.h:
* open.c:
* procuid.c: Moved LINUX_VERSION macro to glibtop_server.h.
* Changelog: Converted to UTF-8.
2004-05-19 Benoît Dejean <TazForEver@dlfp.org>
@@ -132,7 +87,7 @@
the file (Closes: #126504)
2004-02-02 Sebastien Bacher <seb128@debian.org>
* sysdeps/linux/mem.c: (glibtop_get_mem_s): patch from
Benoît Dejean <bnet@ifrance.com> to fix libtop_mem.used
and glibtop_mem.shared values (Closes: #129863).
@@ -279,7 +234,7 @@
* netload.c (glibtop_get_netload_s): Added implementation
for this function.
The code here is smart enough to use /proc/net/ip_acct if
IP accounting is enabled in the kernel and activated on the
requested device and /proc/net/dev if not.

View File

@@ -54,13 +54,24 @@ void
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
{
char buffer [BUFSIZ], *p;
int fd, len;
int i;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
memset (buf, 0, sizeof (glibtop_cpu));
file_to_buffer(server, buffer, FILENAME);
fd = open (FILENAME, O_RDONLY);
if (fd < 0)
glibtop_error_io_r (server, "open (%s)", FILENAME);
len = read (fd, buffer, BUFSIZ-1);
if (len < 0)
glibtop_error_io_r (server, "read (%s)", FILENAME);
close (fd);
buffer [len] = '\0';
/*
* GLOBAL

View File

@@ -1,17 +1,12 @@
#include <glibtop.h>
#include <glibtop/error.h>
#include <glib.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
/* gcc warning bug */
unsigned get_pageshift();
unsigned long long
get_scaled(const char *buffer, const char *key)
@@ -33,73 +28,25 @@ get_scaled(const char *buffer, const char *key)
}
/*
* Read functions
*/
enum TRY_FILE_TO_BUFFER
int
proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid)
{
TRY_FILE_TO_BUFFER_OK = 0,
TRY_FILE_TO_BUFFER_OPEN = -1,
TRY_FILE_TO_BUFFER_READ = -2
};
int try_file_to_buffer(char *buffer, const char *format, ...)
{
char path[4096];
char filename [256];
int fd;
ssize_t len;
va_list pa;
va_start(pa, format);
g_snprintf (filename, sizeof filename, fmt, pid);
/* C99 also provides vsnprintf */
g_vsnprintf(path, sizeof path, format, pa);
va_end(pa);
if((fd = open (path, O_RDONLY)) < 0)
return TRY_FILE_TO_BUFFER_OPEN;
fd = open (filename, O_RDONLY);
if (fd < 0) return -1;
len = read (fd, buffer, BUFSIZ-1);
close (fd);
if (len < 0)
return TRY_FILE_TO_BUFFER_READ;
if (len < 0) return -1;
buffer [len] = '\0';
return TRY_FILE_TO_BUFFER_OK;
return 0;
}
void
file_to_buffer(glibtop *server, char *buffer, const char *filename)
{
switch(try_file_to_buffer(buffer, filename))
{
case TRY_FILE_TO_BUFFER_OPEN:
glibtop_error_io_r (server, "open (%s)", filename);
case TRY_FILE_TO_BUFFER_READ:
glibtop_error_io_r (server, "read (%s)", filename);
}
}
#warning "Ignore the following warning"
unsigned get_pageshift()
{
static unsigned pageshift = 0;
if(G_UNLIKELY(!pageshift))
{
register unsigned pagesize = getpagesize();
while( pagesize > 1 )
{
pagesize >>= 1;
pageshift++;
}
}
return pageshift;
}

View File

@@ -21,16 +21,12 @@
Boston, MA 02111-1307, USA.
*/
#ifndef __LINUX__GLIBTOP_SERVER_H__
#define __LINUX__GLIBTOP_SERVER_H__
#ifndef __GLIBTOP_SERVER_H__
#define __GLIBTOP_SERVER_H__
#include <glibtop.h>
#include <glib.h>
#include <fcntl.h>
#include <ctype.h>
#include <string.h>
G_BEGIN_DECLS
@@ -38,10 +34,6 @@ G_BEGIN_DECLS
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
unsigned get_pageshift();
static inline char *
skip_token (const char *p)
{
@@ -59,7 +51,6 @@ skip_multiple_token (const char *p, size_t count)
return (char *)p;
}
static inline char *
skip_line (const char *p)
{
@@ -67,29 +58,12 @@ skip_line (const char *p)
return (char *) (*p ? p+1 : p);
}
unsigned long long
get_scaled(const char *buffer, const char *key);
/* aborts on error */
void
file_to_buffer(glibtop *server, char *buffer, const char *filename);
/* return < 0 on error, otherwise 0 on success */
int
try_file_to_buffer(char *buffer, const char *format, ...);
/* some inline functions that wrap proc path
* as fast as macros :)
*/
static inline int
proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid)
{
return try_file_to_buffer(buffer, fmt, pid);
}
proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid);
static inline int
proc_stat_to_buffer (char *buffer, pid_t pid)
@@ -109,13 +83,13 @@ proc_statm_to_buffer (char *buffer, pid_t pid)
return proc_file_to_buffer (buffer, "/proc/%d/statm", pid);
}
static inline char *
proc_stat_after_cmd (char *p)
{
p = strrchr (p, ')');
if (G_LIKELY(p))
*p++ = '\0';
if (!p) return p;
*p++ = '\0';
return p;
}
@@ -144,4 +118,4 @@ proc_stat_after_cmd (char *p)
G_END_DECLS
#endif /* __LINUX__GLIBTOP_SERVER_H__ */
#endif

View File

@@ -49,12 +49,23 @@ void
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
{
char buffer [BUFSIZ], *p, *old;
int fd, len;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_LOADAVG, 0);
memset (buf, 0, sizeof (glibtop_loadavg));
file_to_buffer(server, buffer, FILENAME);
fd = open (FILENAME, O_RDONLY);
if (fd < 0)
glibtop_error_io_r (server, "open (%s)", FILENAME);
len = read (fd, buffer, BUFSIZ-1);
if (len < 0)
glibtop_error_io_r (server, "read (%s)", FILENAME);
close (fd);
buffer [len] = '\0';
buf->loadavg [0] = strtod (buffer, &p);
buf->loadavg [1] = strtod (p, &p);
@@ -62,12 +73,12 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
buf->flags = _glibtop_sysdeps_loadavg;
while (isspace(*p)) p++;
while (isspace(*p)) p++;
/* Older Linux versions don't have the nr_running/nr_tasks fields. */
old = p;
while (*p) {
while (*p) {
if (*p == '/')
break;
if (!isdigit (*p))

View File

@@ -47,10 +47,23 @@ void
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{
char buffer [BUFSIZ];
int fd, len;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
file_to_buffer(server, buffer, FILENAME);
memset (buf, 0, sizeof (glibtop_mem));
fd = open (FILENAME, O_RDONLY);
if (fd < 0)
glibtop_error_io_r (server, "open (%s)", FILENAME);
len = read (fd, buffer, BUFSIZ-1);
if (len < 0)
glibtop_error_io_r (server, "read (%s)", FILENAME);
close (fd);
buffer [len] = '\0';
buf->total = get_scaled(buffer, "MemTotal:");
buf->free = get_scaled(buffer, "MemFree:");
@@ -59,6 +72,6 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
buf->buffer = get_scaled(buffer, "Buffers:");
buf->cached = get_scaled(buffer, "Cached:");
buf->user = buf->total - buf->free - buf->cached - buf->buffer;
buf->flags = _glibtop_sysdeps_mem;
buf->user = buf->total - buf->free - buf->cached - buf->buffer;
buf->flags = _glibtop_sysdeps_mem;
}

View File

@@ -47,17 +47,6 @@
#include <linux/udp.h>
#endif
/* IPV6 */
#include <ifaddrs.h>
#ifndef IN6_IS_ADDR_GLOBAL
#define IN6_IS_ADDR_GLOBAL(a) \
(((((__const uint8_t *) (a))[0] & 0xff) == 0x3f \
|| (((__const uint8_t *) (a))[0] & 0xff) == 0x20))
#endif
/* IPV6 */
#define _GLIBTOP_IP_FW_ACCTIN 0x1000 /* Account incoming packets only. */
#define _GLIBTOP_IP_FW_ACCTOUT 0x2000 /* Account outgoing packets only. */
@@ -97,11 +86,6 @@ static const unsigned long _glibtop_sysdeps_netload_out =
(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
(1L << GLIBTOP_NETLOAD_BYTES_OUT);
static const unsigned long _glibtop_sysdeps_netload_6 =
(1L << GLIBTOP_NETLOAD_ADDRESS6) +
(1L << GLIBTOP_NETLOAD_PREFIX6) +
(1L << GLIBTOP_NETLOAD_SCOPE6);
/* Init function. */
void
@@ -330,8 +314,6 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
if (strcmp (dev, interface))
continue;
/* Ok, we've found the interface */
/* Only read byte counts if we really have them. */
if (have_bytes) {
@@ -366,56 +348,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
if (have_bytes)
buf->flags |= _glibtop_sysdeps_netload_bytes;
break; /* finished */
}
fclose (f);
/* IPv6 */
{
struct ifaddrs *ifa0, *ifr6;
getifaddrs (&ifa0);
for (ifr6 = ifa0; ifr6; ifr6 = ifr6->ifa_next) {
if (strcmp (ifr6->ifa_name, interface) == 0
&& ifr6->ifa_addr->sa_family == AF_INET6)
break;
}
if(!ifr6) return;
memcpy(buf->address6,
&((struct sockaddr_in6 *) ifr6->ifa_addr)->sin6_addr,
16);
memcpy(buf->prefix6,
&((struct sockaddr_in6 *) ifr6->ifa_netmask)->sin6_addr,
16);
if (IN6_IS_ADDR_LINKLOCAL (buf->address6))
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_LINK;
else if (IN6_IS_ADDR_SITELOCAL (buf->address6))
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_SITE;
else if (IN6_IS_ADDR_GLOBAL (buf->address6)
|| IN6_IS_ADDR_MC_ORGLOCAL (buf->address6)
|| IN6_IS_ADDR_V4COMPAT (buf->address6)
|| IN6_IS_ADDR_MULTICAST (buf->address6)
|| IN6_IS_ADDR_UNSPECIFIED (buf->address6)
)
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_GLOBAL;
else if (IN6_IS_ADDR_LOOPBACK (buf->address6))
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_HOST;
else
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_UNKNOWN;
buf->flags |= _glibtop_sysdeps_netload_6;
} /* IPV6 */
}

View File

@@ -66,12 +66,23 @@ glibtop_open_s (glibtop *server, const char *program_name,
const unsigned flags)
{
char buffer [BUFSIZ], *p = buffer;
int fd, len;
server->name = program_name;
server->os_version_code = get_linux_version();
file_to_buffer(server, buffer, FILENAME);
fd = open (FILENAME, O_RDONLY);
if (fd < 0)
glibtop_error_io_r (server, "open (%s)", FILENAME);
len = read (fd, buffer, BUFSIZ-1);
if (len < 0)
glibtop_error_io_r (server, "read (%s)", FILENAME);
close (fd);
buffer [len] = '\0';
for (server->ncpu = 0; server->ncpu < GLIBTOP_NCPU; server->ncpu++) {

View File

@@ -52,35 +52,40 @@ glibtop_init_ppp_s (glibtop *server)
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
}
static gboolean
static int
get_ISDN_stats (glibtop *server, int *in, int *out)
{
unsigned long isdn_stats[2 * ISDN_MAX_CHANNELS], *ptr;
int fd;
unsigned long *isdn_stats, *ptr;
int fd, i;
*in = *out = 0;
isdn_stats = g_malloc (ISDN_MAX_CHANNELS * 2 * sizeof (unsigned long));
fd = open ("/dev/isdninfo", O_RDONLY);
if (fd < 0) {
g_free (isdn_stats);
return FALSE;
}
if ((ioctl (fd, IIOCGETCPS, isdn_stats) < 0) && (errno != 0)) {
close(fd);
g_free (isdn_stats);
close (fd);
return FALSE;
}
for (ptr = isdn_stats;
ptr != (isdn_stats + G_N_ELEMENTS(isdn_stats));
/* NOOP */) {
for (i = 0, ptr = isdn_stats; i < ISDN_MAX_CHANNELS; i++) {
*in += *ptr++; *out += *ptr++;
}
g_free (isdn_stats);
close (fd);
return TRUE;
}
static gboolean is_ISDN_on (glibtop *server, int *online)
static int is_ISDN_on (glibtop *server, int *online)
{
FILE *f = 0;
char buffer [BUFSIZ], *p;

View File

@@ -42,11 +42,11 @@ char *
glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
pid_t pid, unsigned max_len)
{
char filename[48]; /* magiv */
char filename[48];
char *args;
gsize length;
GError *error = NULL;
GError *error;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_ARGS, 0);
@@ -55,14 +55,13 @@ glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
sprintf (filename, "/proc/%d/cmdline", pid);
if(!g_file_get_contents(filename, &args, &length, &error)) {
g_error_free(error);
buf->size = 0;
return NULL;
}
if(max_len && max_len < length) {
args = g_realloc(args, max_len);
args[max_len - 1] = '\0';
args = g_realloc(args, max_len+1);
args[max_len] = '\0';
length = max_len;
}

View File

@@ -33,14 +33,34 @@ static const unsigned long _glibtop_sysdeps_proc_mem_statm =
(1L << GLIBTOP_PROC_MEM_SIZE) + (1L << GLIBTOP_PROC_MEM_RESIDENT) +
(1L << GLIBTOP_PROC_MEM_SHARE);
#ifndef LOG1024
#define LOG1024 10
#endif
/* these are for getting the memory statistics */
static int pageshift = 0; /* log base 2 of the pagesize */
/* define pagetok in terms of pageshift */
#define pagetok(size) ((size) << pageshift)
/* Init function. */
void
glibtop_init_proc_mem_s (glibtop *server)
{
register int pagesize;
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem |
_glibtop_sysdeps_proc_mem_statm;
/* get the page size with "getpagesize" and calculate pageshift
* from it */
pagesize = getpagesize ();
pageshift = 0;
while (pagesize > 1) {
pageshift++;
pagesize >>= 1;
}
}
/* Provides detailed information about a process. */
@@ -49,7 +69,6 @@ void
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
{
char buffer [BUFSIZ], *p;
const unsigned pageshift = get_pageshift();
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);

View File

@@ -37,13 +37,34 @@ static const unsigned long _glibtop_sysdeps_proc_segment_statm =
(1L << GLIBTOP_PROC_SEGMENT_DATA_RSS) +
(1L << GLIBTOP_PROC_SEGMENT_DIRTY_SIZE);
#ifndef LOG1024
#define LOG1024 10
#endif
/* these are for getting the memory statistics */
static int pageshift = 0; /* log base 2 of the pagesize */
/* define pagetok in terms of pageshift */
#define pagetok(size) ((size) << pageshift)
/* Init function. */
void
glibtop_init_proc_segment_s (glibtop *server)
{
register int pagesize;
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment |
_glibtop_sysdeps_proc_segment_statm;
/* get the page size with "getpagesize" and calculate pageshift
* from it */
pagesize = getpagesize ();
pageshift = 0;
while (pagesize > 1) {
pageshift++;
pagesize >>= 1;
}
}
/* Provides detailed information about a process. */
@@ -53,7 +74,6 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
pid_t pid)
{
char buffer [BUFSIZ], *p;
const unsigned pageshift = get_pageshift();
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);

View File

@@ -83,7 +83,7 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
buf->state = p [2];
p = skip_token (buffer); p++; /* pid */
if (G_UNLIKELY(*p++ != '('))
if (*p++ != '(')
glibtop_error_r (server, "Bad data in /proc/%d/stat", pid);
g_strlcpy (buf->cmd, p, sizeof buf->cmd);

View File

@@ -117,7 +117,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
buf->priority = 2*15 - buf->priority;
buf->nice = 15 - buf->nice;
}
else if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
/* when tty wasn't full devno */
buf->tty = 4*0x100 + buf->tty;

View File

@@ -52,12 +52,23 @@ void
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
{
char buffer [BUFSIZ], *p;
int fd, len;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SWAP, 0);
memset (buf, 0, sizeof (glibtop_swap));
file_to_buffer(server, buffer, MEMINFO);
fd = open (MEMINFO, O_RDONLY);
if (fd < 0)
glibtop_error_io_r (server, "open (%s)", MEMINFO);
len = read (fd, buffer, BUFSIZ-1);
if (len < 0)
glibtop_error_io_r (server, "read (%s)", MEMINFO);
close (fd);
buffer [len] = '\0';
/* Kernel 2.6 with multiple lines */
@@ -67,7 +78,17 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
buf->flags = _glibtop_sysdeps_swap;
file_to_buffer(server, buffer, PROC_STAT);
fd = open (PROC_STAT, O_RDONLY);
if (fd < 0)
glibtop_error_io_r (server, "open (%s)", PROC_STAT);
len = read (fd, buffer, BUFSIZ-1);
if (len < 0)
glibtop_error_io_r (server, "read (%s)", PROC_STAT);
close (fd);
buffer [len] = '\0';
p = strstr (buffer, "\nswap");
if (p == NULL) return;

View File

@@ -36,13 +36,31 @@ static glibtop_sysinfo sysinfo = { .flags = 0 };
static void
init_sysinfo (glibtop *server)
{
int fd;
ssize_t len;
char buffer [BUFSIZ];
if(G_LIKELY(sysinfo.flags)) return;
if(sysinfo.flags) return;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
file_to_buffer(server, buffer, FILENAME);
memset (&sysinfo, 0, sizeof (glibtop_sysinfo));
/* load the file */
fd = open (FILENAME, O_RDONLY);
if (fd < 0)
glibtop_error_io_r (server, "open (%s)", FILENAME);
len = read (fd, buffer, BUFSIZ-1);
if (len < 0)
glibtop_error_io_r (server, "read (%s)", FILENAME);
close (fd);
buffer [len] = '\0';
/* cpuinfo records are seperated by a blank line */
gchar ** const processors = g_strsplit(buffer, "\n\n", 0);
@@ -79,7 +97,8 @@ init_sysinfo (glibtop *server)
/* the last key has no value and has not been added */
if(*p) g_free(*p);
if(*p)
g_free(*p);
/* just g_free instead of g_strvfree because we stole
the memory*/

View File

@@ -45,12 +45,23 @@ void
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
{
char buffer [BUFSIZ], *p;
int fd, len;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_UPTIME, 0);
memset (buf, 0, sizeof (glibtop_uptime));
file_to_buffer(server, buffer, FILENAME);
fd = open (FILENAME, O_RDONLY);
if (fd < 0)
glibtop_error_io_r (server, "open (%s)", FILENAME);
len = read (fd, buffer, BUFSIZ-1);
if (len < 0)
glibtop_error_io_r (server, "read (%s)", FILENAME);
close (fd);
buffer [len] = '\0';
buf->uptime = strtod (buffer, &p);
buf->idletime = strtod (p, &p);