From d712d3b76d6c2507f1f9b81349bc9b8b780f7a5c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 12 Oct 2020 09:23:57 +0200 Subject: Add usercount to RPC, simplify timing calculation --- src/rpc.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/rpc.c') diff --git a/src/rpc.c b/src/rpc.c index 28e4b2e..0689587 100644 --- a/src/rpc.c +++ b/src/rpc.c @@ -68,15 +68,17 @@ int rpc_open( void ) return fd; } -void rpc_wait( int listenFd, int seconds ) +bool rpc_wait( int listenFd, int seconds ) { struct pollfd pd[2] = { { .fd = listenFd, .events = POLLIN | POLLHUP | POLLRDHUP }, { .fd = rpcPipe.read, .events = POLLIN | POLLHUP | POLLRDHUP }, }; - if ( poll( pd, 2, seconds * 1000 ) == -1 ) { + int ret = poll( pd, 2, seconds * 1000 ); + if ( ret == -1 ) { perror( "Error polling RPC sockets" ); } + return ret > 0; } void rpc_handle( int listenFd ) @@ -167,11 +169,13 @@ static void handleClient( int fd, struct ucred *creds ) // 1) Global state time_t deadline; const char *name = "none"; - main_getStatus( &name, &deadline ); + int userCount; + main_getStatus( &name, &deadline, &userCount ); fprintf( s, "[General]\n" "nextAction=%s\n" - "nextActionTime=%lld\n", - name, (long long)deadline ); + "nextActionTime=%lld\n" + "userCount=%d\n", + name, (long long)deadline, userCount ); // 2) Requested sessions char *tok = strtok( buffer + 4, " \t\n\r" ); while ( tok != NULL ) { -- cgit v1.2.3-55-g7522