libgtop r2741 - trunk/sysdeps/linux
- From: bdejean svn gnome org
- To: svn-commits-list gnome org
- Subject: libgtop r2741 - trunk/sysdeps/linux
- Date: Mon, 28 Apr 2008 17:20:56 +0100 (BST)
Author: bdejean
Date: Mon Apr 28 16:20:56 2008
New Revision: 2741
URL: http://svn.gnome.org/viewvc/libgtop?rev=2741&view=rev
Log:
Fixed parsing of big /proc/stat for uptime.
Modified:
trunk/sysdeps/linux/glibtop_private.c
Modified: trunk/sysdeps/linux/glibtop_private.c
==============================================================================
--- trunk/sysdeps/linux/glibtop_private.c (original)
+++ trunk/sysdeps/linux/glibtop_private.c Mon Apr 28 16:20:56 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]