summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 9ca1da9..68ae274 100644
--- a/src/main.c
+++ b/src/main.c
@@ -52,6 +52,7 @@ static struct {
int dpmsTimeout;
int gracePeriod;
int minIdle;
+ bool killUserProcesses;
} config;
static time_t combineTime( const time_t now, const struct time * time );
@@ -62,6 +63,8 @@ static bool parseCmdline( int argc, char **argv );
static void execShutdown( enum Shutdown action );
+static void userLoggedOut(struct user* usr);
+
int main( int argc, char **argv )
{
int idx;
@@ -80,7 +83,7 @@ int main( int argc, char **argv )
startWall = time( NULL );
startMono = now();
// Calculate shortest possible sleep time without delaying any timeout related actions
- int defaultSleep = 900;
+ int defaultSleep = 120;
if ( config.logoutTimeout > 0 && config.logoutTimeout < defaultSleep ) {
defaultSleep = config.logoutTimeout;
}
@@ -100,8 +103,13 @@ int main( int argc, char **argv )
userCount = count;
for ( idx = 0; idx < count; ++idx ) {
struct user * const usr = &users[idx];
- if ( !usr->mark ) {
- fprintf( stderr, "This will never happen \\o/\n" );
+ if ( !usr->online ) {
+ if ( !usr->lastOnline ) {
+ fprintf( stderr, "This will never happen \\o/\n" );
+ continue;
+ }
+ // User was logged in, but isn't anymore
+ userLoggedOut(usr);
continue;
}
const time_t NOW = time( NULL );
@@ -384,6 +392,7 @@ static struct option long_options[] = {
{ "min-idle", required_argument, NULL, 'min' },
{ "cmd", required_argument, NULL, 'cmd' },
{ "send", required_argument, NULL, 'send' },
+ { "kill-user-processes", no_argument, NULL, 'kill' },
{ "test", no_argument, NULL, 't' },
{ NULL, 0, NULL, 0 }
};
@@ -422,6 +431,7 @@ static bool parseCmdline( int argc, char **argv )
config.gracePeriod = -1;
config.shutdownCommand = NULL;
config.minIdle = 0;
+ config.killUserProcesses = false;
while ( ( ch = getopt_long( argc, argv, "", long_options, NULL ) ) != -1 ) {
switch ( ch ) {
case 'pot':
@@ -466,6 +476,10 @@ static bool parseCmdline( int argc, char **argv )
break;
case 'send':
exit( !rpc_send( optarg ) );
+ break;
+ case 'kill':
+ config.killUserProcesses = true;
+ break;
default:
fprintf( stderr, "Unhandled command line option %d, aborting\n", ch );
return false;
@@ -518,7 +532,7 @@ void main_getStatus( const char **nextString, time_t *deadline )
struct user* main_getUser( const char *terminal )
{
- for ( int i = 0; i < USERS && users[i].mark; ++i ) {
+ for ( int i = 0; i < userCount; ++i ) {
if ( strcmp( users[i].device, terminal ) == 0
|| strcmp( users[i].display, terminal ) == 0 ) {
return &users[i];
@@ -565,4 +579,18 @@ void main_warnAll( const char *message )
}
}
+static void userLoggedOut(struct user* usr)
+{
+ if ( !config.killUserProcesses )
+ return;
+ for ( int i = 0; i < userCount; ++i ) {
+ if (users[i].online && strcmp(users[i].user, usr->user) == 0)
+ return; // Still an active session
+ }
+ struct passwd *u = getpwnam( usr->user );
+ if ( u == NULL || u->pw_uid < 1000 )
+ return; // Ignore system users
+ printf( "Killing remaining processes of %s\n", usr->user );
+ run( true, "pkill", "-u", usr->user, (char*)NULL );
+}