~ I speak web socket . * * Actually that's dumb, websocket (aka rfc6455) looks nothing like that. */
| 678 | * |
| 679 | * Actually that's dumb, websocket (aka rfc6455) looks nothing like that. */ |
| 680 | static struct io_plan *websocket_connection_in(struct io_conn *conn, |
| 681 | struct daemon *daemon) |
| 682 | { |
| 683 | int childmsg[2], execfail[2]; |
| 684 | pid_t childpid; |
| 685 | int err; |
| 686 | struct conn_in conn_in_arg; |
| 687 | |
| 688 | conn_in_arg.addr.u.wireaddr.is_websocket = true; |
| 689 | if (!get_remote_address(conn, &conn_in_arg.addr)) |
| 690 | return io_close(conn); |
| 691 | |
| 692 | status_debug("Websocket connection in from %s", |
| 693 | fmt_wireaddr_internal(tmpctx, &conn_in_arg.addr)); |
| 694 | |
| 695 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, childmsg) != 0) |
| 696 | goto fail; |
| 697 | |
| 698 | if (pipe(execfail) != 0) |
| 699 | goto close_msgfd_fail; |
| 700 | |
| 701 | if (fcntl(execfail[1], F_SETFD, fcntl(execfail[1], F_GETFD) |
| 702 | | FD_CLOEXEC) < 0) |
| 703 | goto close_execfail_fail; |
| 704 | |
| 705 | childpid = fork(); |
| 706 | if (childpid < 0) |
| 707 | goto close_execfail_fail; |
| 708 | |
| 709 | if (childpid == 0) { |
| 710 | close(childmsg[0]); |
| 711 | close(execfail[0]); |
| 712 | |
| 713 | /* Attach remote socket to stdin. */ |
| 714 | if (dup2(io_conn_fd(conn), STDIN_FILENO) == -1) |
| 715 | goto child_errno_fail; |
| 716 | |
| 717 | /* Attach our socket to stdout. */ |
| 718 | if (dup2(childmsg[1], STDOUT_FILENO) == -1) |
| 719 | goto child_errno_fail; |
| 720 | |
| 721 | /* Make (fairly!) sure all other fds are closed. */ |
| 722 | closefrom(STDERR_FILENO + 1); |
| 723 | |
| 724 | /* Tell websocket helper what we read so far. */ |
| 725 | execlp(daemon->websocket_helper, daemon->websocket_helper, |
| 726 | NULL); |
| 727 | |
| 728 | child_errno_fail: |
| 729 | err = errno; |
| 730 | /* Gcc's warn-unused-result fail. */ |
| 731 | if (write(execfail[1], &err, sizeof(err))) { |
| 732 | ; |
| 733 | } |
| 734 | exit(127); |
| 735 | } |
| 736 | |
| 737 | close(childmsg[1]); |
nothing calls this directly
no test coverage detected