diff options
author | Simon Rettberg | 2022-09-30 15:07:00 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-09-30 15:07:00 +0200 |
commit | 38a7538c59535cc7b6d3812cce79bc9d10f3b4cc (patch) | |
tree | 4705654255107cab055943444173dfcedd2719c7 | |
parent | Cap sleep time to 5 after RPC activity (diff) | |
download | idle-daemon-38a7538c59535cc7b6d3812cce79bc9d10f3b4cc.tar.gz idle-daemon-38a7538c59535cc7b6d3812cce79bc9d10f3b4cc.tar.xz idle-daemon-38a7538c59535cc7b6d3812cce79bc9d10f3b4cc.zip |
Add --logout-is-shutdown flag
-rw-r--r-- | src/main.c | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -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; |