]> git.itanic.dy.fi Git - rrdd/commitdiff
Remove redundant strerror usage
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sat, 14 Apr 2012 12:06:52 +0000 (15:06 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sat, 14 Apr 2012 12:06:52 +0000 (15:06 +0300)
It is preferred to use '%m' with printf instead.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
parser.c
process.c

index 23955e35042e8b0118889f8d8383b1961e63c615..d7aa293065b324dda750aceb2fe54062116cc7c6 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1,7 +1,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <error.h>
 
 #include "parser.h"
 #include "process.h"
@@ -121,7 +120,7 @@ int digitemp_parser(char *data, void *p)
        const char digitemp_cmd[] = "/usr/bin/digitemp";
        char *const digitemp_args[] = { "", "-o2", "-a", "-q", 0 };
        FILE *readf;
-       int pid, ret, error;
+       int pid, ret;
        float t1 = 0, t2 = 0, t3 = 0;
        char buf[1024];
 
@@ -135,9 +134,7 @@ int digitemp_parser(char *data, void *p)
        ret = fscanf(readf, "%f %f %f", &t1, &t2, &t3);
 
        if (ret != 3) {
-               error = errno;
-               pr_err("Failed to parse digitemp output: %s\n",
-                      strerror(error));
+               pr_err("Failed to parse digitemp output: %m\n");
                sprintf(data, "U:U");
                return 1;
        }
@@ -203,8 +200,8 @@ static int get_iface_stats(const char *iface, struct iface_stats *stat)
 
        if (netdev == NULL) {
                error = errno;
-               pr_err("Failed to open file %s: %d (%s)\n",
-                       PROC_NETDEV, error, strerror(error));
+               pr_err("Failed to open file %s: %d (%m)\n",
+                       PROC_NETDEV, error);
                return error;
        }
 
index 93785244cd0e910bd7b1a71ac2c810f3fdd23f65..a00d34e79092b2c7b21521387f646cd0531ab52f 100644 (file)
--- a/process.c
+++ b/process.c
@@ -25,11 +25,10 @@ int get_sibling_count(void)
 
 int do_fork(void)
 {
-       int child, error;
+       int child;
        child = fork();
        if (child < 0) {
-               error = errno;
-               pr_err("fork() failed: %s\n", strerror(error));
+               pr_err("fork() failed: %m\n");
                return -1;
        }
 
@@ -48,7 +47,7 @@ int do_fork(void)
 
 int harvest_zombies(int pid)
 {
-       int status, error;
+       int status;
 
        if (child_count == 0)
                return 0;
@@ -59,8 +58,7 @@ int harvest_zombies(int pid)
 
        pid = waitpid(pid, &status, 0);
        if (pid < 0) {
-               error = errno;
-               pr_err("Error on wait(): %s\n", strerror(error));
+               pr_err("Error on wait(): %m\n");
                child_count--; /* Decrement child count anyway */
        }
        else {
@@ -81,25 +79,22 @@ int harvest_zombies(int pid)
 int run_piped(const char *cmd, char *const argv[],
              int *stdinfd, int *stdoutfd, int *stderrfd)
 {
-       int ifd[2], ofd[2], efd[2], error, pid;
+       int ifd[2], ofd[2], efd[2], pid;
 
        pr_info("Running command %s\n", cmd);
 
        if (stdinfd && pipe(ifd)) {
-               error = errno;
-               pr_err("pipe() failed: %s\n", strerror(error));
+               pr_err("pipe() failed: %m\n");
                return -1;
        }
 
        if (stdoutfd && pipe(ofd)) {
-               error = errno;
-               pr_err("pipe() failed: %s\n", strerror(error));
+               pr_err("pipe() failed: %m\n");
                return -1;
        }
 
        if (stderrfd && pipe(efd)) {
-               error = errno;
-               pr_err("pipe() failed: %s\n", strerror(error));
+               pr_err("pipe() failed: %m\n");
                return -1;
        }
 
@@ -140,8 +135,7 @@ int run_piped(const char *cmd, char *const argv[],
 
        /* Now we have redirected standard streams to parent process */
        execvp(cmd, argv);
-       error = errno;
-       pr_err("Failed to execv command %s: %s\n", cmd, strerror(error));
+       pr_err("Failed to execv command %s: %m\n", cmd);
        exit(1);
 
        return 0;
@@ -156,7 +150,7 @@ int run_piped(const char *cmd, char *const argv[],
 int run_piped_stream(const char *cmd, char *const argv[],
                     FILE **stdinf, FILE **stdoutf, FILE **stderrf)
 {
-       int ifd, ofd, efd, pid, error;
+       int ifd, ofd, efd, pid;
        int *i, *o, *e;
 
        if (stdinf)
@@ -177,9 +171,8 @@ int run_piped_stream(const char *cmd, char *const argv[],
        if (stdinf) {
                *stdinf = fdopen(ifd, "r");
                if (*stdinf == NULL) {
-                       error = errno;
-                       pr_err("Error opening file stream for fd %d: %s\n",
-                              ifd, strerror(error));
+                       pr_err("Error opening file stream for fd %d: %m\n",
+                              ifd);
                        return -1;
                }
        }
@@ -187,9 +180,8 @@ int run_piped_stream(const char *cmd, char *const argv[],
        if (stdoutf) {
                *stdoutf = fdopen(ofd, "r");
                if (*stdoutf == NULL) {
-                       error = errno;
-                       pr_err("Error opening file stream for fd %d: %s\n",
-                              ofd, strerror(error));
+                       pr_err("Error opening file stream for fd %d: %m\n",
+                              ofd);
                        return -1;
                }
        }
@@ -197,9 +189,8 @@ int run_piped_stream(const char *cmd, char *const argv[],
        if (stderrf) {
                *stderrf = fdopen(efd, "r");
                if (*stderrf == NULL) {
-                       error = errno;
-                       pr_err("Error opening file stream for fd %d: %s\n",
-                              efd, strerror(error));
+                       pr_err("Error opening file stream for fd %d: %m\n",
+                              efd);
                        return -1;
                }
        }
@@ -266,8 +257,7 @@ int run(const char *cmd, char *const argv[])
 
 print:
                if (bytes < 0) {
-                       error = errno;
-                       pr_err("read() failed: %s\n", strerror(error));
+                       pr_err("read() failed: %m\n");
                        break;
                }