summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/main.c b/src/main.c
index 35d983e..a29fd35 100644
--- a/src/main.c
+++ b/src/main.c
@@ -84,7 +84,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 = 120;
+ int defaultSleep = 60;
if ( config.logoutTimeout > 0 && config.logoutTimeout < defaultSleep ) {
defaultSleep = config.logoutTimeout;
}
@@ -293,7 +293,7 @@ int main( int argc, char **argv )
nextAction.disarmed = true;
nextAction.force = false;
} else if ( remaining < 310 ) {
- if ( remaining % 30 < 10 ) {
+ if ( remaining % 30 < 8 ) {
enum Warning w = WARN_REBOOT;
if ( nextAction.action == POWEROFF ) {
w = WARN_POWEROFF;
@@ -302,30 +302,30 @@ int main( int argc, char **argv )
warn_showDefaultWarning( &users[idx], w, remaining );
}
}
- CAP_SLEEP( remaining - ( ( remaining - 30 ) / 60 * 60 + 2 ) );
+ CAP_SLEEP( ( remaining % 15 ) - 2 );
} else {
CAP_SLEEP( remaining - 305 );
}
}
}
do {
- const time_t oldDeadline = nextAction.deadline;
// Handle requests
- rpc_handle( listenFd );
- // Might have set a new scheduled action
- if ( nextAction.deadline != oldDeadline ) {
- int delta = nextAction.deadline - monoNOW;
- CAP_SLEEP( delta - 305 );
- }
+ const time_t oldDeadline = nextAction.deadline;
// Sleep until next run
- //printf( "Sleeping %d seconds\n ", sleepTime );
- rpc_wait( listenFd, sleepTime > 5 ? sleepTime : 5 );
+ int sn = sleepTime - ( endMono - startMono );
+ //printf( "Sleeping %d seconds\n ", sn );
+ if ( rpc_wait( listenFd, sn < 1 ? 1 : sn ) ) {
+ rpc_handle( listenFd );
+ // Might have set a new scheduled action, run main loop again
+ if ( nextAction.deadline != oldDeadline ) {
+ CAP_SLEEP( 1 );
+ }
+ }
// Detect time changes
endWall = time( NULL );
endMono = now();
// Sloppy way of preventing we loop too fast -- handle rpc callbacks but don't run main logic
- sleepTime -= ( endMono - startMono );
- } while ( endMono - startMono < 2 );
+ } while ( sleepTime > ( endMono - startMono ) );
// Adjust for clock changes
const int diff = ( endWall - startWall ) - ( endMono - startMono );
if ( diff != 0 ) {
@@ -537,7 +537,7 @@ static void execShutdown( enum Shutdown action )
}
}
-void main_getStatus( const char **nextString, time_t *deadline )
+void main_getStatus( const char **nextString, time_t *deadline, int *numUsers )
{
if ( nextAction.deadline == 0 || nextAction.disarmed ) {
*deadline = 0;
@@ -545,6 +545,7 @@ void main_getStatus( const char **nextString, time_t *deadline )
}
*deadline = ( nextAction.deadline - now() ) + time( NULL );
*nextString = shutdownActions[nextAction.action];
+ *numUsers = userCount;
}
struct user* main_getUser( const char *terminal )