]> git.ipfire.org Git - pakfire.git/commitdiff
execute: Use %m instead of strerror(errno)
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 3 Jun 2021 19:19:51 +0000 (19:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 3 Jun 2021 19:19:51 +0000 (19:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/execute.c

index cd69fa1183a00fea47077d261affbd9207b625ef..33d0d5cfe04edfd421ce77a76d4d14bb24a2ca27 100644 (file)
@@ -98,7 +98,7 @@ static int pakfire_execute_logger_proxy(Pakfire pakfire, int fd,
 
                // Handle errors
                if (bytes_read < 0) {
-                       ERROR(pakfire, "Could not read from fd %d: %s\n", fd, strerror(errno));
+                       ERROR(pakfire, "Could not read from fd %d: %m\n", fd);
                        return -1;
                }
 
@@ -169,7 +169,7 @@ static int pakfire_execute_logger(Pakfire pakfire, pakfire_execute_logging_callb
        // Setup epoll
        epollfd = epoll_create1(0);
        if (epollfd < 0) {
-               ERROR(pakfire, "Could not initialize epoll(): %s\n", strerror(errno));
+               ERROR(pakfire, "Could not initialize epoll(): %m\n");
                r = -errno;
                goto OUT;
        }
@@ -185,8 +185,8 @@ static int pakfire_execute_logger(Pakfire pakfire, pakfire_execute_logging_callb
 
                // Set modified flags
                if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
-                       ERROR(pakfire, "Could not set file descriptor %d into non-blocking mode: %s\n",
-                               fd, strerror(errno));
+                       ERROR(pakfire, "Could not set file descriptor %d into non-blocking mode: %m\n",
+                               fd);
                        r = -errno;
                        goto OUT;
                }
@@ -194,8 +194,7 @@ static int pakfire_execute_logger(Pakfire pakfire, pakfire_execute_logging_callb
                ev.data.fd = fd;
 
                if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev) < 0) {
-                       ERROR(pakfire, "Could not add file descriptor %d to epoll(): %s\n",
-                               fd, strerror(errno));
+                       ERROR(pakfire, "Could not add file descriptor %d to epoll(): %m\n", fd);
                        r = -errno;
                        goto OUT;
                }
@@ -214,7 +213,7 @@ static int pakfire_execute_logger(Pakfire pakfire, pakfire_execute_logging_callb
 
                int fds = epoll_wait(epollfd, events, EPOLL_MAX_EVENTS, -1);
                if (fds < 1) {
-                       ERROR(pakfire, "epoll_wait() failed: %s\n", strerror(errno));
+                       ERROR(pakfire, "epoll_wait() failed: %m\n");
                        r = -errno;
 
                        goto OUT;
@@ -387,13 +386,13 @@ static int pakfire_execute_fork(void* data) {
        if (strcmp(root, "/") != 0) {
                int r = chroot(root);
                if (r) {
-                       ERROR(pakfire, "chroot() to %s failed: %s\n", root, strerror(errno));
+                       ERROR(pakfire, "chroot() to %s failed: %m\n", root);
                        return 1;
                }
 
                r = chdir("/");
                if (r) {
-                       ERROR(pakfire, "chdir() after chroot() failed: %s\n", strerror(errno));
+                       ERROR(pakfire, "chdir() after chroot() failed: %m\n");
                        return 1;
                }
        }
@@ -412,15 +411,15 @@ static int pakfire_execute_fork(void* data) {
        // Connect standard output and error
        if (env->stdout[1] && env->stderr[1]) {
                if (dup2(env->stdout[1], STDOUT_FILENO) < 0) {
-                       ERROR(pakfire, "Could not connect fd %d to stdout: %s\n",
-                               env->stdout[1], strerror(errno));
+                       ERROR(pakfire, "Could not connect fd %d to stdout: %m\n",
+                               env->stdout[1]);
 
                        return 1;
                }
 
                if (dup2(env->stderr[1], STDERR_FILENO) < 0) {
-                       ERROR(pakfire, "Could not connect fd %d to stderr: %s\n",
-                               env->stderr[1], strerror(errno));
+                       ERROR(pakfire, "Could not connect fd %d to stderr: %m\n",
+                               env->stderr[1]);
 
                        return 1;
                }
@@ -438,7 +437,7 @@ static int pakfire_execute_fork(void* data) {
        // exec() command
        r = execvpe(env->argv[0], (char**)env->argv, env->envp);
        if (r < 0) {
-               ERROR(pakfire, "Could not execve(): %s\n", strerror(errno));
+               ERROR(pakfire, "Could not execve(): %m\n");
        }
 
        // Translate errno into regular exit code
@@ -525,15 +524,13 @@ PAKFIRE_EXPORT int pakfire_execute(Pakfire pakfire, const char* argv[], char* en
        // Make some file descriptors for stdout & stderr
        } else {
                if (pipe(env.stdout) < 0) {
-                       ERROR(pakfire, "Could not create file descriptors for stdout: %s\n",
-                               strerror(errno));
+                       ERROR(pakfire, "Could not create file descriptors for stdout: %m\n");
                        r = -1;
                        goto ERROR;
                }
 
                if (pipe(env.stderr) < 0) {
-                       ERROR(pakfire, "Could not create file descriptors for stderr: %s\n",
-                               strerror(errno));
+                       ERROR(pakfire, "Could not create file descriptors for stderr: %m\n");
                        r = -1;
                        goto ERROR;
                }
@@ -579,14 +576,14 @@ PAKFIRE_EXPORT int pakfire_execute(Pakfire pakfire, const char* argv[], char* en
        // Create cgroup
        r = pakfire_cgroup_create(pakfire, env.cgroup);
        if (r) {
-               ERROR(pakfire, "Could not create cgroup %s: %s\n", env.cgroup, strerror(errno));
+               ERROR(pakfire, "Could not create cgroup %s: %m\n", env.cgroup);
                goto ERROR;
        }
 
        // Launch the new process straight into their cgroup
        cgroupdir = pakfire_cgroup_opendir(pakfire, env.cgroup);
        if (!cgroupdir) {
-               ERROR(pakfire, "Could not open cgroup %s: %s\n", env.cgroup, strerror(errno));
+               ERROR(pakfire, "Could not open cgroup %s: %m\n", env.cgroup);
                goto ERROR;
        }
 
@@ -596,7 +593,7 @@ PAKFIRE_EXPORT int pakfire_execute(Pakfire pakfire, const char* argv[], char* en
        // Fork this process
        pid_t pid = syscall(__NR_clone3, &args, sizeof(args));
        if (pid < 0) {
-               ERROR(pakfire, "Could not fork: %s\n", strerror(errno));
+               ERROR(pakfire, "Could not fork: %m\n");
                return -errno;
 
        // Child process
@@ -619,7 +616,7 @@ PAKFIRE_EXPORT int pakfire_execute(Pakfire pakfire, const char* argv[], char* en
                        close(env.stderr[1]);
 
                if (pakfire_execute_logger(pakfire, logging_callback, data, pid, env.stdout[0], env.stderr[0], &status)) {
-                       ERROR(pakfire, "Log reading aborted: %s\n", strerror(errno));
+                       ERROR(pakfire, "Log reading aborted: %m\n");
                }
        }
 
@@ -644,7 +641,7 @@ PAKFIRE_EXPORT int pakfire_execute(Pakfire pakfire, const char* argv[], char* en
        // Fetch CPU usage stats
        r = pakfire_cgroup_cpustat(pakfire, env.cgroup, &cpustat);
        if (r) {
-               ERROR(pakfire, "Could not read CPU usage stats: %s\n", strerror(errno));
+               ERROR(pakfire, "Could not read CPU usage stats: %m\n");
                r = -1;
                goto ERROR;
        }
@@ -701,9 +698,7 @@ PAKFIRE_EXPORT int pakfire_execute_script(Pakfire pakfire, const char* script, c
        // Open a temporary file
        int fd = mkstemp(path);
        if (fd < 0) {
-               ERROR(pakfire, "Could not open a temporary file: %s\n",
-                       strerror(errno));
-
+               ERROR(pakfire, "Could not open a temporary file: %m\n");
                r = errno;
        }
 
@@ -712,9 +707,7 @@ PAKFIRE_EXPORT int pakfire_execute_script(Pakfire pakfire, const char* script, c
        // Write data
        ssize_t bytes_written = write(fd, script, size);
        if (bytes_written < (ssize_t)size) {
-               ERROR(pakfire, "Could not write script to file %s: %s\n",
-                       path, strerror(errno));
-
+               ERROR(pakfire, "Could not write script to file %s: %m\n", path);
                r = errno;
                goto out;
        }
@@ -722,9 +715,7 @@ PAKFIRE_EXPORT int pakfire_execute_script(Pakfire pakfire, const char* script, c
        // Make the script executable
        r = fchmod(fd, S_IRUSR|S_IWUSR|S_IXUSR);
        if (r) {
-               ERROR(pakfire, "Could not set executable permissions on %s: %s\n",
-                       path, strerror(errno));
-
+               ERROR(pakfire, "Could not set executable permissions on %s: %m\n", path);
                r = errno;
                goto out;
        }
@@ -732,9 +723,7 @@ PAKFIRE_EXPORT int pakfire_execute_script(Pakfire pakfire, const char* script, c
        // Close file
        r = close(fd);
        if (r) {
-               ERROR(pakfire, "Could not close script file %s: %s\n",
-                       path, strerror(errno));
-
+               ERROR(pakfire, "Could not close script file %s: %m\n", path);
                r = errno;
                goto out;
        }
@@ -748,7 +737,7 @@ PAKFIRE_EXPORT int pakfire_execute_script(Pakfire pakfire, const char* script, c
 
        argv = calloc(argc + 1, sizeof(*argv));
        if (!argv) {
-               ERROR(pakfire, "Could not allocate argv: %s\n", strerror(errno));
+               ERROR(pakfire, "Could not allocate argv: %m\n");
                goto out;
        }