From bcbce1845f12def0b530f8ce0e751d0b194d491d Mon Sep 17 00:00:00 2001 From: Chuck Zmudzinski Date: Wed, 2 Aug 2023 15:49:03 -0400 Subject: [PATCH] Add option to run vncsession without forking and detaching 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 #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 #1649 --- unix/vncserver/vncsession.c | 26 +++++++++++++++++++------- unix/vncserver/vncsession.man.in | 9 +++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/unix/vncserver/vncsession.c b/unix/vncserver/vncsession.c index c722922183..238029a1f8 100644 --- a/unix/vncserver/vncsession.c +++ b/unix/vncserver/vncsession.c @@ -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] \n", argv[0]); + return EX_USAGE; + } + } else if ((argc != 3) || (argv[2][0] != ':')) { fprintf(stderr, "Syntax:\n"); - fprintf(stderr, " %s \n", argv[0]); + fprintf(stderr, " %s [-D] \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"); @@ -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); @@ -586,7 +597,8 @@ main(int argc, char **argv) fclose(f); } - finish_daemon(); + if (forking) + finish_daemon(); while (1) { int status; diff --git a/unix/vncserver/vncsession.man.in b/unix/vncserver/vncsession.man.in index 4efad41bc5..54ecd4d5fa 100644 --- a/unix/vncserver/vncsession.man.in +++ b/unix/vncserver/vncsession.man.in @@ -3,6 +3,7 @@ vncsession \- start a VNC server .SH SYNOPSIS .B vncsession +.RI [-D] .RI < username > .RI <: display# > .SH DESCRIPTION @@ -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