diff --git a/src/main.c b/src/main.c index 6efba6c..dafbcc9 100644 --- a/src/main.c +++ b/src/main.c @@ -80,6 +80,7 @@ enum socket_type { SOCKET_TYPE_TCP = 0, SOCKET_TYPE_UNIX, SOCKET_TYPE_WEBSOCKET, + SOCKET_TYPE_FROM_FD, }; struct wayvnc { @@ -885,7 +886,7 @@ static char* get_cfg_path(const struct cfg* cfg, char* dst, const char* src) } static int init_nvnc(struct wayvnc* self, const char* addr, uint16_t port, - enum socket_type socket_type) + int fd, enum socket_type socket_type) { switch (socket_type) { case SOCKET_TYPE_TCP: @@ -897,15 +898,20 @@ static int init_nvnc(struct wayvnc* self, const char* addr, uint16_t port, case SOCKET_TYPE_WEBSOCKET: self->nvnc = nvnc_open_websocket(addr, port); break; + case SOCKET_TYPE_FROM_FD: + self->nvnc = nvnc_open_from_fd(fd); + break; default: abort(); } if (!self->nvnc) { - nvnc_log(NVNC_LOG_ERROR, "Failed to bind to address. Add -Ldebug to the argument list for more info."); + nvnc_log(NVNC_LOG_ERROR, "Failed to listen on socket or bind to its address. Add -Ldebug to the argument list for more info."); return -1; } if (socket_type == SOCKET_TYPE_UNIX) nvnc_log(NVNC_LOG_INFO, "Listening for connections on %s", addr); + else if (socket_type == SOCKET_TYPE_FROM_FD) + nvnc_log(NVNC_LOG_INFO, "Listening for connections on fd %d", fd); else nvnc_log(NVNC_LOG_INFO, "Listening for connections on %s:%d", addr, port); @@ -1705,6 +1711,7 @@ int main(int argc, char* argv[]) const char* address = NULL; int port = 0; + int external_listener_fd = -1; bool use_unix_socket = false; bool use_websocket = false; bool start_detached = false; @@ -1754,6 +1761,9 @@ int main(int argc, char* argv[]) "Show performance counters." }, { 'u', "unix-socket", NULL, "Create unix domain socket." }, + { 'x', "external-listener-fd", "", + "Listen on a bound socket at instead of binding to an address.", + .default_ = "-1" }, { 'd', "disable-input", NULL, "Disable all remote input." }, { 'D', "detached", NULL, @@ -1796,6 +1806,7 @@ int main(int argc, char* argv[]) show_performance = !!option_parser_get_value(&option_parser, "performance"); use_unix_socket = !!option_parser_get_value(&option_parser, "unix-socket"); use_websocket = !!option_parser_get_value(&option_parser, "websocket"); + external_listener_fd = atoi(option_parser_get_value(&option_parser, "external-listener-fd")); disable_input = !!option_parser_get_value(&option_parser, "disable-input"); log_level = option_parser_get_value(&option_parser, "verbose") ? NVNC_LOG_INFO : NVNC_LOG_WARNING; @@ -1831,6 +1842,16 @@ int main(int argc, char* argv[]) return 1; } + if (external_listener_fd >= 0 && use_unix_socket) { + nvnc_log(NVNC_LOG_ERROR, "external-listener-fd and unix-socket are conflicting options"); + return 1; + } + + if (external_listener_fd >= 0 && use_websocket) { + nvnc_log(NVNC_LOG_ERROR, "external-listener-fd and websocket are conflicting options"); + return 1; + } + if (use_transient_seat && disable_input) { nvnc_log(NVNC_LOG_ERROR, "transient-seat and disable-input are conflicting options"); return 1; @@ -1862,6 +1883,16 @@ int main(int argc, char* argv[]) if (!port) port = self.cfg.port; } + if (external_listener_fd >= 0 && address) { + nvnc_log(NVNC_LOG_ERROR, "external-listener-fd and address are conflicting options"); + return 1; + } + + if (external_listener_fd >= 0 && port) { + nvnc_log(NVNC_LOG_ERROR, "external-listener-fd and port are conflicting options"); + return 1; + } + if (!address) address = DEFAULT_ADDRESS; if (!port) port = DEFAULT_PORT; @@ -1928,6 +1959,8 @@ int main(int argc, char* argv[]) socket_type = SOCKET_TYPE_UNIX; else if (use_websocket) socket_type = SOCKET_TYPE_WEBSOCKET; + else if (external_listener_fd >= 0) + socket_type = SOCKET_TYPE_FROM_FD; if (!start_detached) { if (self.screencopy.manager) @@ -1961,7 +1994,7 @@ int main(int argc, char* argv[]) if (!self.ctl) goto ctl_server_failure; - if (init_nvnc(&self, address, port, socket_type) < 0) + if (init_nvnc(&self, address, port, external_listener_fd, socket_type) < 0) goto nvnc_failure; if (self.display) diff --git a/wayvnc.scd b/wayvnc.scd index f7a07ad..b9c8c28 100644 --- a/wayvnc.scd +++ b/wayvnc.scd @@ -55,6 +55,11 @@ wayvnc - A VNC server for wlroots based Wayland compositors. *-w, --websocket* Create a websocket. +*-x, --external-listener-fd=* + Have the VNC server listen on an already bound socket at this file + descriptor which should be inherited from wayvnc's parent process. + This is incompatible with all other server socket-related options. + *-L, --log-level* Set log level. The levels are: error, warning, info, debug, trace and quiet.