FreeBSD Bugzilla – Attachment 192211 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
fdpass.c (text/plain), 2.42 KB, created by
Jan Kokemüller
on 2018-04-04 14:24:45 UTC
(
hide
)
Description:
test program
Filename:
MIME Type:
Creator:
Jan Kokemüller
Created:
2018-04-04 14:24:45 UTC
Size:
2.42 KB
patch
obsolete
>#include <sys/types.h> > >#include <sys/procdesc.h> >#include <sys/socket.h> >#include <sys/wait.h> > >#include <err.h> >#include <poll.h> >#include <signal.h> >#include <stdio.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); > >int main() { > for (;;) { > pid_t pid; > int child_fd; > int sock[2]; > > fprintf(stderr, "next gen\n"); > > if (socketpair(PF_UNIX, SOCK_STREAM, 0, sock) < 0) { > err(1, "socketpair"); > } > > pid = pdfork(&child_fd, PD_CLOEXEC); > if (pid < 0) { > err(1, "pdfork"); > } > > if (pid == 0) { > close(sock[0]); > int sock_child[2]; > int dummy = 0; > > if (socketpair(PF_UNIX, SOCK_STREAM, /**/ > 0, sock_child) < 0) { > err(1, "socketpair"); > } > > // fprintf(stderr, "dummy write/read\n"); > // if (write(sock_child[1], &dummy, 1) != 1) { > // err(1, "write"); > // } > // if (read(sock_child[0], &dummy, 1) != 1) { > // err(1, "read"); > // } > > fprintf(stderr, "sending socket...\n"); > if (fd_send(sock[1], &sock_child[0], 1) != 0) { > errx(1, "fd_send failed"); > } > if (read(sock[1], &dummy, 1) != 1) { > err(1, "write"); > } > fprintf(stderr, "sent socket\n"); > > close(sock_child[0]); > > if (write(sock_child[1], &dummy, 1) != 1) { > err(1, "write"); > } > > ssize_t ret; > if ((ret = read(sock_child[1], &dummy, 1)) != 1) { > errx(1, "read failed in child: %d", (int)ret); > } > > close(sock_child[1]); > > _exit(0); > } > > close(sock[1]); > > int sock_child; > uint8_t dummy; > > fprintf(stderr, "recv socket...\n"); > if (fd_recv(sock[0], &sock_child, 1) != 0) { > errx(1, "fd_recv failed"); > } > if (write(sock[0], &dummy, 1) != 1) { > err(1, "write"); > } > fprintf(stderr, "recved socket\n"); > > ssize_t ret; > fprintf(stderr, "reading one byte...\n"); > if ((ret = read(sock_child, &dummy, 1)) != 1) { > int error; > socklen_t err_len = sizeof(error); > if (getsockopt(sock_child, SOL_SOCKET, SO_ERROR, > &error, &err_len) < 0) { > err(1, "getsockopt"); > } > > fprintf(stderr, "got err\n"); > ssize_t ret2 = read(sock_child, &dummy, 1); > > errx(1, > "read failed in parent: %d, so_error: %s (%d), ret2: %d", > (int)ret, strerror(error), error, (int)ret2); > } > > if (write(sock_child, &dummy, 1) != 1) { > err(1, "write"); > } > > close(sock_child); > > struct pollfd pfd = { .fd = child_fd }; > poll(&pfd, 1, -1); > > close(child_fd); > close(sock[0]); > } >}
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