Skip to content

Commit 33bb72d

Browse files
committed
Fix systemd socket activation support
Fix systemd socket activation with passing listening sockets. (Seems only inetd style accept=yes systemd socket activation was actually working previously) Can be used with systemd units among the lines of: x11vnc.service == [Unit] Description=VNC server Requires=x11vnc.socket [Service] Type=simple ExecStart=/usr/bin/x11vnc -no6 -xkb -repeat -auth guess -display WAIT:0 -forever -shared == x11vnc.socket == [Unit] Description=VNC server socket [Socket] ListenStream=5900 [Install] WantedBy=sockets.target == systemctl enable x11vnc.socket Signed-off-by: Floris Bos <bos@je-eigen-domein.nl>
1 parent 0b89907 commit 33bb72d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

libvncserver/sockets.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,27 @@ rfbInitSockets(rfbScreenInfoPtr rfbScreen)
183183
rfbSocket sock = SD_LISTEN_FDS_START + 0;
184184
if (sd_is_socket(sock, AF_UNSPEC, 0, 0))
185185
rfbNewConnectionFromSock(rfbScreen, sock);
186-
else if (sd_is_socket(sock, AF_UNSPEC, 0, 1))
186+
else if (sd_is_socket(sock, AF_UNSPEC, 0, 1)) {
187+
struct sockaddr_storage sa;
188+
int sa_len = sizeof(sa);
189+
char hoststr[NI_MAXHOST];
190+
char portstr[NI_MAXSERV];
191+
192+
if (getsockname(sock, (struct sockaddr *) &sa, &sa_len) == 0
193+
&& getnameinfo((struct sockaddr *)&sa, sa_len, hoststr, sizeof(hoststr),
194+
portstr, sizeof(portstr), NI_NUMERICHOST | NI_NUMERICSERV) == 0) {
195+
rfbLog("Socket activation through systemd. Listening for VNC connections on %s:%s\n", hoststr, portstr);
196+
rfbScreen->port = atoi(portstr);
197+
} else {
198+
rfbLogPerror("Error retrieving nameinfo of socket received from systemd\n");
199+
}
200+
201+
FD_ZERO(&(rfbScreen->allFds));
202+
rfbScreen->listenSock = sock;
203+
FD_SET(rfbScreen->listenSock, &(rfbScreen->allFds));
204+
rfbScreen->maxFd = rfbScreen->listenSock;
187205
rfbProcessNewConnection(rfbScreen);
206+
}
188207
return;
189208
}
190209
else

0 commit comments

Comments
 (0)