Skip to content

Commit

Permalink
Add option to run vncsession without forking and detaching
Browse files Browse the repository at this point in the history
Option is -D, which is what sshd uses for the same option.

Also added description of the new option to the vncsession
man page.

Tested on top of up-to-date version 1.13.80,
commit 094496e (Merge pull request TigerVNC#1648 from TigerVNC/copyright)
on Void Linux with runit system service manager.

Also tested on top of Fedora 38 with version 1.13.1 and systemd
with Type=exec service and -D option passed to vncsession in
vncsession-start.

Resolves TigerVNC#1649
  • Loading branch information
zmudc committed Aug 31, 2023
1 parent c5ad3d6 commit dd6f4b4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
26 changes: 19 additions & 7 deletions unix/vncserver/vncsession.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,23 @@ main(int argc, char **argv)

const char *username, *display;

if ((argc != 3) || (argv[2][0] != ':')) {
int forking = 1;
if (argc == 4) {
if ((getopt(argc, argv, "D") == 'D') && (argv[3][0] == ':'))
forking = 0;
else {
fprintf(stderr, "Syntax:\n");
fprintf(stderr, " %s [-D] <username> <display>\n", argv[0]);
return EX_USAGE;
}
} else if ((argc != 3) || (argv[2][0] != ':')) {
fprintf(stderr, "Syntax:\n");
fprintf(stderr, " %s <username> <display>\n", argv[0]);
fprintf(stderr, " %s [-D] <username> <display>\n", argv[0]);
return EX_USAGE;
}

username = argv[1];
display = argv[2];
username = argv[argc - 2];
display = argv[argc - 1];

if (geteuid() != 0) {
fprintf(stderr, "This program needs to be run as root!\n");
Expand All @@ -534,8 +543,10 @@ main(int argc, char **argv)
return EX_OSERR;
}

if (begin_daemon() == -1)
return EX_OSERR;
if (forking) {
if (begin_daemon() == -1)
return EX_OSERR;
}

openlog("vncsession", LOG_PID, LOG_AUTH);

Expand Down Expand Up @@ -586,7 +597,8 @@ main(int argc, char **argv)
fclose(f);
}

finish_daemon();
if (forking)
finish_daemon();

while (1) {
int status;
Expand Down
9 changes: 9 additions & 0 deletions unix/vncserver/vncsession.man.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
vncsession \- start a VNC server
.SH SYNOPSIS
.B vncsession
.RI [-D]
.RI < username >
.RI <: display# >
.SH DESCRIPTION
Expand All @@ -16,6 +17,14 @@ appropriate options and starts a window manager on the VNC desktop.
is rarely called directly and is normally started by the system service
manager.

.SH -D OPTION
.B vncsession
by default forks and detaches so it normally is a systemd Type=forking service.
If the -D option is used, it does not fork and detach. This option is provided
for use with other types of systemd services such as Type=simple and Type=exec
and for use with non-systemd system service managers that are not compatible
with Type=forking services.

.SH FILES
Several VNC-related files are found in the directory $HOME/.vnc:
.TP
Expand Down

0 comments on commit dd6f4b4

Please sign in to comment.