X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=shm_utils%2Fmon-umurmurd%2Fmon-umurmurd.c;h=7a1a5b2eb0396dd7feddf3d8dcccbb98d151c221;hb=a738ff892738e239ad74f5aa686108298efa7cea;hp=444456c547bf4928a4f6802138a62366709e6cf8;hpb=2311400db89f8dd24cfc57d6f72328f539a9ce8d;p=umurmur.git diff --git a/shm_utils/mon-umurmurd/mon-umurmurd.c b/shm_utils/mon-umurmurd/mon-umurmurd.c index 444456c..7a1a5b2 100644 --- a/shm_utils/mon-umurmurd/mon-umurmurd.c +++ b/shm_utils/mon-umurmurd/mon-umurmurd.c @@ -1,51 +1,43 @@ -#include +#include /* For O_* constants */ #include -#include -#include -#include #include +#include #include #include -#include +#include +#include #include "../../src/sharedmemory.h" +#include "../../src/sharedmemory_global.h" - -struct shmid_ds buf; enum{ NOP_SHM, WAIT_ATTACH_SHM, TRY_ATTACH_SHM, MAT_SHM, CLEAN_UP_SHM, RUN_SHM }; - +int wait = 0, opt; +uint8_t last, shm_statem = TRY_ATTACH_SHM; void run_shm(void); - int main(int argc, char **argv) { - int wait = 0, opt; - unsigned int shm_statem = TRY_ATTACH_SHM; - - key_t key = 0x53021d79; - //key = ftok(".", 'S'); // using my own key for now. makes dev easier will fix - while ((opt = getopt(argc, argv, "w")) != -1) - { - switch (opt) - { + + while ( (opt = getopt(argc, argv, "w")) != -1 ) + { + switch(opt) + { case 'w': wait = 1; break; - default: /* '?' */ + default: fprintf(stderr, "Usage: %s [-w]\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" ); - //My version of this talks to custom PIC18 hardware acting as a i2c slave to a RaspberryPI to - //sound buzzer and turn on a LED when my umurmurd server has users in it. I leave this in here - //in case you need it. exit(EXIT_FAILURE); } } - + shmptr = NULL; - + sprintf( shm_file_name, "/umurmurd:%i", 64738 ); + if( wait ) shm_statem = WAIT_ATTACH_SHM; @@ -57,88 +49,93 @@ int main(int argc, char **argv) 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) ) + if( ( shmptr = mmap(0, 1, PROT_READ, MAP_SHARED, shm_fd, 0) ) == (void *) (-1) ) //MJP BUG? { - perror("shmat"); + exit(EXIT_FAILURE); - } - printf( "shmid: %i\n\r", shmid ); - printf( "Connected to umumurd PID: %u\n\r", shmptr->umurmurd_pid ); - sleep( 1 ); + } + printf( "umumurd PID: %u\n\r", shmptr->umurmurd_pid ); shm_statem = RUN_SHM; break; case CLEAN_UP_SHM: - shmdt( shmptr ); - break; + + break; + } } - fflush(stdout); - return 0; + fflush(stdout); + 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 +int cc; + + printf( "\033[2J\033[H" ); //clear screen VT100 - 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++ ) - { - if( !shmptr->client[cc].authenticated ) + + for( cc = 0 ; cc < shmptr->server_max_clients ; cc++ ) + { + + if( !shmptr->client[cc].authenticated ) continue; - printf( "%s@%s:%i in channel: %s\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\ - \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].online_secs, - shmptr->client[cc].idle_secs, + printf( "%s@%s:%i in channel: %s\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\ + \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].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].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].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