From 38a7538c59535cc7b6d3812cce79bc9d10f3b4cc Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 30 Sep 2022 15:07:00 +0200 Subject: Add --logout-is-shutdown flag --- src/main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 138713f..8521f67 100644 --- a/src/main.c +++ b/src/main.c @@ -54,6 +54,7 @@ static struct { int gracePeriod; int minIdle; bool killUserProcesses; + bool logoutIsShutdown; } config; static time_t combineTime( const time_t now, const struct time * time ); @@ -83,7 +84,8 @@ int main( int argc, char **argv ) nextAction.deadline = 0; startWall = time( NULL ); startMono = now(); - // Calculate shortest possible sleep time without delaying any timeout related actions + // Calculate longest possible sleep time without delaying any timeout related actions + // But cap at 60 seconds int defaultSleep = 60; if ( config.logoutTimeout > 0 && config.logoutTimeout < defaultSleep ) { defaultSleep = config.logoutTimeout; @@ -198,7 +200,12 @@ int main( int argc, char **argv ) // Idle logout is enabled const int remaining = config.logoutTimeout - idleTime; if ( remaining <= 2 ) { - killSession( usr ); + // Kill session, or if enabled, shut down machine entirely, if this was the main session + if ( config.logoutIsShutdown && usr->display[0] == ':' && usr->display[1] == '0' ) { + execShutdown( POWEROFF ); + } else { + killSession( usr ); + } } else if ( remaining <= 65 ) { warn_showDefaultWarning( usr, WARN_LOGOUT, remaining ); CAP_SLEEP( remaining ); @@ -414,6 +421,7 @@ static struct option long_options[] = { { "cmd", required_argument, NULL, 'cmd' }, { "send", required_argument, NULL, 'send' }, { "kill-user-processes", no_argument, NULL, 'kill' }, + { "logout-is-shutdown", no_argument, NULL, 'lis' }, { "test", no_argument, NULL, 't' }, { NULL, 0, NULL, 0 } }; @@ -453,6 +461,7 @@ static bool parseCmdline( int argc, char **argv ) config.shutdownCommand = NULL; config.minIdle = 0; config.killUserProcesses = false; + config.logoutIsShutdown = false; while ( ( ch = getopt_long( argc, argv, "", long_options, NULL ) ) != -1 ) { switch ( ch ) { case 'pot': @@ -501,6 +510,9 @@ static bool parseCmdline( int argc, char **argv ) case 'kill': config.killUserProcesses = true; break; + case 'lis': + config.logoutIsShutdown = true; + break; default: fprintf( stderr, "Unhandled command line option %d, aborting\n", ch ); return false; -- cgit v1.2.3-55-g7522