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 add description of the new option to the vncsession
man page.

Tested on Void Linux using the new option, also tested on
Fedora without using the new option.

Resolves #1649
  • Loading branch information
zmudc committed Nov 20, 2023
1 parent 2d0d516 commit 444c7cc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
38 changes: 29 additions & 9 deletions unix/vncserver/vncsession.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,14 @@ run_script(const char *username, const char *display, char **envp)
_exit(EX_OSERR);
}

static void
usage(void)
{
fprintf(stderr, "Syntax:\n");
fprintf(stderr, " vncsession [-D] <username> <display>\n");
exit(EX_USAGE);
}

int
main(int argc, char **argv)
{
Expand All @@ -511,14 +519,23 @@ main(int argc, char **argv)

const char *username, *display;

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

while ((opt = getopt(argc, argv, "D")) != -1) {
switch (opt) {
case 'D':
forking = 0;
break;
default:
usage();
}
}

username = argv[1];
display = argv[2];
if ((argc != optind + 2) || (argv[optind +1][0] != ':'))
usage();

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 +551,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 +605,8 @@ main(int argc, char **argv)
fclose(f);
}

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

while (1) {
int status;
Expand Down
10 changes: 10 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,15 @@ 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. If the -D option is used, it does not fork and
detach. This option is provided for use with system service managers that
require services to run in the foreground. This option is not intended for
debugging in a login shell from a terminal or for running
.B vncsession
from a terminal as an ordinary user.

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

0 comments on commit 444c7cc

Please sign in to comment.