chiark / gitweb /
tree-wide usage of %m specifier instead of strerror(errno)
authorDaniel Buch <boogiewasthere@gmail.com>
Tue, 26 Nov 2013 08:38:02 +0000 (09:38 +0100)
committerDavid Strauss <david@davidstrauss.net>
Tue, 26 Nov 2013 11:07:46 +0000 (21:07 +1000)
Also for log_error() except where a specific error is specified

e.g. errno ? strerror(errno) : "Some user specified message"

14 files changed:
TODO
src/core/automount.c
src/core/main.c
src/core/manager.c
src/core/mount-setup.c
src/core/service.c
src/initctl/initctl.c
src/journal/coredumpctl.c
src/journal/journald-console.c
src/journal/journald-kmsg.c
src/udev/collect/collect.c
src/udev/scsi_id/scsi_id.c
src/udev/scsi_id/scsi_serial.c
src/udev/udev-rules.c

diff --git a/TODO b/TODO
index d63e13e..653258a 100644 (file)
--- a/TODO
+++ b/TODO
@@ -824,8 +824,6 @@ Regularly:
 
 * Use PR_SET_PROCTITLE_AREA if it becomes available in the kernel
 
-* %m in printf() instead of strerror(errno);
-
 * pahole
 
 * set_put(), hashmap_put() return values check. i.e. == 0 doesn't free()!
index 49a64b1..66e3d78 100644 (file)
@@ -304,7 +304,7 @@ static int open_dev_autofs(Manager *m) {
 
         m->dev_autofs_fd = open("/dev/autofs", O_CLOEXEC|O_RDONLY);
         if (m->dev_autofs_fd < 0) {
-                log_error("Failed to open /dev/autofs: %s", strerror(errno));
+                log_error("Failed to open /dev/autofs: %m");
                 return -errno;
         }
 
index dbc98db..69d3a43 100644 (file)
@@ -131,7 +131,7 @@ _noreturn_ static void crash(int sig) {
 
                 pid = fork();
                 if (pid < 0)
-                        log_error("Caught <%s>, cannot fork for core dump: %s", signal_to_string(sig), strerror(errno));
+                        log_error("Caught <%s>, cannot fork for core dump: %m", signal_to_string(sig));
 
                 else if (pid == 0) {
                         struct rlimit rl = {};
index aa4baaa..65cb73c 100644 (file)
@@ -307,7 +307,7 @@ static int enable_special_signals(Manager *m) {
         } else {
                 /* Enable that we get SIGWINCH on kbrequest */
                 if (ioctl(fd, KDSIGACCEPT, SIGWINCH) < 0)
-                        log_warning("Failed to enable kbrequest handling: %s", strerror(errno));
+                        log_warning("Failed to enable kbrequest handling: %m");
         }
 
         return 0;
index 73c2698..c601c97 100644 (file)
@@ -188,7 +188,7 @@ static int mount_one(const MountPoint *p, bool relabel) {
                   p->type,
                   p->flags,
                   p->options) < 0) {
-                log_full((p->mode & MNT_FATAL) ? LOG_ERR : LOG_DEBUG, "Failed to mount %s: %s", p->where, strerror(errno));
+                log_full((p->mode & MNT_FATAL) ? LOG_ERR : LOG_DEBUG, "Failed to mount %s: %m", p->where);
                 return (p->mode & MNT_FATAL) ? -errno : 0;
         }
 
index 28b1465..7c5d5d8 100644 (file)
@@ -3507,7 +3507,7 @@ static int service_enumerate(Manager *m) {
                         d = opendir(path);
                         if (!d) {
                                 if (errno != ENOENT)
-                                        log_warning("opendir(%s) failed: %s", path, strerror(errno));
+                                        log_warning("opendir(%s) failed: %m", path);
 
                                 continue;
                         }
@@ -3540,7 +3540,7 @@ static int service_enumerate(Manager *m) {
                                 if (access(fpath, X_OK) < 0) {
 
                                         if (errno != ENOENT)
-                                                log_warning("access() failed on %s: %s", fpath, strerror(errno));
+                                                log_warning("access() failed on %s: %m", fpath);
 
                                         continue;
                                 }
index 0000d6c..284319f 100644 (file)
@@ -217,7 +217,7 @@ static int fifo_process(Fifo *f) {
                 if (errno == EAGAIN)
                         return 0;
 
-                log_warning("Failed to read from fifo: %s", strerror(errno));
+                log_warning("Failed to read from fifo: %m");
                 return -1;
         }
 
@@ -278,7 +278,7 @@ static int server_init(Server *s, unsigned n_sockets) {
         s->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
         if (s->epoll_fd < 0) {
                 r = -errno;
-                log_error("Failed to create epoll object: %s", strerror(errno));
+                log_error("Failed to create epoll object: %m");
                 goto fail;
         }
 
@@ -305,8 +305,7 @@ static int server_init(Server *s, unsigned n_sockets) {
                 f = new0(Fifo, 1);
                 if (!f) {
                         r = -ENOMEM;
-                        log_error("Failed to create fifo object: %s",
-                                  strerror(errno));
+                        log_error("Failed to create fifo object: %m");
                         goto fail;
                 }
 
@@ -318,8 +317,7 @@ static int server_init(Server *s, unsigned n_sockets) {
                 if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0) {
                         r = -errno;
                         fifo_free(f);
-                        log_error("Failed to add fifo fd to epoll object: %s",
-                                  strerror(errno));
+                        log_error("Failed to add fifo fd to epoll object: %m");
                         goto fail;
                 }
 
@@ -416,7 +414,7 @@ int main(int argc, char *argv[]) {
                         if (errno == EINTR)
                                 continue;
 
-                        log_error("epoll_wait() failed: %s", strerror(errno));
+                        log_error("epoll_wait() failed: %m");
                         goto fail;
                 }
 
index bcfee46..ec65ff5 100644 (file)
@@ -479,7 +479,7 @@ static int run_gdb(sd_journal *j) {
 
         sz = write(fd, data, len);
         if (sz < 0) {
-                log_error("Failed to write temporary file: %s", strerror(errno));
+                log_error("Failed to write temporary file: %m");
                 r = -errno;
                 goto finish;
         }
index 1ee3afe..04c4424 100644 (file)
@@ -100,12 +100,12 @@ void server_forward_console(
 
         fd = open_terminal(tty, O_WRONLY|O_NOCTTY|O_CLOEXEC);
         if (fd < 0) {
-                log_debug("Failed to open %s for logging: %s", tty, strerror(errno));
+                log_debug("Failed to open %s for logging: %m", tty);
                 goto finish;
         }
 
         if (writev(fd, iovec, n) < 0)
-                log_debug("Failed to write to %s for logging: %s", tty, strerror(errno));
+                log_debug("Failed to write to %s for logging: %m", tty);
 
         close_nointr_nofail(fd);
 
index 21649d0..af49d85 100644 (file)
@@ -88,7 +88,7 @@ void server_forward_kmsg(
         IOVEC_SET_STRING(iovec[n++], "\n");
 
         if (writev(s->dev_kmsg_fd, iovec, n) < 0)
-                log_debug("Failed to write to /dev/kmsg for logging: %s", strerror(errno));
+                log_debug("Failed to write to /dev/kmsg for logging: %m");
 
         free(ident_buf);
 }
index 1346f27..2bbbcd7 100644 (file)
@@ -97,7 +97,7 @@ static int prepare(char *dir, char *filename)
 
         fd = open(buf,O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
         if (fd < 0)
-                fprintf(stderr, "Cannot open %s: %s\n", buf, strerror(errno));
+                fprintf(stderr, "Cannot open %s: %m\n", buf);
 
         if (lockf(fd,F_TLOCK,0) < 0) {
                 if (debug)
@@ -109,7 +109,7 @@ static int prepare(char *dir, char *filename)
                                 fprintf(stderr, "Acquired lock on %s\n", buf);
                 } else {
                         if (debug)
-                                fprintf(stderr, "Could not get lock on %s: %s\n", buf, strerror(errno));
+                                fprintf(stderr, "Could not get lock on %s: %m\n", buf);
                 }
         }
 
@@ -404,7 +404,7 @@ int main(int argc, char **argv)
         us = argv[argi++];
 
         if (signal(SIGALRM, sig_alrm) == SIG_ERR) {
-                fprintf(stderr, "Cannot set SIGALRM: %s\n", strerror(errno));
+                fprintf(stderr, "Cannot set SIGALRM: %m\n");
                 ret = 2;
                 goto exit;
         }
index ab7c54c..c2cc2ea 100644 (file)
@@ -185,7 +185,7 @@ static int get_file_options(struct udev *udev,
                 if (errno == ENOENT) {
                         return 1;
                 } else {
-                        log_error("can't open %s: %s\n", config_file, strerror(errno));
+                        log_error("can't open %s: %m\n", config_file);
                         return -1;
                 }
         }
index d522a23..4b0711b 100644 (file)
@@ -362,7 +362,7 @@ resend:
                         dev_scsi->use_sg = 3;
                         goto resend;
                 }
-                log_debug("%s: ioctl failed: %s\n", dev_scsi->kernel, strerror(errno));
+                log_debug("%s: ioctl failed: %m\n", dev_scsi->kernel);
                 goto error;
         }
 
@@ -820,14 +820,12 @@ int scsi_std_inquiry(struct udev *udev,
 
         fd = open(devname, O_RDONLY | O_NONBLOCK);
         if (fd < 0) {
-                log_debug("scsi_id: cannot open %s: %s\n",
-                     devname, strerror(errno));
+                log_debug("scsi_id: cannot open %s: %m\n", devname);
                 return 1;
         }
 
         if (fstat(fd, &statbuf) < 0) {
-                log_debug("scsi_id: cannot stat %s: %s\n",
-                     devname, strerror(errno));
+                log_debug("scsi_id: cannot stat %s: %m\n", devname);
                 err = 2;
                 goto out;
         }
index 320f004..9154700 100644 (file)
@@ -2595,7 +2595,7 @@ int udev_rules_apply_static_dev_perms(struct udev_rules *rules)
                                         strscpyl(tag_symlink, sizeof(tag_symlink), tags_dir, unescaped_filename, NULL);
                                         r = symlink(device_node, tag_symlink);
                                         if (r < 0 && errno != EEXIST) {
-                                                log_error("failed to create symlink %s -> %s: %s\n", tag_symlink, device_node, strerror(errno));
+                                                log_error("failed to create symlink %s -> %s: %m\n", tag_symlink, device_node);
                                                 return -errno;
                                         } else
                                                 r = 0;