#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
\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
}\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
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
{\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
#include "sharedmemory.h"\r
#include "sharedmemory_global.h"\r
\r
-void Sharedmemory_init(void) \r
+void Sharedmemory_init( int bindport, int bindport6 ) \r
{\r
+ \r
+ int server_max_clients = getIntConf(MAX_CLIENTS); \r
+ int shmtotal_size = sizeof( shm_t ) + (sizeof( shmclient_t ) * server_max_clients);\r
\r
- int bindport = getIntConf(BINDPORT); //MJP BUG commandline option for address and port dont work this way going to have \r
- int server_max_clients = getIntConf(MAX_CLIENTS); //to bring them across as prameters to Sharedmemory_init(void)\r
- int shmptr_size = sizeof( shm_t ) + (sizeof( shmclient_t ) * server_max_clients);\r
+ if( !bindport )\r
+ {\r
+ bindport = getIntConf(BINDPORT); \r
+ }\r
\r
- sprintf( shm_file_name, "umurmurd:%i", bindport );\r
+ sprintf( shm_file_name, "/umurmurd:%i", bindport );\r
Log_info("SHM_API: shm_fd=\"%s\"", shm_file_name );\r
\r
- shm_fd = shm_open( shm_file_name, O_CREAT | O_RDWR, 0660 );\r
- if(shm_fd == -1)\r
- {\r
- Log_fatal( "SHM_API: Open failed:%s\n", strerror(errno));\r
- exit(1);\r
- } \r
+ shm_fd = shm_open( shm_file_name, O_CREAT | O_RDWR, 0660 );\r
+ if(shm_fd == -1)\r
+ {\r
+ Log_fatal( "SHM_API: Open failed:%s\n", strerror(errno));\r
+ exit(1);\r
+ } \r
\r
- if( ftruncate( shm_fd, shmptr_size ) == -1 )\r
- {\r
- Log_fatal( "SHM_API: ftruncate : %s\n", strerror(errno)); \r
- exit(1);\r
- }\r
+ if( ftruncate( shm_fd, shmtotal_size ) == -1 )\r
+ {\r
+ Log_fatal( "SHM_API: ftruncate : %s\n", strerror(errno)); \r
+ exit(1);\r
+ }\r
+\r
+ shmptr = mmap(0, shmtotal_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);\r
+ if (shmptr == (void *) -1) \r
+ {\r
+ Log_fatal( "SHM_API: mmap failed : %s\n", strerror(errno));\r
+ exit(1);\r
+ } \r
\r
- shmptr = mmap(0, shmptr_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);\r
- if (shmptr == (void *) -1) \r
- {\r
- Log_fatal( "SHM_API: mmap failed : %s\n", strerror(errno));\r
- exit(1);\r
- } \r
+ memset( shmptr, 0, shmtotal_size );\r
\r
- memset( shmptr, 0, shmptr_size );\r
- \r
shmptr->umurmurd_pid = getpid();\r
- shmptr->server_max_clients = server_max_clients; \r
+ shmptr->server_max_clients = server_max_clients; \r
+ shmptr->shmtotal_size = shmtotal_size;\r
+ shmptr->shmclient_size = sizeof( shmclient_t ) * shmptr->server_max_clients; \r
+ \r
}\r
\r
void Sharedmemory_update(void) \r
unsigned int cc = 0;\r
client_t *client_itr = NULL;\r
\r
- memset( &shmptr->client[0], 0, sizeof( shmclient_t ) * shmptr->server_max_clients );\r
+ memset( &shmptr->client[0], 0, shmptr->shmclient_size );\r
shmptr->clientcount = Client_count();\r
\r
if( shmptr->clientcount )\r
close( shm_fd );\r
shm_unlink( shm_file_name );\r
shmptr->umurmurd_pid = 0;\r
-}\r
+}
\ No newline at end of file
char os[121], release[121], os_version[121];\r
int tcp_port, udp_port;\r
bool_t bUDP, authenticated, deaf, mute, self_deaf, self_mute, recording, bOpus;\r
- int availableBandwidth;\r
+ int availableBandwidth;\r
uint32_t online_secs, idle_secs;\r
bool_t isAdmin;\r
bool_t isSuppressed;\r
typedef struct\r
{\r
\r
+ int shmtotal_size, shmclient_size;\r
int clientcount, server_max_clients;\r
unsigned int umurmurd_pid;\r
- uint8_t alive; \r
- shmclient_t client[]; \r
- \r
+ uint8_t alive;\r
+ shmclient_t client[];\r
+\r
}shm_t;\r