Last bit of code clean up, and bug fixes. Release?
[umurmur.git] / shm_utils / mon-umurmurd / mon-umurmurd.c
index 18a8a97b5e8de923e259e364107bf3405bd725b3..931a34dcf2d54bed9f6300bafbade01e3072d7f8 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdlib.h>\r
 #include <string.h>\r
 #include <unistd.h>\r
+#include <sys/stat.h>\r
 #include <sys/mman.h>\r
 #include <sys/types.h>\r
 #include "../../src/sharedmemory.h"\r
@@ -18,25 +19,35 @@ void run_shm(void);
 \r
 int main(int argc, char **argv) \r
 {\r
-\r
-\r
-    while ( (opt = getopt(argc, argv, "w")) != -1 ) \r
+  struct stat buf;\r
+  int bindport = 0;\r
+  \r
+    while ( (opt = getopt(argc, argv, "wb:")) != -1 ) \r
     {\r
         switch(opt) \r
         {\r
            case 'w':\r
               wait = 1;\r
               break;\r
-           default: \r
-              fprintf(stderr, "Usage: %s [-w]\n", argv[0]);\r
+           case 'b':\r
+              bindport = atoi(optarg);\r
+              break;              \r
+           default:                                                     \r
+              fprintf(stderr, "Usage: %s [-w] [-b <port>]\n", argv[0]);\r
               fprintf(stderr, "\t-w         - Wait for umurmurd to create shm area. useful if you need to start from init.d script\n" );\r
+              fprintf(stderr, "\t-b <port>  - Change this to the port used when starting umurmurd. Defaults to \"/umurmurd:64738\" \n");\r
               exit(EXIT_FAILURE);\r
         }\r
     }\r
 \r
       shmptr = NULL;\r
       \r
-      sprintf( shm_file_name, "/umurmurd:%i", 64738 );\r
+      if( !bindport )\r
+      {\r
+        bindport = 64738;\r
+      }\r
+      \r
+      sprintf( shm_file_name, "/umurmurd:%i", bindport );\r
             \r
       if( wait )\r
           shm_statem = WAIT_ATTACH_SHM;\r
@@ -62,10 +73,10 @@ int main(int argc, char **argv)
                     }\r
                     shm_statem = MAT_SHM;\r
                     break;\r
-             case MAT_SHM:                                       \r
-                    if( ( shmptr = mmap(0, 1, PROT_READ, MAP_SHARED, shm_fd, 0) ) == (void *) (-1) )   //MJP BUG? \r
+             case MAT_SHM:                  \r
+                    fstat( shm_fd, &buf);                                       \r
+                    if( ( shmptr = mmap(0, buf.st_size, PROT_READ, MAP_SHARED, shm_fd, 0) ) == (void *) (-1) )   //MJP BUG? \r
                     {\r
-                        \r
                         exit(EXIT_FAILURE);\r
                     }                    \r
                     printf( "umumurd PID: %u\n\r", shmptr->umurmurd_pid );\r
@@ -94,7 +105,7 @@ void run_shm(void)
 int cc;\r
 \r
     printf( "\033[2J\033[H" ); fflush(stdout); //clear screen VT100\r
-          \r
+    printf( "%s  Clients(CONECTED/MAX)  %i/%i\n\n", shm_file_name, shmptr->clientcount, shmptr->server_max_clients );      \r
           \r
         for( cc = 0 ; cc < shmptr->server_max_clients ; cc++ )\r
         {\r
@@ -150,4 +161,4 @@ int cc;
         {\r
             exit(EXIT_FAILURE); //You dont have to exit you could just report the fact that the data is not valid \r
         }\r
-}\r
+}
\ No newline at end of file