about summary refs log tree commit diff
path: root/REORG.TODO/nptl/tst-cancel4_1.c
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2017-06-08 15:39:03 -0400
committerZack Weinberg <zackw@panix.com>2017-06-08 15:39:03 -0400
commit5046dbb4a7eba5eccfd258f92f4735c9ffc8d069 (patch)
tree4470480d904b65cf14ca524f96f79eca818c3eaf /REORG.TODO/nptl/tst-cancel4_1.c
parent199fc19d3aaaf57944ef036e15904febe877fc93 (diff)
downloadglibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.tar.gz
glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.tar.xz
glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.zip
Prepare for radical source tree reorganization. zack/build-layout-experiment
All top-level files and directories are moved into a temporary storage
directory, REORG.TODO, except for files that will certainly still
exist in their current form at top level when we're done (COPYING,
COPYING.LIB, LICENSES, NEWS, README), all old ChangeLog files (which
are moved to the new directory OldChangeLogs, instead), and the
generated file INSTALL (which is just deleted; in the new order, there
will be no generated files checked into version control).
Diffstat (limited to 'REORG.TODO/nptl/tst-cancel4_1.c')
-rw-r--r--REORG.TODO/nptl/tst-cancel4_1.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/REORG.TODO/nptl/tst-cancel4_1.c b/REORG.TODO/nptl/tst-cancel4_1.c
new file mode 100644
index 0000000000..0f41965ed1
--- /dev/null
+++ b/REORG.TODO/nptl/tst-cancel4_1.c
@@ -0,0 +1,109 @@
+/* Check sendmmsg cancellation.
+
+   Copyright (C) 2016-2017 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <unistd.h>
+#include <errno.h>
+#include <pthread.h>
+
+#include "tst-cancel4-common.h"
+
+static void *
+tf_sendmmsg (void *arg)
+{
+  if (arg == NULL)
+    // XXX If somebody can provide a portable test case in which sendmmsg()
+    // blocks we can enable this test to run in both rounds.
+    abort ();
+
+  struct sockaddr_un sun;
+
+  tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
+  if (tempfd == -1)
+    FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
+
+  int tries = 0;
+  do
+    {
+      if (++tries > 10)
+	FAIL_EXIT1 ("too many unsuccessful bind calls");
+
+      strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
+      if (mktemp (sun.sun_path) == NULL)
+	FAIL_EXIT1 ("cannot generate temp file name");
+
+      sun.sun_family = AF_UNIX;
+    }
+  while (bind (tempfd, (struct sockaddr *) &sun,
+	       offsetof (struct sockaddr_un, sun_path)
+	       + strlen (sun.sun_path) + 1) != 0);
+  tempfname = strdup (sun.sun_path);
+
+  tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
+  if (tempfd2 == -1)
+    FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
+
+  int r = pthread_barrier_wait (&b2);
+  if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+    FAIL_EXIT1 ("pthread_barrier_wait");
+
+  r = pthread_barrier_wait (&b2);
+  if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+    FAIL_EXIT1 ("pthread_barrier_wait");
+
+  pthread_cleanup_push (cl, NULL);
+
+  char mem[1];
+  struct iovec iov[1];
+  iov[0].iov_base = mem;
+  iov[0].iov_len = 1;
+
+  struct mmsghdr mm;
+  mm.msg_hdr.msg_name = &sun;
+  mm.msg_hdr.msg_namelen = (offsetof (struct sockaddr_un, sun_path)
+			   + strlen (sun.sun_path) + 1);
+  mm.msg_hdr.msg_iov = iov;
+  mm.msg_hdr.msg_iovlen = 1;
+  mm.msg_hdr.msg_control = NULL;
+  mm.msg_hdr.msg_controllen = 0;
+
+  ssize_t ret = sendmmsg (tempfd2, &mm, 1, 0);
+  if (ret == -1 && errno == ENOSYS)
+    exit (77);
+
+  pthread_cleanup_pop (0);
+
+  FAIL_EXIT1 ("sendmmsg returned");
+}
+
+struct cancel_tests tests[] =
+{
+  ADD_TEST (sendmmsg, 2, 1),
+};
+#define ntest_tf (sizeof (tests) / sizeof (tests[0]))
+
+#include "tst-cancel4-common.c"