kfmut Was also thinking about using vncserver script in rc.d service but for some reason was thinking that using su isn't OK for that 🤔
Why? Truthfully speaking, su
is invoked by the rc.subr(8) script to change the process ownership to that of the unprivileged user optionally specified by the $name_user variable within the service script (providing $name_chroot hasn't been given at the same time, they're mutually exclusive); have a look at rc.subr sources.
The rationale behind using a su
hook to start/stop the service in place of a standard $name_user variable is that $name_user defaults to su -m
, as opposed to su -l
. The latter simulates a full login, by discarding root's environment –which is why I recommended you to define TERM capabilities system-wide– changing the working directory to target's HOME and setting the PATH to that of target's login class, as defined in /etc/login.conf.
vncserver
needs to be started from user's home in order to detect the ~/.vnc dir and create a session-specific process pid with proper ownership/permissions (for this reason I didn't define/check a process pid in my service script, normally one would have it set to /var/run/{name}.pid). It also requires xauth
(which on NetBSD resides at /usr/X11R7/bin) to be found within the PATH. If started with su -m
vncserver shall attempt (and fail) to create a .vnc dir at /.