chiark / gitweb /
service: really stop watchdog timer when stopping
[elogind.git] / src / bootchart / log.c
index eda001a20e5e333676943c8bc15420c2ac04c150..48002fafd05faa117168988eb4c3ed8179e50a9c 100644 (file)
@@ -26,6 +26,7 @@
 
 
 #include "bootchart.h"
+#include "util.h"
 
 /*
  * Alloc a static 4k buffer for stdio - primarily used to increase
@@ -38,11 +39,11 @@ DIR *proc;
 
 double gettime_ns(void)
 {
-        struct timespec now;
+        struct timespec n;
 
-        clock_gettime(CLOCK_MONOTONIC, &now);
+        clock_gettime(CLOCK_MONOTONIC, &n);
 
-        return (now.tv_sec + (now.tv_nsec / 1000000000.0));
+        return (n.tv_sec + (n.tv_nsec / 1000000000.0));
 }
 
 
@@ -125,9 +126,9 @@ void log_sample(int sample)
         while (m) {
                 if (sscanf(m, "%s %s", key, val) < 2)
                         goto vmstat_next;
-                if (!strcmp(key, "pgpgin"))
+                if (streq(key, "pgpgin"))
                         blockstat[sample].bi = atoi(val);
-                if (!strcmp(key, "pgpgout")) {
+                if (streq(key, "pgpgout")) {
                         blockstat[sample].bo = atoi(val);
                         break;
                 }
@@ -182,8 +183,10 @@ schedstat_next:
 
                 if (e_fd) {
                         n = pread(e_fd, buf, sizeof(buf) - 1, 0);
-                        if (n > 0)
+                        if (n > 0) {
+                                buf[n] = '\0';
                                 entropy_avail[sample] = atoi(buf);
+                        }
                 }
         }
 
@@ -222,21 +225,19 @@ schedstat_next:
                         char t[32];
                         struct ps_struct *parent;
 
-                        ps->next_ps = malloc(sizeof(struct ps_struct));
+                        ps->next_ps = calloc(1, sizeof(struct ps_struct));
                         if (!ps->next_ps) {
-                                perror("malloc(ps_struct)");
+                                perror("calloc(ps_struct)");
                                 exit (EXIT_FAILURE);
                         }
-                        memset(ps->next_ps, 0, sizeof(struct ps_struct));
                         ps = ps->next_ps;
                         ps->pid = pid;
 
-                        ps->sample = malloc(sizeof(struct ps_sched_struct) * (len + 1));
+                        ps->sample = calloc(len + 1, sizeof(struct ps_sched_struct));
                         if (!ps->sample) {
-                                perror("malloc(ps_struct)");
+                                perror("calloc(ps_struct)");
                                 exit (EXIT_FAILURE);
                         }
-                        memset(ps->sample, 0, sizeof(struct ps_sched_struct) * (len + 1));
 
                         pscount++;
 
@@ -256,6 +257,7 @@ schedstat_next:
                                 close(ps->sched);
                                 continue;
                         }
+                        buf[s] = '\0';
 
                         if (!sscanf(buf, "%s %*s %*s", key))
                                 continue;
@@ -337,8 +339,8 @@ schedstat_next:
                         if (ps->schedstat == -1)
                                 continue;
                 }
-
-                if (pread(ps->schedstat, buf, sizeof(buf) - 1, 0) <= 0) {
+                s = pread(ps->schedstat, buf, sizeof(buf) - 1, 0);
+                if (s <= 0) {
                         /* clean up our file descriptors - assume that the process exited */
                         close(ps->schedstat);
                         if (ps->sched)
@@ -347,6 +349,8 @@ schedstat_next:
                         //        fclose(ps->smaps);
                         continue;
                 }
+                buf[s] = '\0';
+
                 if (!sscanf(buf, "%s %s %*s", rt, wt))
                         continue;
 
@@ -401,7 +405,8 @@ catch_rename:
                                 if (ps->sched == -1)
                                         continue;
                         }
-                        if (pread(ps->sched, buf, sizeof(buf) - 1, 0) <= 0) {
+                        s = pread(ps->sched, buf, sizeof(buf) - 1, 0);
+                        if (s <= 0) {
                                 /* clean up file descriptors */
                                 close(ps->sched);
                                 if (ps->schedstat)
@@ -410,6 +415,7 @@ catch_rename:
                                 //        fclose(ps->smaps);
                                 continue;
                         }
+                        buf[s] = '\0';
 
                         if (!sscanf(buf, "%s %*s %*s", key))
                                 continue;