chiark / gitweb /
move _cleanup_ attribute in front of the type
[elogind.git] / src / bootchart / store.c
index 0253ebb5af0af277dc1024f785cf1806913df379..4de187c8bc8bdcda4a148399befeec7626248039 100644 (file)
@@ -34,6 +34,7 @@
 #include <time.h>
 
 #include "util.h"
+#include "strxcpyx.h"
 #include "store.h"
 #include "bootchart.h"
 
@@ -55,7 +56,7 @@ double gettime_ns(void) {
 }
 
 void log_uptime(void) {
-        FILE _cleanup_fclose_ *f = NULL;
+        _cleanup_fclose_ FILE *f = NULL;
         char str[32];
         double uptime;
 
@@ -89,9 +90,9 @@ static char *bufgetline(char *buf) {
         return c;
 }
 
-static int pid_cmdline_strncpy(char *buffer, int pid, size_t buf_len) {
+static int pid_cmdline_strscpy(char *buffer, size_t buf_len, int pid) {
         char filename[PATH_MAX];
-        int _cleanup_close_ fd=-1;
+        _cleanup_close_ int fd=-1;
         ssize_t n;
 
         sprintf(filename, "%d/cmdline", pid);
@@ -113,7 +114,7 @@ static int pid_cmdline_strncpy(char *buffer, int pid, size_t buf_len) {
 void log_sample(int sample) {
         static int vmstat;
         static int schedstat;
-        char buf[4095];
+        char buf[4096];
         char key[256];
         char val[256];
         char rt[256];
@@ -245,7 +246,7 @@ schedstat_next:
 
                 /* end of our LL? then append a new record */
                 if (ps->pid != pid) {
-                        FILE _cleanup_fclose_ *st = NULL;
+                        _cleanup_fclose_ FILE *st = NULL;
                         char t[32];
                         struct ps_struct *parent;
 
@@ -286,11 +287,11 @@ schedstat_next:
                         if (!sscanf(buf, "%s %*s %*s", key))
                                 continue;
 
-                        strncpy(ps->name, key, 256);
+                        strscpy(ps->name, sizeof(ps->name), key);
 
                         /* cmdline */
                         if (arg_show_cmdline)
-                                pid_cmdline_strncpy(ps->name, pid, 256);
+                                pid_cmdline_strscpy(ps->name, sizeof(ps->name), pid);
 
                         /* discard line 2 */
                         m = bufgetline(buf);
@@ -449,11 +450,11 @@ catch_rename:
                         if (!sscanf(buf, "%s %*s %*s", key))
                                 continue;
 
-                        strncpy(ps->name, key, 256);
+                        strscpy(ps->name, sizeof(ps->name), key);
 
                         /* cmdline */
                         if (arg_show_cmdline)
-                                pid_cmdline_strncpy(ps->name, pid, 256);
+                                pid_cmdline_strscpy(ps->name, sizeof(ps->name), pid);
                 }
         }
 }