tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Determining if a system is in shutdown



Hello,

for a patch for "nodm" (a lightweight X session manager), I try
to find out how to determine if a system is currently in shutdown.

The intention is to prevent "nodm" from restarting an X session
that caught a SIGTERM while the system is in shutdown.

I found this to work on GNU using SVr4 "utmp.h":

 #include<stdlib.h>
 #include<utmp.h>

 int in_shutdown(void) {
     struct utmp * ut;

     setutent();

     while ((ut = getutent()) != NULL)
         if (ut->ut_type == RUN_LVL)
           /* Current runlevel is pid_t modulo 256.
              Runlevel 0 means system is in shutdown. */
           return ut->ut_pid % 256 == 0;

     return -1;
 }

(This does not work with POSIX "utmpx.h", because there is
no RUN_LVL there, for obvious reasons).

The question:

My question is if there is an analogous way in BSD to determine
if a system shutdown is currently scheduled.

Kind regards,
Tilman.


Home | Main Index | Thread Index | Old Index