]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use structured initialization for sockaddr_un
authorLennart Poettering <lennart@poettering.net>
Mon, 15 Oct 2018 11:59:07 +0000 (13:59 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 15 Oct 2018 17:35:00 +0000 (19:35 +0200)
src/libsystemd/sd-bus/sd-bus.c
src/nspawn/nspawn.c
src/udev/udev-ctrl.c

index 1437df6cf36ced4a8029343b40680875dcf7982e..7868e53fb6244f7f744db7f8713905191ac8de43 100644 (file)
@@ -964,9 +964,11 @@ static int parse_container_unix_address(sd_bus *b, const char **p, char **guid)
         } else
                 b->nspid = 0;
 
-        b->sockaddr.un.sun_family = AF_UNIX;
-        /* Note that we use the old /var/run prefix here, to increase compatibility with really old containers */
-        strncpy(b->sockaddr.un.sun_path, "/var/run/dbus/system_bus_socket", sizeof(b->sockaddr.un.sun_path));
+        b->sockaddr.un = (struct sockaddr_un) {
+                .sun_family = AF_UNIX,
+                /* Note that we use the old /var/run prefix here, to increase compatibility with really old containers */
+                .sun_path = "/var/run/dbus/system_bus_socket",
+        };
         b->sockaddr_size = SOCKADDR_UN_LEN(b->sockaddr.un);
         b->is_local = false;
 
index 134c4c3b5d7d83729dab8581aa34e541fa9efd4c..d756d0aed0575a65c948d7a04f78602f67b7190b 100644 (file)
@@ -2815,7 +2815,8 @@ static int setup_sd_notify_child(void) {
         static const int one = 1;
         int fd = -1;
         union sockaddr_union sa = {
-                .sa.sa_family = AF_UNIX,
+                .un.sun_family = AF_UNIX,
+                .un.sun_path = NSPAWN_NOTIFY_SOCKET_PATH,
         };
         int r;
 
@@ -2826,11 +2827,10 @@ static int setup_sd_notify_child(void) {
         (void) mkdir_parents(NSPAWN_NOTIFY_SOCKET_PATH, 0755);
         (void) unlink(NSPAWN_NOTIFY_SOCKET_PATH);
 
-        strncpy(sa.un.sun_path, NSPAWN_NOTIFY_SOCKET_PATH, sizeof(sa.un.sun_path));
         r = bind(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un));
         if (r < 0) {
                 safe_close(fd);
-                return log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path);
+                return log_error_errno(errno, "bind(" NSPAWN_NOTIFY_SOCKET_PATH ") failed: %m");
         }
 
         r = userns_lchown(NSPAWN_NOTIFY_SOCKET_PATH, 0, 0);
index df9ceef7ce6a98e27cb5934a1883106f4ef79585..84909b3e15dd4b2d5d5f006c756aaa99868684d7 100644 (file)
@@ -101,8 +101,11 @@ struct udev_ctrl *udev_ctrl_new_from_fd(int fd) {
         if (r < 0)
                 log_warning_errno(errno, "could not set SO_PASSCRED: %m");
 
-        uctrl->saddr.un.sun_family = AF_LOCAL;
-        strscpy(uctrl->saddr.un.sun_path, sizeof(uctrl->saddr.un.sun_path), "/run/udev/control");
+        uctrl->saddr.un = (struct sockaddr_un) {
+                .sun_family = AF_UNIX,
+                .sun_path = "/run/udev/control",
+        };
+
         uctrl->addrlen = SOCKADDR_UN_LEN(uctrl->saddr.un);
         return uctrl;
 }