Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External listener fd #310

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ enum socket_type {
SOCKET_TYPE_TCP = 0,
SOCKET_TYPE_UNIX,
SOCKET_TYPE_WEBSOCKET,
SOCKET_TYPE_FROM_FD,
};

struct wayvnc {
Expand Down Expand Up @@ -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:
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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", "<fd>",
"Listen on a bound socket at <fd> instead of binding to an address.",
.default_ = "-1" },
{ 'd', "disable-input", NULL,
"Disable all remote input." },
{ 'D', "detached", NULL,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1831,13 +1842,23 @@ 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;
}

if (seat_name && use_transient_seat) {
nvnc_log(NVNC_LOG_ERROR, "transient seat and seat are conflicting options");
nvnc_log(NVNC_LOG_ERROR, "transient-seat and seat are conflicting options");
layercak3 marked this conversation as resolved.
Show resolved Hide resolved
return 1;
}

Expand All @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions wayvnc.scd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ wayvnc - A VNC server for wlroots based Wayland compositors.
*-C, --config=<path>*
Select a config file.

*-g,--gpu*
*-g, --gpu*
layercak3 marked this conversation as resolved.
Show resolved Hide resolved
Enable features that require GPU.

*-o, --output=<name>*
Expand Down Expand Up @@ -49,13 +49,18 @@ wayvnc - A VNC server for wlroots based Wayland compositors.
*-V, --version*
Show version info.

*-v,--verbose*
*-v, --verbose*
Be more verbose. Same as setting `--log-level=info`.

*-w,--websocket*
*-w, --websocket*
Create a websocket.

*-L,--log-level*
*-x, --external-listener-fd=<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.

Expand Down
Loading