]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: fix a number of log calls that use %m but have no errno set
authorLennart Poettering <lennart@poettering.net>
Tue, 5 Jun 2018 18:18:47 +0000 (20:18 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 7 Jun 2018 13:29:17 +0000 (15:29 +0200)
This is mostly fall-out from d1a1f0aaf0d2f08c60d1e0d32e646439d99f58dc,
however some cases are older bugs.

There might be more issues lurking, this was a simple grep for "%m"
across the tree, with all lines removed that mention "errno" at all.

src/basic/conf-files.c
src/basic/fs-util.c
src/basic/selinux-util.c
src/core/automount.c
src/core/service.c
src/journal/journald-stream.c
src/network/netdev/netdev.c
src/nspawn/nspawn.c
src/shared/bus-unit-util.c
src/shared/conf-parser.c
src/shared/dropin.c

index 2e65a6e74f3c3e74b3181b6dca6dac42cc4f6989..15a066da7fe4851510196613f4df390f8da777e6 100644 (file)
@@ -349,7 +349,7 @@ int conf_files_cat(const char *root, const char *name) {
                 assert(endswith(dir, "/"));
                 r = strv_extendf(&dirs, "%s%s.d", dir, name);
                 if (r < 0)
-                        return log_error("Failed to build directory list: %m");
+                        return log_error_errno(r, "Failed to build directory list: %m");
         }
 
         r = conf_files_list_strv(&files, ".conf", root, 0, (const char* const*) dirs);
index 6146c6678207f8b5a43a4f1b74d1eacd8c061d2b..ab6ccf7c86d1f644e30770bf37cce06dc5fb561c 100644 (file)
@@ -1155,9 +1155,9 @@ int fsync_directory_of_file(int fd) {
 
         r = fd_get_path(fd, &path);
         if (r < 0) {
-                log_debug("Failed to query /proc/self/fd/%d%s: %m",
-                          fd,
-                          r == -EOPNOTSUPP ? ", ignoring" : "");
+                log_debug_errno(r, "Failed to query /proc/self/fd/%d%s: %m",
+                                fd,
+                                r == -EOPNOTSUPP ? ", ignoring" : "");
 
                 if (r == -EOPNOTSUPP)
                         /* If /proc is not available, we're most likely running in some
index aba3e4f15d8990a509ac65fbf8cd36cf453f2b8d..61504a673a7bfe498bd60c3f4688e72e03c94241 100644 (file)
@@ -79,7 +79,7 @@ int mac_selinux_init(void) {
 
         label_hnd = selabel_open(SELABEL_CTX_FILE, NULL, 0);
         if (!label_hnd) {
-                log_enforcing("Failed to initialize SELinux context: %m");
+                log_enforcing_errno(errno, "Failed to initialize SELinux context: %m");
                 r = security_getenforce() == 1 ? -errno : 0;
         } else  {
                 char timespan[FORMAT_TIMESPAN_MAX];
@@ -189,7 +189,7 @@ int mac_selinux_apply(const char *path, const char *label) {
         assert(label);
 
         if (setfilecon(path, label) < 0) {
-                log_enforcing("Failed to set SELinux security context %s on path %s: %m", label, path);
+                log_enforcing_errno(errno, "Failed to set SELinux security context %s on path %s: %m", label, path);
                 if (security_getenforce() > 0)
                         return -errno;
         }
@@ -349,12 +349,12 @@ int mac_selinux_create_file_prepare(const char *path, mode_t mode) {
                 if (errno == ENOENT)
                         return 0;
 
-                log_enforcing("Failed to determine SELinux security context for %s: %m", path);
+                log_enforcing_errno(errno, "Failed to determine SELinux security context for %s: %m", path);
         } else {
                 if (setfscreatecon_raw(filecon) >= 0)
                         return 0; /* Success! */
 
-                log_enforcing("Failed to set SELinux security context %s for %s: %m", filecon, path);
+                log_enforcing_errno(errno, "Failed to set SELinux security context %s for %s: %m", filecon, path);
         }
 
         if (security_getenforce() > 0)
@@ -385,7 +385,7 @@ int mac_selinux_create_socket_prepare(const char *label) {
         assert(label);
 
         if (setsockcreatecon(label) < 0) {
-                log_enforcing("Failed to set SELinux security context %s for sockets: %m", label);
+                log_enforcing_errno(errno, "Failed to set SELinux security context %s for sockets: %m", label);
 
                 if (security_getenforce() == 1)
                         return -errno;
@@ -457,13 +457,13 @@ int mac_selinux_bind(int fd, const struct sockaddr *addr, socklen_t addrlen) {
                 if (errno == ENOENT)
                         goto skipped;
 
-                log_enforcing("Failed to determine SELinux security context for %s: %m", path);
+                log_enforcing_errno(errno, "Failed to determine SELinux security context for %s: %m", path);
                 if (security_getenforce() > 0)
                         return -errno;
 
         } else {
                 if (setfscreatecon_raw(fcon) < 0) {
-                        log_enforcing("Failed to set SELinux security context %s for %s: %m", fcon, path);
+                        log_enforcing_errno(errno, "Failed to set SELinux security context %s for %s: %m", fcon, path);
                         if (security_getenforce() > 0)
                                 return -errno;
                 } else
index 3e848c80855a887a748b792bb702895ea0b39eda..0aba87b778c7e182e41f4a00b4c4c5c969c6f452 100644 (file)
@@ -177,7 +177,7 @@ static int automount_verify(Automount *a) {
 
         r = unit_name_from_path(a->where, ".automount", &e);
         if (r < 0)
-                return log_unit_error(UNIT(a), "Failed to generate unit name from path: %m");
+                return log_unit_error_errno(UNIT(a), r, "Failed to generate unit name from path: %m");
 
         if (!unit_has_name(UNIT(a), e)) {
                 log_unit_error(UNIT(a), "Where= setting doesn't match unit name. Refusing.");
index db0c1dc397a70fa3ff6040e8d593d1af164d7e2d..2d43779cfbcb84ad139fa2dee70eda0d610e74e9 100644 (file)
@@ -1947,7 +1947,7 @@ static void service_enter_start(Service *s) {
                         /* There's no command line configured for the main command? Hmm, that is strange. This can only
                          * happen if the configuration changes at runtime. In this case, let's enter a failure
                          * state. */
-                        log_unit_error(UNIT(s), "There's no 'start' task anymore we could start: %m");
+                        log_unit_error(UNIT(s), "There's no 'start' task anymore we could start.");
                         r = -ENXIO;
                         goto fail;
                 }
index 93a0cc2288572a999e853c684d59dd7a3acab66c..4975aba016a648a9d863cd0da1cbd6f8108c20f1 100644 (file)
@@ -766,8 +766,8 @@ int server_restore_streams(Server *s, FDSet *fds) {
                         /* No file descriptor? Then let's delete the state file */
                         log_debug("Cannot restore stream file %s", de->d_name);
                         if (unlinkat(dirfd(d), de->d_name, 0) < 0)
-                                log_warning("Failed to remove /run/systemd/journal/streams/%s: %m",
-                                            de->d_name);
+                                log_warning_errno(errno, "Failed to remove /run/systemd/journal/streams/%s: %m",
+                                                  de->d_name);
                         continue;
                 }
 
index a0b26971836ca619c11be70079371f8e99d6d9a3..7ca570eee67c9032c24f69a7905a2e375b5fe069 100644 (file)
@@ -242,7 +242,7 @@ static int netdev_enslave_ready(NetDev *netdev, Link* link, sd_netlink_message_h
 
         r = sd_netlink_call_async(netdev->manager->rtnl, req, callback, link, 0, NULL);
         if (r < 0)
-                return log_netdev_error(netdev, "Could not send rtnetlink message: %m");
+                return log_netdev_error_errno(netdev, r, "Could not send rtnetlink message: %m");
 
         link_ref(link);
 
index 5792ae9587dd4697883a897d85a58ca768e26eb9..7f11d6606286152bb22a7784146f6207d50be1dc 100644 (file)
@@ -2930,7 +2930,7 @@ static int outer_child(
                 if (l < 0)
                         return log_error_errno(errno, "Failed to send cgroup mode: %m");
                 if (l != sizeof(arg_unified_cgroup_hierarchy)) {
-                        log_error("Short write while sending cgroup mode: %m");
+                        log_error("Short write while sending cgroup mode.");
                         return -EIO;
                 }
 
index 539a7b4d9da9beabef898a4c472bc07351c7aef1..64b7ac8d69273a819547b38965f1e7ef28bf4df0 100644 (file)
@@ -1156,8 +1156,10 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
                         r = extract_first_word(&w, &path, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
                         if (r < 0)
                                 return log_error_errno(r, "Failed to parse argument: %m");
-                        if (r == 0)
-                                return log_error("Failed to parse argument: %m");
+                        if (r == 0) {
+                                log_error("Failed to parse argument: %s", p);
+                                return -EINVAL;
+                        }
 
                         r = sd_bus_message_append(m, "(ss)", path, w);
                         if (r < 0)
index 4ad83b806b52e317c39d9cd028d31c6aea0ca887..b5ee07c9bd773336da9deec6e981469ac32b27b0 100644 (file)
@@ -303,8 +303,8 @@ int config_parse(const char *unit,
                         /* Only log on request, except for ENOENT,
                          * since we return 0 to the caller. */
                         if ((flags & CONFIG_PARSE_WARN) || errno == ENOENT)
-                                log_full(errno == ENOENT ? LOG_DEBUG : LOG_ERR,
-                                         "Failed to open configuration file '%s': %m", filename);
+                                log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR, errno,
+                                               "Failed to open configuration file '%s': %m", filename);
                         return errno == ENOENT ? 0 : -errno;
                 }
         }
index d9362f6919edc6c745221d1eb4454dea867a31b8..0fc02914ac748ca9a856a8f3b640d0a764c9d91a 100644 (file)
@@ -210,7 +210,7 @@ static int unit_file_find_dirs(
 
         type = unit_name_to_type(name);
         if (type < 0) {
-                log_error("Failed to to derive unit type from unit name: %m");
+                log_error("Failed to to derive unit type from unit name: %s", name);
                 return -EINVAL;
         }