~ I speak web socket . * * Actually that's dumb, websocket (aka rfc6455) looks nothing like that. */
| 730 | * |
| 731 | * Actually that's dumb, websocket (aka rfc6455) looks nothing like that. */ |
| 732 | static struct io_plan *websocket_connection_in(struct io_conn *conn, |
| 733 | struct daemon *daemon) |
| 734 | { |
| 735 | int childmsg[2], execfail[2]; |
| 736 | pid_t childpid; |
| 737 | int err; |
| 738 | struct conn_in conn_in_arg; |
| 739 | |
| 740 | /* Did we fail to accept? */ |
| 741 | if (!conn) |
| 742 | return accept_failed(daemon); |
| 743 | |
| 744 | conn_in_arg.addr.u.wireaddr.is_websocket = true; |
| 745 | if (!get_remote_address(conn, &conn_in_arg.addr)) |
| 746 | return io_close(conn); |
| 747 | |
| 748 | status_debug("Websocket connection in from %s", |
| 749 | fmt_wireaddr_internal(tmpctx, &conn_in_arg.addr)); |
| 750 | |
| 751 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, childmsg) != 0) |
| 752 | goto fail; |
| 753 | |
| 754 | if (pipe(execfail) != 0) |
| 755 | goto close_msgfd_fail; |
| 756 | |
| 757 | if (fcntl(execfail[1], F_SETFD, fcntl(execfail[1], F_GETFD) |
| 758 | | FD_CLOEXEC) < 0) |
| 759 | goto close_execfail_fail; |
| 760 | |
| 761 | childpid = fork(); |
| 762 | if (childpid < 0) |
| 763 | goto close_execfail_fail; |
| 764 | |
| 765 | if (childpid == 0) { |
| 766 | close(childmsg[0]); |
| 767 | close(execfail[0]); |
| 768 | |
| 769 | /* Attach remote socket to stdin. */ |
| 770 | if (dup2(io_conn_fd(conn), STDIN_FILENO) == -1) |
| 771 | goto child_errno_fail; |
| 772 | |
| 773 | /* Attach our socket to stdout. */ |
| 774 | if (dup2(childmsg[1], STDOUT_FILENO) == -1) |
| 775 | goto child_errno_fail; |
| 776 | |
| 777 | /* Make (fairly!) sure all other fds are closed. */ |
| 778 | closefrom(STDERR_FILENO + 1); |
| 779 | |
| 780 | /* Tell websocket helper what we read so far. */ |
| 781 | execlp(daemon->websocket_helper, daemon->websocket_helper, |
| 782 | NULL); |
| 783 | |
| 784 | child_errno_fail: |
| 785 | err = errno; |
| 786 | /* Gcc's warn-unused-result fail. */ |
| 787 | if (write(execfail[1], &err, sizeof(err))) { |
| 788 | ; |
| 789 | } |
nothing calls this directly
no test coverage detected