add uptime

This commit is contained in:
ehouse 2005-10-19 03:39:18 +00:00
parent 5e693ee022
commit 4df7b3d75a

View file

@ -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_set( 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
print_to_sock( int sock, int addCR, const char* what, ... )
@ -93,6 +94,7 @@ static const FuncRec gFuncs[] = {
{ "shutdown", cmd_shutdown },
{ "get", cmd_get },
{ "set", cmd_set },
{ "uptime", cmd_uptime },
};
static int
@ -195,6 +197,32 @@ cmd_set( int socket, const char** args )
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
cmd_shutdown( int socket, const char** args )
{
@ -363,7 +391,6 @@ ctrl_thread_main( void* arg )
char buf[512];
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 */
break;
} else if ( nGot > 2 ) {