chiark / gitweb /
Use %m instead of strerror(errno) where appropiate
[elogind.git] / src / nspawn / nspawn.c
index 2d627db9c7fc364af4f9d2c9ab233fcfd1d4b807..73158a051831edf74a5db86ee8027b471a5e28c8 100644 (file)
@@ -657,7 +657,7 @@ static int mount_binds(const char *dest, char **l, unsigned long flags) {
                                 return r;
                         }
                 } else {
-                        log_error("Failed to bind mount %s: %s", *x, strerror(errno));
+                        log_error("Failed to bind mount %s: %m", *x);
                         return -errno;
                 }
                 /* Create the mount point, but be conservative -- refuse to create block
@@ -769,6 +769,15 @@ static int setup_resolv_conf(const char *dest) {
         return 0;
 }
 
+static char* id128_format_as_uuid(sd_id128_t id, char s[37]) {
+
+        snprintf(s, 37,
+                 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+                 SD_ID128_FORMAT_VAL(id));
+
+        return s;
+}
+
 static int setup_boot_id(const char *dest) {
         _cleanup_free_ char *from = NULL, *to = NULL;
         sd_id128_t rnd = {};
@@ -794,10 +803,7 @@ static int setup_boot_id(const char *dest) {
                 return r;
         }
 
-        snprintf(as_uuid, sizeof(as_uuid),
-                 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-                 SD_ID128_FORMAT_VAL(rnd));
-        char_array_0(as_uuid);
+        id128_format_as_uuid(rnd, as_uuid);
 
         r = write_string_file(from, as_uuid);
         if (r < 0) {
@@ -1137,10 +1143,8 @@ static int setup_journal(const char *directory) {
         } else if (access(p, F_OK) < 0)
                 return 0;
 
-        if (dir_is_empty(q) == 0) {
-                log_error("%s not empty.", q);
-                return -ENOTEMPTY;
-        }
+        if (dir_is_empty(q) == 0)
+                log_warning("%s is not empty, proceeding anyway.", q);
 
         r = mkdir_p(q, 0755);
         if (r < 0) {
@@ -1486,13 +1490,7 @@ static int setup_veth(pid_t pid, char iface_name[IFNAMSIZ]) {
                 return r;
         }
 
-        r = sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "veth");
-        if (r < 0) {
-                log_error("Failed to append netlink kind: %s", strerror(-r));
-                return r;
-        }
-
-        r = sd_rtnl_message_open_container(m, IFLA_INFO_DATA);
+        r = sd_rtnl_message_open_container_union(m, IFLA_INFO_DATA, "veth");
         if (r < 0) {
                 log_error("Failed to open netlink container: %s", strerror(-r));
                 return r;
@@ -1757,13 +1755,7 @@ static int setup_macvlan(pid_t pid) {
                         return r;
                 }
 
-                r = sd_rtnl_message_append_string(m, IFLA_INFO_KIND, "macvlan");
-                if (r < 0) {
-                        log_error("Failed to append netlink kind: %s", strerror(-r));
-                        return r;
-                }
-
-                r = sd_rtnl_message_open_container(m, IFLA_INFO_DATA);
+                r = sd_rtnl_message_open_container_union(m, IFLA_INFO_DATA, "macvlan");
                 if (r < 0) {
                         log_error("Failed to open netlink container: %s", strerror(-r));
                         return r;
@@ -2378,7 +2370,7 @@ static int change_uid_gid(char **_home) {
         _cleanup_fclose_ FILE *f = NULL;
         _cleanup_close_ int fd = -1;
         unsigned n_uids = 0;
-        size_t sz, l;
+        size_t sz = 0, l;
         uid_t uid;
         gid_t gid;
         pid_t pid;
@@ -2582,7 +2574,7 @@ int main(int argc, char *argv[]) {
         _cleanup_free_ char *kdbus_domain = NULL, *device_path = NULL, *root_device = NULL, *home_device = NULL, *srv_device = NULL;
         bool root_device_rw = true, home_device_rw = true, srv_device_rw = true;
         _cleanup_close_ int master = -1, kdbus_fd = -1, image_fd = -1;
-        _cleanup_close_pipe_ int kmsg_socket_pair[2] = { -1, -1 };
+        _cleanup_close_pair_ int kmsg_socket_pair[2] = { -1, -1 };
         _cleanup_fdset_free_ FDSet *fds = NULL;
         int r = EXIT_FAILURE, k, n_fd_passed, loop_nr = -1;
         const char *console = NULL;
@@ -2966,7 +2958,9 @@ int main(int argc, char *argv[]) {
                         }
 
                         if (!sd_id128_equal(arg_uuid, SD_ID128_NULL)) {
-                                if (asprintf((char**)(envp + n_env++), "container_uuid=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(arg_uuid)) < 0) {
+                                char as_uuid[37];
+
+                                if (asprintf((char**)(envp + n_env++), "container_uuid=%s", id128_format_as_uuid(arg_uuid, as_uuid)) < 0) {
                                         log_oom();
                                         goto child_fail;
                                 }
@@ -3061,7 +3055,7 @@ int main(int argc, char *argv[]) {
                 fds = NULL;
 
                 /* Wait until the child reported that it is ready with
-                 * all it needs to do with priviliges. After we got
+                 * all it needs to do with privileges. After we got
                  * the notification we can make the process join its
                  * cgroup which might limit what it can do */
                 eventfd_read(child_ready_fd, &x);