X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=shm_utils%2Fmon-umurmurd%2Fmon-umurmurd.c;h=444456c547bf4928a4f6802138a62366709e6cf8;hb=ac5399b3432cabca65ed362138ffcf4f8e917ebd;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..444456c 100644 --- a/shm_utils/mon-umurmurd/mon-umurmurd.c +++ b/shm_utils/mon-umurmurd/mon-umurmurd.c @@ -11,46 +11,48 @@ struct shmid_ds buf; - -int wait = 0, opt; - enum{ NOP_SHM, WAIT_ATTACH_SHM, TRY_ATTACH_SHM, MAT_SHM, CLEAN_UP_SHM, RUN_SHM }; -unsigned int 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) { + 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) + { case 'w': wait = 1; break; 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); } } - //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( wait ) shm_statem = WAIT_ATTACH_SHM; while( shm_statem ) { - switch( shm_statem ) { - case RUN_SHM: run_shm(); break; @@ -70,69 +72,73 @@ key_t key = 0x53021d79; shm_statem = MAT_SHM; break; case MAT_SHM: - if( ( shmptr = shmat( shmid, 0, 0 ) ) == (void *) (-1) ) ////MJP BUG? + if( ( shmptr = shmat( shmid, 0, 0 ) ) == (void *) (-1) ) { perror("shmat"); exit(EXIT_FAILURE); } printf( "shmid: %i\n\r", shmid ); - printf( "umumurd PID: %u\n\r", shmptr->umurmurd_pid ); + printf( "Connected to umumurd PID: %u\n\r", shmptr->umurmurd_pid ); + sleep( 1 ); shm_statem = RUN_SHM; break; case CLEAN_UP_SHM: shmdt( shmptr ); - break; - + break; } } - fflush(stdout); - return 0; + fflush(stdout); + return 0; } void run_shm(void) { + int cc; + + shmctl( shmid, IPC_STAT, &buf ); //MJP BUG check for errors here -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"); //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 ) + 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 ) 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", - + 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].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 + } + sleep( 1 ); // Sleep for 1 sec } \ No newline at end of file