Reverted some stuff from 06-07-1998 since it was too buggy.

1998-06-18  Martin Baulig  <baulig@taurus.uni-trier.de>

	* sysdeps/linux/*.c: Reverted some stuff from 06-07-1998
	since it was too buggy.
This commit is contained in:
Martin Baulig
1998-06-18 19:02:49 +00:00
committed by Martin Baulig
parent 3fcc477b25
commit 1b90ed4fcc
11 changed files with 117 additions and 280 deletions

View File

@@ -44,17 +44,10 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
buf->flags = _glibtop_sysdeps_cpu;
#ifdef GLIBTOP_CACHE_OPEN
fd = server->machine.fd_stat;
#endif
if (fd == 0) {
fd = open (FILENAME, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
FILENAME, strerror (errno));
} else {
lseek (fd, 0, SEEK_SET);
}
ret = read (fd, buffer, BUFSIZ);
if (ret == -1)
@@ -63,6 +56,7 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
tmp = strchr (buffer, '\n');
tmp = skip_token (tmp); /* "cpu" */
buf->user = strtoul (tmp, &tmp, 10);
buf->nice = strtoul (tmp, &tmp, 10);
buf->sys = strtoul (tmp, &tmp, 10);
@@ -71,10 +65,5 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
buf->total = buf->user + buf->nice + buf->sys + buf->idle;
buf->frequency = 100;
#ifdef GLIBTOP_CACHE_OPEN
server->machine.fd_stat = fd;
#else
close (fd);
#endif
}

View File

@@ -42,17 +42,10 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
buf->flags = _glibtop_sysdeps_loadavg;
#ifdef GLIBTOP_CACHE_OPEN
fd = server->machine.fd_loadavg;
#endif
if (fd == 0) {
fd = open (FILENAME, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
FILENAME, strerror (errno));
} else {
lseek (fd, 0, SEEK_SET);
}
ret = read (fd, buffer, BUFSIZ);
if (ret == -1)
@@ -63,9 +56,5 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
buf->loadavg [1] = strtod (tmp, &tmp);
buf->loadavg [2] = strtod (tmp, &tmp);
#ifdef GLIBTOP_CACHE_OPEN
server->machine.fd_loadavg = fd;
#else
close (fd);
#endif
}

View File

@@ -45,17 +45,10 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
buf->flags = _glibtop_sysdeps_mem;
#ifdef GLIBTOP_CACHE_OPEN
fd = server->machine.fd_meminfo;
#endif
if (fd == 0) {
fd = open (FILENAME, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
FILENAME, strerror (errno));
} else {
lseek (fd, 0, SEEK_SET);
}
ret = read (fd, buffer, BUFSIZ);
if (ret == -1)
@@ -75,9 +68,5 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
buf->user = buf->total - buf->free - buf->shared - buf->buffer;
#ifdef GLIBTOP_CACHE_OPEN
server->machine.fd_meminfo = fd;
#else
close (fd);
#endif
}

View File

@@ -47,20 +47,6 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
return;
}
if (pid != server->machine.last_pid) {
server->machine.last_pid = pid;
server->machine.no_update = 0;
}
if (!server->machine.no_update) {
server->machine.proc_status [0] = 0;
server->machine.proc_statm [0] = 0;
server->machine.proc_stat [0] = 0;
}
if (server->machine.proc_stat [0]) {
strcpy (buffer, server->machine.proc_stat);
} else {
sprintf (input, "/proc/%d/stat", pid);
fd = open (input, O_RDONLY);
@@ -74,9 +60,7 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
input, strerror (errno));
buffer [nread] = 0;
strcpy (server->machine.proc_stat, buffer);
close (fd);
}
/* This is from guile-utils/gtop/proc/readproc.c */

View File

@@ -46,20 +46,6 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
return;
}
if (pid != server->machine.last_pid) {
server->machine.last_pid = pid;
server->machine.no_update = 0;
}
if (!server->machine.no_update) {
server->machine.proc_status [0] = 0;
server->machine.proc_statm [0] = 0;
server->machine.proc_stat [0] = 0;
}
if (server->machine.proc_stat [0]) {
strcpy (buffer, server->machine.proc_stat);
} else {
sprintf (input, "/proc/%d/stat", pid);
fd = open (input, O_RDONLY);
@@ -73,9 +59,7 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
input, strerror (errno));
buffer [nread] = 0;
strcpy (server->machine.proc_stat, buffer);
close (fd);
}
/* This is from guile-utils/gtop/proc/readproc.c */
@@ -88,9 +72,6 @@ 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);
if (server->machine.proc_statm [0]) {
strcpy (buffer, server->machine.proc_statm);
} else {
sprintf (input, "/proc/%d/statm", pid);
fd = open (input, O_RDONLY);
@@ -104,9 +85,7 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
input, strerror (errno));
buffer [nread] = 0;
strcpy (server->machine.proc_statm, buffer);
close (fd);
}
sscanf (buffer, "%ld %ld %ld",
&buf->size, &buf->resident, &buf->share);

View File

@@ -48,20 +48,6 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
return;
}
if (pid != server->machine.last_pid) {
server->machine.last_pid = pid;
server->machine.no_update = 0;
}
if (!server->machine.no_update) {
server->machine.proc_status [0] = 0;
server->machine.proc_statm [0] = 0;
server->machine.proc_stat [0] = 0;
}
if (server->machine.proc_stat [0]) {
strcpy (buffer, server->machine.proc_stat);
} else {
sprintf (input, "/proc/%d/stat", pid);
fd = open (input, O_RDONLY);
@@ -75,9 +61,7 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
input, strerror (errno));
buffer [nread] = 0;
strcpy (server->machine.proc_stat, buffer);
close (fd);
}
/* This is from guile-utils/gtop/proc/readproc.c */
@@ -91,9 +75,6 @@ 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);
if (server->machine.proc_statm [0]) {
strcpy (buffer, server->machine.proc_statm);
} else {
sprintf (input, "/proc/%d/statm", pid);
fd = open (input, O_RDONLY);
@@ -107,9 +88,7 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
input, strerror (errno));
buffer [nread] = 0;
strcpy (server->machine.proc_statm, buffer);
close (fd);
}
sscanf (buffer, "%*d %*d %*d %ld %ld %ld %ld",
&buf->trs, &buf->lrs, &buf->drs, &buf->dt);

View File

@@ -45,20 +45,6 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
return;
}
if (pid != server->machine.last_pid) {
server->machine.last_pid = pid;
server->machine.no_update = 0;
}
if (!server->machine.no_update) {
server->machine.proc_status [0] = 0;
server->machine.proc_statm [0] = 0;
server->machine.proc_stat [0] = 0;
}
if (server->machine.proc_stat [0]) {
strcpy (buffer, server->machine.proc_stat);
} else {
sprintf (input, "/proc/%d/stat", pid);
fd = open (input, O_RDONLY);
@@ -72,9 +58,7 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
input, strerror (errno));
buffer [nread] = 0;
strcpy (server->machine.proc_stat, buffer);
close (fd);
}
/* This is from guile-utils/gtop/proc/readproc.c */

View File

@@ -48,12 +48,6 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
return;
}
server->machine.last_pid = pid;
server->machine.no_update = 0;
server->machine.proc_status [0] = 0;
server->machine.proc_statm [0] = 0;
server->machine.proc_stat [0] = 0;
sprintf (input, "/proc/%d/stat", pid);
/* IMPORTANT NOTICE: For security reasons it is extremely important
@@ -80,9 +74,6 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
buffer [nread] = 0;
server->machine.last_pid = pid;
strcpy (server->machine.proc_stat, buffer);
/* This is from guile-utils/gtop/proc/readproc.c */
/* split into "PID (cmd" and "<rest>" */

View File

@@ -47,20 +47,6 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
return;
}
if (pid != server->machine.last_pid) {
server->machine.last_pid = pid;
server->machine.no_update = 0;
}
if (!server->machine.no_update) {
server->machine.proc_status [0] = 0;
server->machine.proc_statm [0] = 0;
server->machine.proc_stat [0] = 0;
}
if (server->machine.proc_stat [0]) {
strcpy (buffer, server->machine.proc_stat);
} else {
sprintf (input, "/proc/%d/stat", pid);
fd = open (input, O_RDONLY);
@@ -74,9 +60,7 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
input, strerror (errno));
buffer [nread] = 0;
strcpy (server->machine.proc_stat, buffer);
close (fd);
}
/* This is from guile-utils/gtop/proc/readproc.c */

View File

@@ -51,20 +51,6 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
return;
}
if (pid != server->machine.last_pid) {
server->machine.last_pid = pid;
server->machine.no_update = 0;
}
if (!server->machine.no_update) {
server->machine.proc_status [0] = 0;
server->machine.proc_statm [0] = 0;
server->machine.proc_stat [0] = 0;
}
if (server->machine.proc_status [0]) {
strcpy (buffer, server->machine.proc_status);
} else {
sprintf (input, "/proc/%d/status", pid);
fd = open (input, O_RDONLY);
@@ -78,9 +64,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
input, strerror (errno));
buffer [nread] = 0;
strcpy (server->machine.proc_status, buffer);
close (fd);
}
/* Search substring 'Pid:' */
@@ -92,9 +76,6 @@ 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);
if (server->machine.proc_stat [0]) {
strcpy (buffer, server->machine.proc_stat);
} else {
sprintf (input, "/proc/%d/stat", pid);
fd = open (input, O_RDONLY);
@@ -108,9 +89,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
input, strerror (errno));
buffer [nread] = 0;
strcpy (server->machine.proc_stat, buffer);
close (fd);
}
/* This is from guile-utils/gtop/proc/readproc.c */

View File

@@ -43,17 +43,10 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
buf->flags = _glibtop_sysdeps_swap;
#ifdef GLIBTOP_CACHE_OPEN
fd = server->machine.fd_meminfo;
#endif
if (fd == 0) {
fd = open (FILENAME, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
FILENAME, strerror (errno));
} else {
lseek (fd, 0, SEEK_SET);
}
ret = read (fd, buffer, BUFSIZ);
if (ret == -1)
@@ -64,13 +57,10 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
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);
#ifdef GLIBTOP_CACHE_OPEN
server->machine.fd_meminfo = fd;
#else
close (fd);
#endif
}