FreeBSD Bugzilla – Attachment 192514 Details for
Bug 227285
File descriptor passing does not work reliably on SMP system
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
test program (faster reproduction)
fdpass-race-fast.c (text/plain), 2.64 KB, created by
Jan Kokemüller
on 2018-04-14 19:42:45 UTC
(
hide
)
Description:
test program (faster reproduction)
Filename:
MIME Type:
Creator:
Jan Kokemüller
Created:
2018-04-14 19:42:45 UTC
Size:
2.64 KB
patch
obsolete
>#include <sys/types.h> > >#include <sys/event.h> >#include <sys/socket.h> >#include <sys/sysctl.h> >#include <sys/wait.h> > >#include <stdatomic.h> > >#include <err.h> >#include <poll.h> >#include <pthread.h> >#include <signal.h> >#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <unistd.h> > >/* From libnv. */ >extern int fd_send(int sock, const int *fds, size_t nfds); >extern int fd_recv(int sock, int *fds, size_t nfds); > >/* > * This thread triggers the unp garbage collector. Domain socket loops are > * created that can only be cleaned up by the garbage collector. > */ >static void * >trigger_gc(void *dummy_arg) >{ > int sock[2]; > > (void)dummy_arg; > > for (;;) { > if (socketpair(PF_UNIX, SOCK_STREAM, 0, sock) < 0) { > err(1, "socketpair"); > } > > if (fd_send(sock[1], &sock[0], 1) != 0) { > errx(1, "fd_send failed"); > } > > close(sock[0]); > close(sock[1]); > } >} >static unsigned long counter = 0; > >static void >print_info() >{ > int unp_recycled; > size_t unp_recycled_size = sizeof(unp_recycled); > char const recycled_sysctl[] = "net.local.recycled"; > > if (sysctlbyname(recycled_sysctl, &unp_recycled, > &unp_recycled_size, NULL, 0) < 0 || > unp_recycled_size != sizeof(unp_recycled)) { > err(1, "sysctlbyname"); > } > > fprintf(stdout, "%9lu, %s: %9d\n", /**/ > counter, recycled_sysctl, unp_recycled); >} > >static int comm_sock[2] = { -1, -1 }; > >static void * >create_sock(void *dummy_arg) >{ > uint8_t dummy = 0; > int sock[2] = { -1, -1 }; > > (void)dummy_arg; > > for (;;) { > if (socketpair(PF_UNIX, SOCK_STREAM, 0, sock) < 0) { > err(1, "socketpair"); > } > ++counter; > > if (fd_send(comm_sock[1], &sock[0], 1) != 0) { > errx(1, "fd_send failed"); > } > > close(sock[0]); > > if (write(sock[1], &dummy, 1) != 1) { > errx(1, "write error"); > } > > > if (read(sock[1], &dummy, 1) != 1) { > errx(1, "read error"); > } > > close(sock[1]); > > if (!(counter % 10000)) { > print_info(); > } > } > > return (NULL); >} > >int >main() >{ > pthread_t socket_create_thread; > pthread_t gc_trigger_thread; > int sock_client; > uint8_t dummy; > ssize_t rc; > > atexit(print_info); > print_info(); > > if (pthread_create(&gc_trigger_thread, NULL, trigger_gc, NULL)) { > err(1, "pthread_create"); > } > > if (socketpair(PF_UNIX, SOCK_STREAM, 0, comm_sock) < 0) { > err(1, "socketpair"); > } > > if (pthread_create(&socket_create_thread, NULL, create_sock, NULL)) { > err(1, "pthread_create"); > } > > for (;;) { > if (fd_recv(comm_sock[0], &sock_client, 1) != 0) { > errx(1, "fd_recv failed"); > } > > if ((rc = read(sock_client, &dummy, 1)) != 1) { > if (rc < 0) { > err(1, "read"); > } else { > errx(1, "read: EOF"); > } > } > > if (write(sock_client, &dummy, 1) < 0) { > err(1, "write error"); > } > > close(sock_client); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 227285
:
192211
|
192213
|
192214
|
192216
|
192350
| 192514 |
192515