No longer use `glibtop_machine.h' for Linux.

1998-07-03  Martin baulig  <martin@home-of-linux.org>

	* macros/gnome-libgtop-sysdeps.m4: No longer use
	`glibtop_machine.h' for Linux.

	* sysdeps/linux/glibtop_machine.h: Removed.

	* sysdeps/guile/guile.awk: Using `scm_append'
	instead of `gh_append'.

	* sysdeps/guile/names/guile-names.awk: dito.

	* sysdeps/linux/*.c: Using code from stable branch again.

	* include/glibtop/parameter.h: New file.

	* lib/parameter.c: New file.

	* lib/{open, init}.c: Done some more work on server
	initialization
This commit is contained in:
Martin baulig
1998-07-03 17:19:25 +00:00
committed by Martin Baulig
parent 94715ef718
commit 9532dadc2e
26 changed files with 557 additions and 355 deletions

View File

@@ -55,7 +55,7 @@ BEGIN {
print "";
print "\tif (ptr) {";
print "\t\tfor (i = 0; i < proclist.number; i++)";
print "\t\t\tlist = gh_append";
print "\t\t\tlist = scm_append";
print "\t\t\t\t(gh_list (list,";
print "\t\t\t\t\t gh_list (gh_ulong2scm ((unsigned long) ptr [i])),";
print "\t\t\t\t\t SCM_UNDEFINED));";

View File

@@ -22,7 +22,7 @@ function output(feature) {
print "\tlist = gh_list (SCM_UNDEFINED);";
print "";
print "\tfor (i = 0; i < GLIBTOP_MAX_"toupper(feature)"; i++)";
print "\t\tlist = gh_append";
print "\t\tlist = scm_append";
print "\t\t\t(gh_list (list,";
print "\t\t\t\t gh_list (gh_str02scm ((char *) glibtop_names_"feature" [i])),";
print "\t\t\t\t SCM_UNDEFINED));";
@@ -41,7 +41,7 @@ function output(feature) {
print "\tlist = gh_list (SCM_UNDEFINED);";
print "";
print "\tfor (i = 0; i < GLIBTOP_MAX_"toupper(feature)"; i++)";
print "\t\tlist = gh_append";
print "\t\tlist = scm_append";
print "\t\t\t(gh_list (list,";
print "\t\t\t\t gh_list (gh_ulong2scm (glibtop_types_"feature" [i])),";
print "\t\t\t\t SCM_UNDEFINED));";
@@ -60,7 +60,7 @@ function output(feature) {
print "\tlist = gh_list (SCM_UNDEFINED);";
print "";
print "\tfor (i = 0; i < GLIBTOP_MAX_"toupper(feature)"; i++)";
print "\t\tlist = gh_append";
print "\t\tlist = scm_append";
print "\t\t\t(gh_list (list,";
print "\t\t\t\t gh_list (gh_str02scm (gettext";
print "\t\t\t\t\t\t\t(glibtop_labels_"feature" [i]))),";
@@ -80,7 +80,7 @@ function output(feature) {
print "\tlist = gh_list (SCM_UNDEFINED);";
print "";
print "\tfor (i = 0; i < GLIBTOP_MAX_"toupper(feature)"; i++)";
print "\t\tlist = gh_append";
print "\t\tlist = scm_append";
print "\t\t\t(gh_list (list,";
print "\t\t\t\t gh_list (gh_str02scm (gettext";
print "\t\t\t\t\t\t\t(glibtop_descriptions_"feature" [i]))),";

View File

@@ -35,8 +35,7 @@ static const unsigned long _glibtop_sysdeps_cpu =
void
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
{
char buffer [BUFSIZ], *tmp;
int fd = 0, ret;
FILE *f;
glibtop_init_r (&server, 0, 0);
@@ -44,25 +43,15 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
buf->flags = _glibtop_sysdeps_cpu;
fd = open (FILENAME, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
FILENAME, strerror (errno));
f = fopen ("/proc/stat", "r");
if (!f) return;
ret = read (fd, buffer, BUFSIZ);
if (ret == -1)
glibtop_error_r (server, "read (%s): %s",
FILENAME, strerror (errno));
tmp = skip_token (buffer); /* "cpu" */
buf->user = strtoul (tmp, &tmp, 10);
buf->nice = strtoul (tmp, &tmp, 10);
buf->sys = strtoul (tmp, &tmp, 10);
buf->idle = strtoul (tmp, &tmp, 10);
fscanf (f, "cpu %lu %lu %lu %lu\n",
&buf->user, &buf->nice, &buf->sys, &buf->idle);
buf->total = buf->user + buf->nice + buf->sys + buf->idle;
buf->frequency = 100;
close (fd);
fclose (f);
}

View File

@@ -33,8 +33,7 @@ static const unsigned long _glibtop_sysdeps_loadavg =
void
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
{
char buffer [BUFSIZ], *tmp;
int fd = 0, ret;
FILE *f;
glibtop_init_r (&server, 0, 0);
@@ -42,19 +41,11 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
buf->flags = _glibtop_sysdeps_loadavg;
fd = open (FILENAME, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
FILENAME, strerror (errno));
f = fopen ("/proc/loadavg", "r");
if (!f) return;
ret = read (fd, buffer, BUFSIZ);
if (ret == -1)
glibtop_error_r (server, "read (%s): %s",
FILENAME, strerror (errno));
buf->loadavg [0] = strtod (buffer, &tmp);
buf->loadavg [1] = strtod (tmp, &tmp);
buf->loadavg [2] = strtod (tmp, &tmp);
close (fd);
fscanf (f, "%lf %lf %lf\n",
&buf->loadavg [0], &buf->loadavg [1], &buf->loadavg [2]);
fclose (f);
}

View File

@@ -36,8 +36,7 @@ static const unsigned long _glibtop_sysdeps_mem =
void
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{
char buffer [BUFSIZ], *tmp;
int fd = 0, ret;
FILE *f;
glibtop_init_r (&server, 0, 0);
@@ -45,28 +44,13 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
buf->flags = _glibtop_sysdeps_mem;
fd = open (FILENAME, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
FILENAME, strerror (errno));
f = fopen ("/proc/meminfo", "r");
if (!f) return;
ret = read (fd, buffer, BUFSIZ);
if (ret == -1)
glibtop_error_r (server, "read (%s): %s",
FILENAME, strerror (errno));
tmp = strchr (buffer, '\n');
tmp = skip_token (tmp); /* "Mem:" */
tmp = skip_token (tmp); /* total memory */
buf->total = strtoul (tmp, &tmp, 10);
buf->used = strtoul (tmp, &tmp, 10);
buf->free = strtoul (tmp, &tmp, 10);
buf->shared = strtoul (tmp, &tmp, 10);
buf->buffer = strtoul (tmp, &tmp, 10);
buf->cached = strtoul (tmp, &tmp, 10);
fscanf (f, "%*[^\n]\nMem: %lu %lu %lu %lu %lu %lu\n",
&buf->total, &buf->used, &buf->free, &buf->shared, &buf->buffer, &buf->cached);
buf->user = buf->total - buf->free - buf->shared - buf->buffer;
close (fd);
fclose (f);
}

View File

@@ -34,8 +34,9 @@ static const unsigned long _glibtop_sysdeps_proc_kernel =
void
glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
{
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
int fd = 0, nread;
char input [BUFSIZ], *tmp;
int nread;
FILE *f;
glibtop_init_r (&server, 0, 0);
@@ -48,24 +49,23 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
}
sprintf (input, "/proc/%d/stat", pid);
fd = open (input, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
input, strerror (errno));
nread = read (fd, buffer, BUFSIZ);
if (nread == -1)
glibtop_error_r (server, "read (%s): %s",
input, strerror (errno));
buffer [nread] = 0;
close (fd);
f = fopen (input, "r");
if (!f) return;
nread = fread (input, 1, BUFSIZ, f);
if (nread < 0) {
fclose (f);
return;
}
input [nread] = 0;
/* This is from guile-utils/gtop/proc/readproc.c */
/* split into "PID (cmd" and "<rest>" */
tmp = strrchr (buffer, ')');
tmp = strrchr (input, ')');
*tmp = '\0'; /* replace trailing ')' with NUL */
/* parse these two strings separately, skipping the leading "(". */
@@ -76,6 +76,8 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
&buf->k_flags, &buf->min_flt, &buf->cmin_flt,
&buf->maj_flt, &buf->cmaj_flt, &buf->kstk_esp,
&buf->kstk_eip, &buf->wchan);
fclose (f);
buf->flags = _glibtop_sysdeps_proc_kernel;
}

View File

@@ -33,8 +33,9 @@ static const unsigned long _glibtop_sysdeps_proc_mem =
void
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
{
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
int fd = 0, nread;
char input [BUFSIZ], *tmp;
int nread;
FILE *f;
glibtop_init_r (&server, 0, 0);
@@ -47,24 +48,23 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
}
sprintf (input, "/proc/%d/stat", pid);
fd = open (input, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
input, strerror (errno));
nread = read (fd, buffer, BUFSIZ);
if (nread == -1)
glibtop_error_r (server, "read (%s): %s",
input, strerror (errno));
buffer [nread] = 0;
close (fd);
f = fopen (input, "r");
if (!f) return;
nread = fread (input, 1, BUFSIZ, f);
if (nread < 0) {
fclose (f);
return;
}
input [nread] = 0;
/* This is from guile-utils/gtop/proc/readproc.c */
/* split into "PID (cmd" and "<rest>" */
tmp = strrchr (buffer, ')');
tmp = strrchr (input, ')');
*tmp = '\0'; /* replace trailing ')' with NUL */
/* parse these two strings separately, skipping the leading "(". */
sscanf(tmp + 2, /* skip space after ')' too */
@@ -72,23 +72,26 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
"%*d %*d %*d %*d %*d %*d %*u %*u %*d %lu "
"%lu %lu", &buf->vsize, &buf->rss, &buf->rss_rlim);
sprintf (input, "/proc/%d/statm", pid);
fd = open (input, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
input, strerror (errno));
nread = read (fd, buffer, BUFSIZ);
if (nread == -1)
glibtop_error_r (server, "read (%s): %s",
input, strerror (errno));
fclose (f);
buffer [nread] = 0;
close (fd);
sscanf (buffer, "%ld %ld %ld",
sprintf (input, "/proc/%d/statm", pid);
f = fopen (input, "r");
if (!f) return;
nread = fread (input, 1, BUFSIZ, f);
if (nread < 0) {
fclose (f);
return;
}
input [nread] = 0;
sscanf (input, "%ld %ld %ld",
&buf->size, &buf->resident, &buf->share);
fclose (f);
buf->flags = _glibtop_sysdeps_proc_mem;
}

View File

@@ -35,8 +35,9 @@ void
glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
pid_t pid)
{
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
int fd = 0, nread;
char input [BUFSIZ], *tmp;
int nread;
FILE *f;
glibtop_init_r (&server, 0, 0);
@@ -49,24 +50,23 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
}
sprintf (input, "/proc/%d/stat", pid);
fd = open (input, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
input, strerror (errno));
nread = read (fd, buffer, BUFSIZ);
if (nread == -1)
glibtop_error_r (server, "read (%s): %s",
input, strerror (errno));
buffer [nread] = 0;
close (fd);
f = fopen (input, "r");
if (!f) return;
nread = fread (input, 1, BUFSIZ, f);
if (nread < 0) {
fclose (f);
return;
}
input [nread] = 0;
/* This is from guile-utils/gtop/proc/readproc.c */
/* split into "PID (cmd" and "<rest>" */
tmp = strrchr (buffer, ')');
tmp = strrchr (input, ')');
*tmp = '\0'; /* replace trailing ')' with NUL */
/* parse these two strings separately, skipping the leading "(". */
sscanf(tmp + 2, /* skip space after ')' too */
@@ -75,23 +75,26 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
"%*u %*u %lu %lu %lu", &buf->start_code,
&buf->end_code, &buf->start_stack);
sprintf (input, "/proc/%d/statm", pid);
fd = open (input, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
input, strerror (errno));
nread = read (fd, buffer, BUFSIZ);
if (nread == -1)
glibtop_error_r (server, "read (%s): %s",
input, strerror (errno));
buffer [nread] = 0;
close (fd);
fclose (f);
sscanf (buffer, "%*d %*d %*d %ld %ld %ld %ld",
sprintf (input, "/proc/%d/statm", pid);
f = fopen (input, "r");
if (!f) return;
nread = fread (input, 1, BUFSIZ, f);
if (nread < 0) {
fclose (f);
return;
}
input [nread] = 0;
sscanf (input, "%*d %*d %*d %ld %ld %ld %ld",
&buf->trs, &buf->lrs, &buf->drs, &buf->dt);
fclose (f);
buf->flags = _glibtop_sysdeps_proc_segment;
}

View File

@@ -32,8 +32,9 @@ static const unsigned long _glibtop_sysdeps_proc_signal =
void
glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
{
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
int fd = 0, nread;
char input [BUFSIZ], *tmp;
int nread;
FILE *f;
glibtop_init_r (&server, 0, 0);
@@ -46,24 +47,23 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
}
sprintf (input, "/proc/%d/stat", pid);
fd = open (input, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
input, strerror (errno));
nread = read (fd, buffer, BUFSIZ);
if (nread == -1)
glibtop_error_r (server, "read (%s): %s",
input, strerror (errno));
buffer [nread] = 0;
close (fd);
f = fopen (input, "r");
if (!f) return;
nread = fread (input, 1, BUFSIZ, f);
if (nread < 0) {
fclose (f);
return;
}
input [nread] = 0;
/* This is from guile-utils/gtop/proc/readproc.c */
/* split into "PID (cmd" and "<rest>" */
tmp = strrchr (buffer, ')');
tmp = strrchr (input, ')');
*tmp = '\0'; /* replace trailing ')' with NUL */
/* parse these two strings separately, skipping the leading "(". */
sscanf(tmp + 2, /* skip space after ')' too */
@@ -73,5 +73,7 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
&buf->signal, &buf->blocked, &buf->sigignore,
&buf->sigcatch);
fclose (f);
buf->flags = _glibtop_sysdeps_proc_signal;
}

View File

@@ -34,9 +34,10 @@ static const unsigned long _glibtop_sysdeps_proc_state =
void
glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
{
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
char input [BUFSIZ], *tmp;
struct stat statb;
int fd, nread;
int nread;
FILE *f;
glibtop_init_r (&server, 0, 0);
@@ -61,30 +62,28 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
buf->uid = statb.st_uid;
buf->gid = statb.st_gid;
fd = open (input, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
input, strerror (errno));
nread = read (fd, buffer, BUFSIZ);
if (nread == -1)
glibtop_error_r (server, "read (%s): %s",
input, strerror (errno));
buffer [nread] = 0;
f = fopen (input, "r");
if (!f) return;
nread = fread (input, 1, BUFSIZ, f);
if (nread < 0) {
fclose (f);
return;
}
input [nread] = 0;
/* This is from guile-utils/gtop/proc/readproc.c */
/* split into "PID (cmd" and "<rest>" */
tmp = strrchr (buffer, ')');
tmp = strrchr (input, ')');
*tmp = '\0'; /* replace trailing ')' with NUL */
/* parse these two strings separately, skipping the leading "(". */
memset (buf->cmd, 0, sizeof (buf->cmd));
sscanf (buffer, "%d (%39c", &pid, buf->cmd);
sscanf (input, "%d (%39c", &pid, buf->cmd);
sscanf(tmp + 2, "%c", &buf->state); /* skip space after ')' too */
close (fd);
buf->flags = _glibtop_sysdeps_proc_state;
}

View File

@@ -34,8 +34,9 @@ static const unsigned long _glibtop_sysdeps_proc_time =
void
glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
{
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
int fd = 0, nread;
char input [BUFSIZ], *tmp;
int nread;
FILE *f;
glibtop_init_r (&server, 0, 0);
@@ -48,24 +49,23 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
}
sprintf (input, "/proc/%d/stat", pid);
fd = open (input, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
input, strerror (errno));
nread = read (fd, buffer, BUFSIZ);
if (nread == -1)
glibtop_error_r (server, "read (%s): %s",
input, strerror (errno));
buffer [nread] = 0;
close (fd);
f = fopen (input, "r");
if (!f) return;
nread = fread (input, 1, BUFSIZ, f);
if (nread < 0) {
fclose (f);
return;
}
input [nread] = 0;
/* This is from guile-utils/gtop/proc/readproc.c */
/* split into "PID (cmd" and "<rest>" */
tmp = strrchr (buffer, ')');
tmp = strrchr (input, ')');
*tmp = '\0'; /* replace trailing ')' with NUL */
/* parse these two strings separately, skipping the leading "(". */
sscanf(tmp + 2, /* skip space after ')' too */
@@ -74,5 +74,7 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
&buf->utime, &buf->stime, &buf->cutime, &buf->cstime,
&buf->timeout, &buf->it_real_value, &buf->start_time);
fclose (f);
buf->flags = _glibtop_sysdeps_proc_time;
}

View File

@@ -38,8 +38,9 @@ static const unsigned long _glibtop_sysdeps_proc_uid =
void
glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
{
char buffer [BUFSIZ], input [BUFSIZ], *tmp;
int fd = 0, nread;
char input [BUFSIZ], *tmp;
int nread;
FILE *f;
glibtop_init_r (&server, 0, 0);
@@ -52,23 +53,22 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
}
sprintf (input, "/proc/%d/status", pid);
fd = open (input, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
input, strerror (errno));
nread = read (fd, buffer, BUFSIZ);
if (nread == -1)
glibtop_error_r (server, "read (%s): %s",
input, strerror (errno));
buffer [nread] = 0;
close (fd);
f = fopen (input, "r");
if (!f) return;
nread = fread (input, 1, BUFSIZ, f);
if (nread < 0) {
fclose (f);
return;
}
input [nread] = 0;
/* Search substring 'Pid:' */
tmp = strstr (buffer, "Pid:");
tmp = strstr (input, "Pid:");
if (tmp == NULL) return;
@@ -76,25 +76,26 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
"Gid: %u %u %*u %*u\n", &buf->pid, &buf->ppid,
&buf->uid, &buf->euid, &buf->gid, &buf->egid);
fclose (f);
sprintf (input, "/proc/%d/stat", pid);
fd = open (input, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
input, strerror (errno));
nread = read (fd, buffer, BUFSIZ);
if (nread == -1)
glibtop_error_r (server, "read (%s): %s",
input, strerror (errno));
buffer [nread] = 0;
close (fd);
f = fopen (input, "r");
if (!f) return;
nread = fread (input, 1, BUFSIZ, f);
if (nread < 0) {
fclose (f);
return;
}
input [nread] = 0;
/* This is from guile-utils/gtop/proc/readproc.c */
/* split into "PID (cmd" and "<rest>" */
tmp = strrchr (buffer, ')');
tmp = strrchr (input, ')');
*tmp = '\0'; /* replace trailing ')' with NUL */
/* parse these two strings separately, skipping the leading "(". */
sscanf(tmp + 2, /* skip space after ')' too */
@@ -116,5 +117,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
/* when tty wasn't full devno */
buf->tty = 4*0x100 + buf->tty;
fclose (f);
buf->flags = _glibtop_sysdeps_proc_uid;
}

View File

@@ -34,8 +34,7 @@ static unsigned long _glibtop_sysdeps_swap =
void
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
{
char buffer [BUFSIZ], *tmp;
int fd = 0, ret;
FILE *f;
glibtop_init_r (&server, 0, 0);
@@ -43,24 +42,11 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
buf->flags = _glibtop_sysdeps_swap;
fd = open (FILENAME, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
FILENAME, strerror (errno));
f = fopen ("/proc/meminfo", "r");
if (!f) return;
ret = read (fd, buffer, BUFSIZ);
if (ret == -1)
glibtop_error_r (server, "read (%s): %s",
FILENAME, strerror (errno));
fscanf (f, "%*[^\n]\n%*[^\n]\nSwap: %lu %lu %lu\n",
&buf->total, &buf->used, &buf->free);
tmp = strchr (buffer, '\n');
tmp = strchr (tmp+1, '\n');
tmp = skip_token (tmp); /* "Swap:" */
buf->total = strtoul (tmp, &tmp, 10);
buf->used = strtoul (tmp, &tmp, 10);
buf->free = strtoul (tmp, &tmp, 10);
close (fd);
fclose (f);
}

View File

@@ -33,8 +33,7 @@ static unsigned long _glibtop_sysdeps_uptime =
void
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
{
int fd, ret;
char buffer [BUFSIZ];
FILE *f;
glibtop_init_r (&server, 0, 0);
@@ -42,17 +41,10 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
buf->flags = _glibtop_sysdeps_uptime;
fd = open (FILENAME, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
FILENAME, strerror (errno));
f = fopen ("/proc/uptime", "r");
if (!f) return;
ret = read (fd, buffer, BUFSIZ);
if (ret == -1)
glibtop_error_r (server, "read (%s): %s",
FILENAME, strerror (errno));
fscanf (f, "%lf %lf\n", &buf->uptime, &buf->idletime);
sscanf (buffer, "%lf %lf\n", &buf->uptime, &buf->idletime);
close (fd);
fclose (f);
}