libgtop r2742 - in branches/gnome-2-22: . sysdeps/linux
- From: bdejean svn gnome org
- To: svn-commits-list gnome org
- Subject: libgtop r2742 - in branches/gnome-2-22: . sysdeps/linux
- Date: Tue, 29 Apr 2008 18:57:01 +0100 (BST)
Author: bdejean
Date: Tue Apr 29 17:57:01 2008
New Revision: 2742
URL: http://svn.gnome.org/viewvc/libgtop?rev=2742&view=rev
Log:
Fixed parsing of big /proc/stat for uptime.
Closes #529946.
Modified:
branches/gnome-2-22/configure.in
branches/gnome-2-22/sysdeps/linux/glibtop_private.c
Modified: branches/gnome-2-22/configure.in
==============================================================================
--- branches/gnome-2-22/configure.in (original)
+++ branches/gnome-2-22/configure.in Tue Apr 29 17:57:01 2008
@@ -4,7 +4,7 @@
m4_define([libgtop_major_version], [2])
m4_define([libgtop_minor_version], [22])
-m4_define([libgtop_micro_version], [1])
+m4_define([libgtop_micro_version], [2])
m4_define([libgtop_version], [libgtop_major_version.libgtop_minor_version.libgtop_micro_version])
dnl increment if the interface has additions, changes, removals.
Modified: branches/gnome-2-22/sysdeps/linux/glibtop_private.c
==============================================================================
--- branches/gnome-2-22/sysdeps/linux/glibtop_private.c (original)
+++ branches/gnome-2-22/sysdeps/linux/glibtop_private.c Tue Apr 29 17:57:01 2008
@@ -119,20 +119,27 @@
static unsigned long
read_boot_time(glibtop *server)
{
- char buffer[BUFSIZ];
- char *btime;
-
- file_to_buffer(server, buffer, sizeof buffer, "/proc/stat");
-
- btime = strstr(buffer, "btime");
+ char* line = NULL;
+ size_t size = 0;
+ FILE* stat;
+ unsigned long btime = 0;
+
+ if (!(stat = fopen("/proc/stat", "r"))) {
+ glibtop_error_io_r(server, "fopen(\"/proc/stat\")");
+ goto out;
+ }
- if (!btime) {
- glibtop_warn_io_r(server, "cannot find btime in /proc/stat");
- return 0UL;
+ while (getline(&line, &size, stat) != -1) {
+ if (!strncmp(line, "btime", 5)) {
+ btime = strtoul(skip_token(line), NULL, 10);
+ break;
+ }
}
- btime = skip_token(btime);
- return strtoul(btime, NULL, 10);
+ free(line);
+ fclose(stat);
+out:
+ return btime;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]