Fixed parsing of big /proc/stat for uptime.
svn path=/trunk/; revision=2741
This commit is contained in:
@@ -119,20 +119,27 @@ file_to_buffer(glibtop *server, char *buffer, size_t bufsiz, const char *filenam
|
|||||||
static unsigned long
|
static unsigned long
|
||||||
read_boot_time(glibtop *server)
|
read_boot_time(glibtop *server)
|
||||||
{
|
{
|
||||||
char buffer[BUFSIZ];
|
char* line = NULL;
|
||||||
char *btime;
|
size_t size = 0;
|
||||||
|
FILE* stat;
|
||||||
|
unsigned long btime = 0;
|
||||||
|
|
||||||
file_to_buffer(server, buffer, sizeof buffer, "/proc/stat");
|
if (!(stat = fopen("/proc/stat", "r"))) {
|
||||||
|
glibtop_error_io_r(server, "fopen(\"/proc/stat\")");
|
||||||
btime = strstr(buffer, "btime");
|
goto out;
|
||||||
|
|
||||||
if (!btime) {
|
|
||||||
glibtop_warn_io_r(server, "cannot find btime in /proc/stat");
|
|
||||||
return 0UL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
btime = skip_token(btime);
|
while (getline(&line, &size, stat) != -1) {
|
||||||
return strtoul(btime, NULL, 10);
|
if (!strncmp(line, "btime", 5)) {
|
||||||
|
btime = strtoul(skip_token(line), NULL, 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(line);
|
||||||
|
fclose(stat);
|
||||||
|
out:
|
||||||
|
return btime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user