X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=shm_utils%2Fmon-umurmurd%2Fmon-umurmurd.c;h=931a34dcf2d54bed9f6300bafbade01e3072d7f8;hb=60b0fbf1b141566fd5f559c1d7db2317676a3be4;hp=046050f7c60df24cea4823e2adb5bcaa96b9de5a;hpb=9179d97f99164c4f27bb73e32181a7f2e9a7629a;p=umurmur.git diff --git a/shm_utils/mon-umurmurd/mon-umurmurd.c b/shm_utils/mon-umurmurd/mon-umurmurd.c index 046050f..931a34d 100644 --- a/shm_utils/mon-umurmurd/mon-umurmurd.c +++ b/shm_utils/mon-umurmurd/mon-umurmurd.c @@ -1,86 +1,89 @@ -#include +#include /* For O_* constants */ #include -#include -#include -#include #include +#include #include #include -#include +#include +#include +#include #include "../../src/sharedmemory.h" - - -struct shmid_ds buf; - -int wait = 0, opt; +#include "../../src/sharedmemory_global.h" enum{ NOP_SHM, WAIT_ATTACH_SHM, TRY_ATTACH_SHM, MAT_SHM, CLEAN_UP_SHM, RUN_SHM }; -unsigned int shm_statem = TRY_ATTACH_SHM; +int wait = 0, opt; +uint8_t last, shm_statem = TRY_ATTACH_SHM; void run_shm(void); int main(int argc, char **argv) { - -key_t key = 0x53021d79; - - while ((opt = getopt(argc, argv, "w")) != -1) { - switch (opt) { + struct stat buf; + int bindport = 0; + + while ( (opt = getopt(argc, argv, "wb:")) != -1 ) + { + switch(opt) + { case 'w': wait = 1; break; - default: /* '?' */ - fprintf(stderr, "Usage: %s [-w]\n", argv[0]); + case 'b': + bindport = atoi(optarg); + break; + default: + fprintf(stderr, "Usage: %s [-w] [-b ]\n", argv[0]); fprintf(stderr, "\t-w - Wait for umurmurd to create shm area. useful if you need to start from init.d script\n" ); + fprintf(stderr, "\t-b - Change this to the port used when starting umurmurd. Defaults to \"/umurmurd:64738\" \n"); exit(EXIT_FAILURE); } } - - //key = ftok(".", 'S'); // check if ftok works if both umurmur and mon-umurmur are in same dir - // using my own key for now. makes dev easier will fix shmptr = NULL; + if( !bindport ) + { + bindport = 64738; + } + + sprintf( shm_file_name, "/umurmurd:%i", bindport ); + if( wait ) shm_statem = WAIT_ATTACH_SHM; while( shm_statem ) { - switch( shm_statem ) { - case RUN_SHM: run_shm(); break; case WAIT_ATTACH_SHM: - printf( "waiting on umurmurd to be run\n\r"); fflush(stdout); - while( ( shmid = shmget( key, 0, 0) ) == -1 ) + printf( "Waiting for umurmurd to be run\n\r"); fflush(stdout); + while( ( shm_fd = shm_open( shm_file_name, O_RDONLY, 0666 ) ) == -1 ) sleep( 1 ); shm_statem = MAT_SHM; break; case TRY_ATTACH_SHM: - if( ( shmid = shmget( key, 0, 0) ) == -1 ) + if( ( shm_fd = shm_open( shm_file_name, O_RDONLY, 0666 ) ) == -1 ) { - perror("shmget"); printf( "umurmurd doesn't seem to be running\n\r" ); exit(EXIT_FAILURE); } shm_statem = MAT_SHM; break; - case MAT_SHM: - if( ( shmptr = shmat( shmid, 0, 0 ) ) == (void *) (-1) ) ////MJP BUG? + case MAT_SHM: + fstat( shm_fd, &buf); + if( ( shmptr = mmap(0, buf.st_size, PROT_READ, MAP_SHARED, shm_fd, 0) ) == (void *) (-1) ) //MJP BUG? { - perror("shmat"); exit(EXIT_FAILURE); - } - printf( "shmid: %i\n\r", shmid ); + } printf( "umumurd PID: %u\n\r", shmptr->umurmurd_pid ); shm_statem = RUN_SHM; break; case CLEAN_UP_SHM: - shmdt( shmptr ); + break; } @@ -89,50 +92,73 @@ key_t key = 0x53021d79; return 0; } +uint8_t check_serverTick(void) +{ + last = shmptr->alive; + sleep( 1 ); // Sleep for 1 sec + return(shmptr->alive - last); +} void run_shm(void) { int cc; - - - shmctl( shmid, IPC_STAT, &buf ); //MJP BUG check for errors here - - printf("\033[2J\033[H"); //clear screen VT100 + printf( "\033[2J\033[H" ); fflush(stdout); //clear screen VT100 + printf( "%s Clients(CONECTED/MAX) %i/%i\n\n", shm_file_name, shmptr->clientcount, shmptr->server_max_clients ); - printf( "attach: %lu SCC: %i SMC: %i\n", (unsigned long int)buf.shm_nattch, shmptr->clientcount, shmptr->server_max_clients ); - for( cc = 0 ; cc < shmptr->server_max_clients ; cc++ ) - { + for( cc = 0 ; cc < shmptr->server_max_clients ; cc++ ) + { if( !shmptr->client[cc].authenticated ) continue; printf( "%s@%s:%i in channel: %s\n\ - \tlastActivity/connectTime/idleTime: %llu/%llu/%llu idleTime: %llu \n\ - \tUDP_Avg/Var: %3.2f/%3.2f \n\ - \tTCP_Avg/Var: %3.2f/%3.2f \n\ - \tUDP_C/TCP_C: %lu/%lu\n", - + \tclient_OS: %s %s\n\ + \tclient_info: %s\n\ + \tavailableBandwidth: %i\n\ + \tOnline(secs): %lu Idle(secs): %lu\n\ + \tusingUDP=%i\n\ + \tdeaf=%i, mute=%i\n\ + \tself_deaf=%i, self_mute=%i\n\ + \trecording=%i\n\ + \tbOpus=%i\n\ + \tisAdmin=%i\n\ + \tisSuppressed=%i\n\ + \tUDP_Avg/Var: %3.2f/%3.2f\n\ + \tTCP_Avg/Var: %3.2f/%3.2f\n\ + \tUDP_C/TCP_C: %lu/%lu\n", + shmptr->client[cc].username, + shmptr->client[cc].ipaddress, + shmptr->client[cc].udp_port, + shmptr->client[cc].channel, + shmptr->client[cc].os, + shmptr->client[cc].os_version, + shmptr->client[cc].release, + shmptr->client[cc].availableBandwidth, + shmptr->client[cc].online_secs, + shmptr->client[cc].idle_secs, + + shmptr->client[cc].bUDP, + shmptr->client[cc].deaf, + shmptr->client[cc].mute, + shmptr->client[cc].self_deaf, + shmptr->client[cc].self_mute, + shmptr->client[cc].recording, + shmptr->client[cc].bOpus, + + shmptr->client[cc].isAdmin, + shmptr->client[cc].isSuppressed, - - shmptr->client[cc].username, - shmptr->client[cc].ipaddress, - shmptr->client[cc].udp_port, - shmptr->client[cc].channel, - shmptr->client[cc].lastActivity, - shmptr->client[cc].connectTime, - shmptr->client[cc].idleTime, - (long long unsigned int)shmptr->client[cc].lastActivity - shmptr->client[cc].idleTime, - shmptr->client[cc].UDPPingAvg, - shmptr->client[cc].UDPPingVar, - shmptr->client[cc].TCPPingAvg, - shmptr->client[cc].TCPPingVar, - shmptr->client[cc].UDPPackets, - shmptr->client[cc].TCPPackets - ); fflush(stdout); // fflush need because of sleep() call - } - sleep( 1 ); // Sleep for 1 sec - - + shmptr->client[cc].UDPPingAvg, + shmptr->client[cc].UDPPingVar, + shmptr->client[cc].TCPPingAvg, + shmptr->client[cc].TCPPingVar, + shmptr->client[cc].UDPPackets, + shmptr->client[cc].TCPPackets ); fflush(stdout); // fflush need because of sleep() call + } + if( !check_serverTick() ) + { + exit(EXIT_FAILURE); //You dont have to exit you could just report the fact that the data is not valid + } } \ No newline at end of file