Solved [Solved] Shutdown detection methodology

I am the developer of the PCDM login manager for the PC-BSD project, and I am trying to set[ ]up PCDM to be able to detect when the system is getting ready to shutdown/restart to make sure that it doesn't restart X again.

I am already checking for the existance of /var/run/nologin, but that was still not catching about 90% of the shutdown/restart processes from the various desktop environments (I am testing KDE, MATE, GNOME3, Cinnamon, Xfce, LXDE). I then added an additional check (using pgrep) for the "shutdown", "reboot", and "halt" processes but that is not having any luck either.

Is there any other method for checking whether the system is scheduled for a shutdown/restart? I am not sure how the DE's are triggering the system event, so I am looking for a general method that should always work (in theory).
 
Re: Shutdown detection methodology

Look in pam.conf(). In FreeBSD, /sbin/nologin exists and you have to use PAM to set it.

That is to set the value you want.
 
Re: Shutdown detection methodology

I may be way off, but would adding the standard
Code:
# KEYWORD: shutdown
to the PCDM rc script be sufficient to ensure the daemon gets delivered a shutdown signal via the rc system when it starts shutting down? Polling for a process or file that probably only gets created by the actual shutdown command rather than hal/dbus/whatever seems rather inefficient.
 
Re: Shutdown detection methodology

@sossego
PCDM is not the one initiating the shutdown/restart, which is why I need a reliable way to detect if the system is scheduled to shutdown soon. I am already checking for the /var/run/nologin flag: the /sbin/nologin (or /usr/sbin/nologin) binaries are only for displaying that the particular user is not setup for an active login (see the nologin man page).

@junovitch
PCDM does get shutdown just fine, I am simply trying to prevent the internal login daemon for PCDM from starting up a new login session if the system is going into a shutdown (but before PCDM itself is shutdown). It is just a minor annoyance (that GDM also exibits), but basically if a user selects shutdown/restart from within a desktop environment, GDM/PCDM go through and start up a new graphical/X.Org login session - causing the system shutdown to take a longer than necessary because it is spinning up new processes when it really should just keep the current X.Org session in a "paused" state until it gets the shutdown signal itself. I setup PCDM so that it will just show a simple splash screen with "System Shutting Down" display for ~30 seconds (usually long enough for PCDM to get it's own shutdown signal), but it currently only works if the user shuts down with system with the "shutdown" or "reboot" commands - not when the DE is the one that initiated the shutdown.
 
Last edited by a moderator:
Re: Shutdown detection methodology

Along the lines of what @junovitch said, if possible why not add a setenv variable in rc.shutdown and then simply look for this variable prior to (re)starting PCDM?
 
Last edited by a moderator:
Re: Shutdown detection methodology

My thinking is that whatever intermediary starts the shutdown, be that dbus/ shutdown/other, when it gets down the rc processing a shutdown, this would be in effect and ensure that pcdm gets a proper shutdown signal and knows it doesn't have to try to start another login session.

From rc()
Code:
       3.   Invoke rcorder(8) to order the files in /etc/rc.d/ and the
          $local_startup directories that have a ``shutdown'' KEYWORD (refer
          to rcorder(8)'s -k flag), reverse that order, and assign the result
          to a variable.

     4.   Call each script in turn using run_rc_script() (from rc.subr(8)),
          which sets $1 to ``stop'', and sources the script in a subshell.  If
          the script has a .sh suffix then it is sourced directly into the
          current shell.

For what it's worth, both rc scripts for gdm and pcdm are missing the
Code:
KEYWORD: shutdown
line. /usr/local/etc/rc.d/kdm4 has that line. This is on an out of date PC-BSD 10-STABLE-p4 system.
 
Re: Shutdown detection methodology

Thanks for all the input guys, here is a quick status update:

Using @junovitch's suggestion, I modified the PCDM rc.d script to have the shutdown signal detection (similar to /usr/local/etc/rc.d/kdm) but also define a "stop" command and have it forward that on to the PCDM daemon. This appears to be working so far (tested with KDE and Cinnamon on 10.0), so I am going to mark this as solved. I am also putting a link to the PCDM rc.d script[1] at the bottom in case someone else runs into a similar issue.

Thanks again!

[1] https://github.com/pcbsd/pcbsd/blob/master/src-qt4/PCDM/rc.d/pcdm
 
Last edited by a moderator:
Back
Top