MCPcopy Create free account
hub / github.com/ElementsProject/lightning / websocket_connection_in

Function websocket_connection_in

connectd/connectd.c:473–562  ·  view source on GitHub ↗

~ I speak web socket . * * Actually that's dumb, websocket (aka rfc6455) looks nothing like that. */

Source from the content-addressed store, hash-verified

471 *
472 * Actually that's dumb, websocket (aka rfc6455) looks nothing like that. */
473static struct io_plan *websocket_connection_in(struct io_conn *conn,
474 struct daemon *daemon)
475{
476 int childmsg[2], execfail[2];
477 pid_t childpid;
478 int err;
479 struct conn_in conn_in_arg;
480
481 if (!get_remote_address(conn, &conn_in_arg.addr))
482 return io_close(conn);
483
484 status_debug("Websocket connection in from %s",
485 type_to_string(tmpctx, struct wireaddr_internal,
486 &conn_in_arg.addr));
487
488 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, childmsg) != 0)
489 goto fail;
490
491 if (pipe(execfail) != 0)
492 goto close_msgfd_fail;
493
494 if (fcntl(execfail[1], F_SETFD, fcntl(execfail[1], F_GETFD)
495 | FD_CLOEXEC) < 0)
496 goto close_execfail_fail;
497
498 childpid = fork();
499 if (childpid < 0)
500 goto close_execfail_fail;
501
502 if (childpid == 0) {
503 close(childmsg[0]);
504 close(execfail[0]);
505
506 /* Attach remote socket to stdin. */
507 if (dup2(io_conn_fd(conn), STDIN_FILENO) == -1)
508 goto child_errno_fail;
509
510 /* Attach our socket to stdout. */
511 if (dup2(childmsg[1], STDOUT_FILENO) == -1)
512 goto child_errno_fail;
513
514 /* Make (fairly!) sure all other fds are closed. */
515 closefrom(STDERR_FILENO + 1);
516
517 /* Tell websocket helper what we read so far. */
518 execlp(daemon->websocket_helper, daemon->websocket_helper,
519 NULL);
520
521 child_errno_fail:
522 err = errno;
523 /* Gcc's warn-unused-result fail. */
524 if (write(execfail[1], &err, sizeof(err))) {
525 ;
526 }
527 exit(127);
528 }
529
530 close(childmsg[1]);

Callers

nothing calls this directly

Calls 7

get_remote_addressFunction · 0.85
io_closeFunction · 0.85
io_conn_fdFunction · 0.85
closefromFunction · 0.85
tal_parentFunction · 0.85
close_noerrFunction · 0.85
type_to_stringClass · 0.50

Tested by

no test coverage detected