chiark / gitweb /
sd-daemon: replace VLA with alloca(), to make llvm happy
[elogind.git] / src / libsystemd / sd-daemon / sd-daemon.c
index 028c2a7a5b4cceb881207ee23fa2bff511196933..0842aba9cbfa4ebcfe62c75532743ccb75fefbbd 100644 (file)
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
-#include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/socket.h>
 #include <sys/un.h>
-#include <fcntl.h>
 #include <netinet/in.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -352,11 +350,7 @@ _public_ int sd_pid_notify_with_fds(pid_t pid, int unset_environment, const char
                 .msg_iovlen = 1,
                 .msg_name = &sockaddr,
         };
-        union {
-                struct cmsghdr cmsghdr;
-                uint8_t buf[CMSG_SPACE(sizeof(struct ucred)) +
-                            CMSG_SPACE(sizeof(int) * n_fds)];
-        } control;
+        struct cmsghdr *control;
         _cleanup_close_ int fd = -1;
         struct cmsghdr *cmsg = NULL;
         const char *e;
@@ -400,8 +394,10 @@ _public_ int sd_pid_notify_with_fds(pid_t pid, int unset_environment, const char
         if (msghdr.msg_namelen > sizeof(struct sockaddr_un))
                 msghdr.msg_namelen = sizeof(struct sockaddr_un);
 
+        control = alloca(CMSG_SPACE(sizeof(struct ucred)) + CMSG_SPACE(sizeof(int) * n_fds));
+
         if (n_fds > 0) {
-                msghdr.msg_control = &control;
+                msghdr.msg_control = control;
                 msghdr.msg_controllen = CMSG_LEN(sizeof(int) * n_fds);
 
                 cmsg = CMSG_FIRSTHDR(&msghdr);
@@ -418,7 +414,7 @@ _public_ int sd_pid_notify_with_fds(pid_t pid, int unset_environment, const char
                 try_without_ucred = true;
                 controllen_without_ucred = msghdr.msg_controllen;
 
-                msghdr.msg_control = &control;
+                msghdr.msg_control = control;
                 msghdr.msg_controllen += CMSG_LEN(sizeof(struct ucred));
 
                 if (cmsg)