]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
socket: Add time64 alias for sendmmsg
authorFlorian Weimer <fweimer@redhat.com>
Wed, 21 Jul 2021 09:42:31 +0000 (11:42 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 21 Jul 2021 09:58:16 +0000 (11:58 +0200)
Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
25 files changed:
socket/sys/socket.h
sysdeps/unix/sysv/linux/Makefile
sysdeps/unix/sysv/linux/Versions
sysdeps/unix/sysv/linux/arm/be/libc.abilist
sysdeps/unix/sysv/linux/arm/le/libc.abilist
sysdeps/unix/sysv/linux/csky/libc.abilist
sysdeps/unix/sysv/linux/hppa/libc.abilist
sysdeps/unix/sysv/linux/i386/libc.abilist
sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
sysdeps/unix/sysv/linux/microblaze/be/libc.abilist
sysdeps/unix/sysv/linux/microblaze/le/libc.abilist
sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
sysdeps/unix/sysv/linux/nios2/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
sysdeps/unix/sysv/linux/sendmmsg.c
sysdeps/unix/sysv/linux/sh/be/libc.abilist
sysdeps/unix/sysv/linux/sh/le/libc.abilist
sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
sysdeps/unix/sysv/linux/tst-scm_rights-time64.c [new file with mode: 0644]
sysdeps/unix/sysv/linux/tst-scm_rights.c [new file with mode: 0644]

index 5577e75b805212f07fff60716bdb79937cf104b7..d02d976bb5d43134d3f1dba01317d120a680093c 100644 (file)
@@ -179,9 +179,21 @@ extern ssize_t sendmsg (int __fd, const struct msghdr *__message,
 
    This function is a cancellation point and therefore not marked with
    __THROW.  */
+# ifndef __USE_TIME_BITS64
 extern int sendmmsg (int __fd, struct mmsghdr *__vmessages,
                     unsigned int __vlen, int __flags);
-#endif
+# else
+#  ifdef __REDIRECT
+extern int __REDIRECT (sendmmsg, (int __fd, struct mmsghdr *__vmessages,
+                                 unsigned int __vlen, int __flags),
+                      __sendmmsg64);
+#  else
+extern int __sendmmsg64 (int __fd, struct mmsghdr *__vmessages,
+                        unsigned int __vlen, int __flags);
+#   define sendmmsg __sendmmsg64
+#  endif
+# endif         /* __USE_TIME_BITS64 */
+#endif /* __USE_GNU */
 
 /* Receive a message as described by MESSAGE from socket FD.
    Returns the number of bytes read or -1 for errors.
index 123f15c2e3692dc26aadf0c84ab95270dca225ee..76ad06361c4323d74ceaf4d69758eddc87d2e9cd 100644 (file)
@@ -122,6 +122,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
         tst-ntp_gettimex tst-sigtimedwait tst-misalign-clone \
   tst-close_range \
   tst-prctl \
+  tst-scm_rights \
   # tests
 
 # Test for the symbol version of fcntl that was replaced in glibc 2.28.
@@ -141,6 +142,7 @@ tests-time64 += \
   tst-sigtimedwait-time64 \
   tst-timerfd-time64 \
   tst-prctl-time64 \
+  tst-scm_rights-time64 \
   # tests-time64
 
 tests-clone-internal = \
index cff3d476da4059d974f7bc24628df782ca5d01c8..a8ec041371f356e5c42bf806a57c9329d718bfac 100644 (file)
@@ -265,6 +265,7 @@ libc {
     __semctl64;
     __semtimedop64;
     __sem_timedwait64;
+    __sendmmsg64;
     __setitimer64;
     __settimeofday64;
     __shmctl64;
index a108dccfe9c4c3909481dcceb98700052e5102ca..740081f235cdf6b70d1103dd9b593495be55e1ce 100644 (file)
@@ -266,6 +266,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 3511d35f5ebf06c077aa0e01e02860c2442cae9f..55f17e1ee3356a517a74ae7710166e41291ce90f 100644 (file)
@@ -263,6 +263,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 40342891a5f929112cdf3df3a16cb53b46727980..610f59aad7443652ef2b06259f601771e75ca337 100644 (file)
@@ -2422,6 +2422,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 1502aaddd4ac3166d26c9cf94574b6d636b45b53..3c6ce135e2134ef2bbd48103058fc73450fb9143 100644 (file)
@@ -2373,6 +2373,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 70a0f7f1c35951e7537a34ed093ed3ab9fe9ea15..2fae97c00c760c7f01bf772ed8382ea50583a4c3 100644 (file)
@@ -2557,6 +2557,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 13ac607c49fb22fc0652bfef14f02605320ef574..c146c01b623fa623a252b187a99cc5214bbcd11f 100644 (file)
@@ -267,6 +267,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 662a51909551db06d1a49c9a7c25f45f278c88b9..dc2397091327bed82820f7fafe7e95762aa385bb 100644 (file)
@@ -2500,6 +2500,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index fc0c6b6acc68ea9fd5862897122db95744176f81..63b86f46136cbf0bf63bf5c352ec462be1767066 100644 (file)
@@ -2473,6 +2473,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 56a52de04913046606e0b2d0f72e1d744a524f6d..4f2811c869b2ee903445467100302f70258ea234 100644 (file)
@@ -2470,6 +2470,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 4aa9e33b7dfaaa879b13a4aa21de6bbb19bc99c6..b3491fd1db8037a5fe7368c2beda97f44278eb5d 100644 (file)
@@ -2465,6 +2465,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 1c1227301b1292f4c2782c24a1e419d5dc840302..7d56039df520f3a87363067ebc570f57b748a667 100644 (file)
@@ -2463,6 +2463,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 876893455e965d4d23334110ec23ca85e8e7e4c6..0898b26a9031d27a26aab675984a1709cce93961 100644 (file)
@@ -2471,6 +2471,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index dc41e174876b3acb91f182b25255b1c286b6892d..19b42df933a8c19dd2145f525b7c8e69bb621faf 100644 (file)
@@ -2512,6 +2512,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 9e3311a978bcc386b020176dd7e59a3aae293e6d..09179d2a48932a98cf2f9505c8eb0b2f98b18647 100644 (file)
@@ -2527,6 +2527,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 2ac6aa068f7696dcb62df1be5d526afe2e7e799d..d45be8ab9e0d44070402fadfcb58f58a8b8bdc83 100644 (file)
@@ -2560,6 +2560,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 644f6b734c2df635b5aac0e5a6af6b56f9804a5d..c290ae49484f6b404c1fc03d95952d53aa2bdc49 100644 (file)
@@ -2525,6 +2525,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 6093e9ed7026e0e1848d7851a997f7a9d332a67d..10aaff4d1f134a3d1beb42d6011323c875055e90 100644 (file)
@@ -35,3 +35,6 @@ __sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
 }
 libc_hidden_def (__sendmmsg)
 weak_alias (__sendmmsg, sendmmsg)
+#if __TIMESIZE != 64
+weak_alias (__sendmmsg, __sendmmsg64)
+#endif
index 369dccc4af5696c1293c5f930d7632aa0e89e071..714f7d4f550fd620406835f8d3514f08dd5e5386 100644 (file)
@@ -2380,6 +2380,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 4254360898a811e93ac203af949a5a82db5c2e16..9f858a4f681b4da80a7f3b83eb0d40c326cfce6d 100644 (file)
@@ -2377,6 +2377,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
index 31f43ed41436c6ad35d0b47b56bba40f9e6760f1..2420775e21fd74819420d0c4c259809b67bca217 100644 (file)
@@ -2520,6 +2520,7 @@ GLIBC_2.34 __sem_clockwait64 F
 GLIBC_2.34 __sem_timedwait64 F
 GLIBC_2.34 __semctl64 F
 GLIBC_2.34 __semtimedop64 F
+GLIBC_2.34 __sendmmsg64 F
 GLIBC_2.34 __setitimer64 F
 GLIBC_2.34 __settimeofday64 F
 GLIBC_2.34 __shmctl64 F
diff --git a/sysdeps/unix/sysv/linux/tst-scm_rights-time64.c b/sysdeps/unix/sysv/linux/tst-scm_rights-time64.c
new file mode 100644 (file)
index 0000000..302613c
--- /dev/null
@@ -0,0 +1 @@
+#include "tst-scm_rights.c"
diff --git a/sysdeps/unix/sysv/linux/tst-scm_rights.c b/sysdeps/unix/sysv/linux/tst-scm_rights.c
new file mode 100644 (file)
index 0000000..c85b873
--- /dev/null
@@ -0,0 +1,186 @@
+/* Smoke test for SCM_RIGHTS.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+/* This test passes a file descriptor from a subprocess to the parent
+   process, using recvmsg/sendmsg or recvmmsg/sendmmsg.  */
+
+#include <fcntl.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <string.h>
+#include <support/check.h>
+#include <support/xunistd.h>
+#include <sys/socket.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+/* String sent over the socket.  */
+static char DATA[] = "descriptor";
+
+/* Path that is to be opened and sent over the socket.  */
+#define PATH "/etc"
+
+/* True if sendmmsg/recvmmsg is to be used.  */
+static bool use_multi_call;
+
+/* The pair of sockets used for coordination.  The subprocess uses
+   sockets[1].  */
+static int sockets[2];
+
+/* Subprocess side of one send/receive test.  */
+_Noreturn static void
+subprocess (void)
+{
+  /* The file descriptor to send.  */
+  int fd = xopen (PATH, O_RDONLY, 0);
+
+  struct iovec iov = { .iov_base = DATA, .iov_len = sizeof (DATA) };
+  union
+  {
+    struct cmsghdr header;
+    char bytes[CMSG_SPACE (sizeof (int))];
+  } cmsg_storage;
+  struct mmsghdr mmhdr =
+    {
+      .msg_hdr =
+      {
+        .msg_iov = &iov,
+        .msg_iovlen = 1,
+        .msg_control = cmsg_storage.bytes,
+        .msg_controllen = sizeof (cmsg_storage),
+      },
+    };
+
+  /* Configure the file descriptor for sending.  */
+  struct cmsghdr *cmsg = CMSG_FIRSTHDR (&mmhdr.msg_hdr);
+  cmsg->cmsg_level = SOL_SOCKET;
+  cmsg->cmsg_type = SCM_RIGHTS;
+  cmsg->cmsg_len = CMSG_LEN (sizeof (int));
+  memcpy (CMSG_DATA (cmsg), &fd, sizeof (fd));
+  mmhdr.msg_hdr.msg_controllen = cmsg->cmsg_len;
+
+  /* Perform the send operation.  */
+  int ret;
+  if (use_multi_call)
+    {
+      ret = sendmmsg (sockets[1], &mmhdr, 1, 0);
+      if (ret >= 0)
+        ret = mmhdr.msg_len;
+    }
+  else
+    ret = sendmsg (sockets[1], &mmhdr.msg_hdr, 0);
+  TEST_COMPARE (ret, sizeof (DATA));
+
+  xclose (fd);
+
+  /* Stop the process from exiting.  */
+  while (true)
+    pause ();
+}
+
+/* Performs one send/receive test.  */
+static void
+one_test (void)
+{
+  TEST_COMPARE (socketpair (AF_UNIX, SOCK_STREAM, 0, sockets), 0);
+
+  pid_t pid = xfork ();
+  if (pid == 0)
+    subprocess ();
+
+  char data_storage[sizeof (DATA) + 1];
+  struct iovec iov =
+    {
+      .iov_base = data_storage,
+      .iov_len = sizeof (data_storage)
+    };
+  union
+  {
+    struct cmsghdr header;
+    char bytes[CMSG_SPACE (sizeof (int))];
+  } cmsg_storage;
+  struct mmsghdr mmhdr =
+    {
+      .msg_hdr =
+      {
+        .msg_iov = &iov,
+        .msg_iovlen = 1,
+        .msg_control = cmsg_storage.bytes,
+        .msg_controllen = sizeof (cmsg_storage),
+      },
+    };
+
+  /* Set up the space for receiving the file descriptor.  */
+  struct cmsghdr *cmsg = CMSG_FIRSTHDR (&mmhdr.msg_hdr);
+  cmsg->cmsg_level = SOL_SOCKET;
+  cmsg->cmsg_type = SCM_RIGHTS;
+  cmsg->cmsg_len = CMSG_LEN (sizeof (int));
+  mmhdr.msg_hdr.msg_controllen = cmsg->cmsg_len;
+
+  /* Perform the receive operation.  */
+  int ret;
+  if (use_multi_call)
+    {
+      ret = recvmmsg (sockets[0], &mmhdr, 1, 0, NULL);
+      if (ret >= 0)
+        ret = mmhdr.msg_len;
+    }
+  else
+    ret = recvmsg (sockets[0], &mmhdr.msg_hdr, 0);
+  TEST_COMPARE (ret, sizeof (DATA));
+  TEST_COMPARE_BLOB (data_storage, sizeof (DATA), DATA, sizeof (DATA));
+
+  /* Extract the file descriptor.  */
+  TEST_VERIFY (CMSG_FIRSTHDR (&mmhdr.msg_hdr) != NULL);
+  TEST_COMPARE (CMSG_FIRSTHDR (&mmhdr.msg_hdr)->cmsg_len,
+                CMSG_LEN (sizeof (int)));
+  TEST_VERIFY (&cmsg_storage.header == CMSG_FIRSTHDR (&mmhdr.msg_hdr));
+  int fd;
+  memcpy (&fd, CMSG_DATA (CMSG_FIRSTHDR (&mmhdr.msg_hdr)), sizeof (fd));
+
+  /* Verify the received file descriptor.  */
+  TEST_VERIFY (fd > 2);
+  struct stat64 st_fd;
+  TEST_COMPARE (fstat64 (fd, &st_fd), 0);
+  struct stat64 st_path;
+  TEST_COMPARE (stat64 (PATH, &st_path), 0);
+  TEST_COMPARE (st_fd.st_ino, st_path.st_ino);
+  TEST_COMPARE (st_fd.st_dev, st_path.st_dev);
+  xclose (fd);
+
+  /* Terminate the subprocess.  */
+  TEST_COMPARE (kill (pid, SIGUSR1), 0);
+  int status;
+  TEST_COMPARE (xwaitpid (pid, &status, 0), pid);
+  TEST_VERIFY (WIFSIGNALED (status));
+  TEST_COMPARE (WTERMSIG (status), SIGUSR1);
+
+  xclose (sockets[0]);
+  xclose (sockets[1]);
+}
+
+static int
+do_test (void)
+{
+  one_test ();
+  use_multi_call = true;
+  one_test ();
+  return 0;
+}
+
+#include <support/test-driver.c>