mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-11 08:48:06 +01:00
add uptime
This commit is contained in:
parent
76d35deea5
commit
e72740d184
1 changed files with 28 additions and 1 deletions
|
@ -63,6 +63,7 @@ static int cmd_kill_eject( int socket, const char** args );
|
||||||
static int cmd_get( int socket, const char** args );
|
static int cmd_get( int socket, const char** args );
|
||||||
static int cmd_set( int socket, const char** args );
|
static int cmd_set( int socket, const char** args );
|
||||||
static int cmd_shutdown( int socket, const char** args );
|
static int cmd_shutdown( int socket, const char** args );
|
||||||
|
static int cmd_uptime( int socket, const char** args );
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_to_sock( int sock, int addCR, const char* what, ... )
|
print_to_sock( int sock, int addCR, const char* what, ... )
|
||||||
|
@ -93,6 +94,7 @@ static const FuncRec gFuncs[] = {
|
||||||
{ "shutdown", cmd_shutdown },
|
{ "shutdown", cmd_shutdown },
|
||||||
{ "get", cmd_get },
|
{ "get", cmd_get },
|
||||||
{ "set", cmd_set },
|
{ "set", cmd_set },
|
||||||
|
{ "uptime", cmd_uptime },
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -195,6 +197,32 @@ cmd_set( int socket, const char** args )
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
cmd_uptime( int socket, const char** args )
|
||||||
|
{
|
||||||
|
if ( 0 == strcmp( args[1], "help" ) ) {
|
||||||
|
print_to_sock( socket, 1,
|
||||||
|
"* %s -- prints how long the relay's been running",
|
||||||
|
args[0] );
|
||||||
|
} else {
|
||||||
|
time_t seconds = now();
|
||||||
|
|
||||||
|
int days = seconds / (24*60*60);
|
||||||
|
seconds %= (24*60*60);
|
||||||
|
|
||||||
|
int hours = seconds / (60*60);
|
||||||
|
seconds %= (60*60);
|
||||||
|
|
||||||
|
int minutes = seconds / 60;
|
||||||
|
seconds %= 60;
|
||||||
|
|
||||||
|
print_to_sock( socket, 1,
|
||||||
|
"uptime: %d days, %d hours, %d minutes, %ld seconds",
|
||||||
|
days, hours, minutes, seconds );
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cmd_shutdown( int socket, const char** args )
|
cmd_shutdown( int socket, const char** args )
|
||||||
{
|
{
|
||||||
|
@ -363,7 +391,6 @@ ctrl_thread_main( void* arg )
|
||||||
|
|
||||||
char buf[512];
|
char buf[512];
|
||||||
ssize_t nGot = recv( socket, buf, sizeof(buf)-1, 0 );
|
ssize_t nGot = recv( socket, buf, sizeof(buf)-1, 0 );
|
||||||
logf( XW_LOGINFO, "nGot=%d", nGot );
|
|
||||||
if ( nGot <= 1 ) { /* break when just \n comes in */
|
if ( nGot <= 1 ) { /* break when just \n comes in */
|
||||||
break;
|
break;
|
||||||
} else if ( nGot > 2 ) {
|
} else if ( nGot > 2 ) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue