From: hadaq Date: Fri, 26 Jan 2007 15:56:04 +0000 (+0000) Subject: give unique name to shared memory X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=f4d13739ebe3181f2bf9488229c428cb2a0e50aa;p=daqdata.git give unique name to shared memory --- diff --git a/hadaq/memnet.c b/hadaq/memnet.c index c15d2e7..b800710 100644 --- a/hadaq/memnet.c +++ b/hadaq/memnet.c @@ -1,8 +1,9 @@ -static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/memnet.c,v 6.18 2004-08-13 10:30:00 hadaq Exp $"; +static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/memnet.c,v 6.19 2007-01-26 15:56:04 hadaq Exp $"; #define _POSIX_C_SOURCE 199309L #define SYSLOG_NAMES #include +#include #include @@ -29,6 +30,7 @@ typedef struct TheArgsS { unsigned long priority; unsigned long queueSize; char verbosity[PARAM_MAX_VALUE_LEN]; + char shmnum[PARAM_MAX_VALUE_LEN]; } TheArgs; static jmp_buf terminateJmp; @@ -47,6 +49,7 @@ static void usage(const char *progName) { syslog(LOG_ERR, "Usage: %s [-a (agentCtrl)] -o outPath", progName); syslog(LOG_ERR, "Usage: [-w bandwidth] [-p priority] [-q queueSize]"); + syslog(LOG_ERR, "Usage: [--shmnum unique number for shared memory]" ); } static void argsDump(TheArgs *my) @@ -57,6 +60,9 @@ static void argsDump(TheArgs *my) syslog(LOG_DEBUG, "isStandalone: %d", my->isStandalone); syslog(LOG_DEBUG, "queueSize: %d", my->queueSize); syslog(LOG_DEBUG, "verbosity: %s", my->verbosity); + if(my->shmnum != 0){ + syslog (LOG_DEBUG, "shmnum: %d", my->shmnum); + } } static void argsDefault(TheArgs *my) @@ -67,38 +73,56 @@ static void argsDefault(TheArgs *my) my->isStandalone = 1; my->queueSize = 1 * 1024 * 1024; strcpy(my->verbosity, "info"); + strcpy(my->shmnum, ""); } static int argsFromCL(TheArgs *my, int argc, char *argv[]) { extern char *optarg; int i; - - while ((i = getopt(argc, argv, "aw:q:o:p:v:")) != -1) { - switch (i) { - case 'w': - my->bandWidth = atoi(optarg); - break; - case 'o': - strcpy(my->outPath, optarg); - break; - case 'a': - my->isStandalone = 0; - break; - case 'p': - my->priority = atoi(optarg); - break; - case 'q': - my->queueSize = atoi(optarg); - break; - case 'v': - strcpy(my->verbosity, optarg); - break; - default: - return -1; - break; - } - } + int option_index = 0; + + while (1) + { + static struct option long_options[] = + { + {"shmnum", 1, 0, 'z'}, + {0, 0, 0, 0} + }; + + i = getopt_long (argc, argv, "aw:q:o:p:v:z:", + long_options, &option_index); + + if (i == -1) + break; + + switch (i) { + case 'w': + my->bandWidth = atoi(optarg); + break; + case 'o': + strcpy(my->outPath, optarg); + break; + case 'a': + my->isStandalone = 0; + break; + case 'p': + my->priority = atoi(optarg); + break; + case 'q': + my->queueSize = atoi(optarg); + break; + case 'v': + strcpy(my->verbosity, optarg); + break; + case 'z': + strcpy(my->shmnum, optarg); + break; + default: + return -1; + break; + } + } return 0; } @@ -165,11 +189,12 @@ int main(int argc, char *argv[]) ShmTrans *shmTrans; int exitStat; + char shmname[PARAM_MAX_VALUE_LEN] = "subevtqueue"; + openlog(argv[0], LOG_PID | LOG_PERROR, LOG_LOCAL0); setlogmask(LOG_UPTO(LOG_INFO)); - argsDefault(theArgs); argsFromParam(theArgs, argc, argv); if (0 > argsFromCL(theArgs, argc, argv)) { @@ -186,6 +211,9 @@ int main(int argc, char *argv[]) argsDump(theArgs); + /* give unique name to shared memory*/ + strcat(shmname, theArgs->shmnum); + if (strcmp(theArgs->outPath, "") == 0) { usage(argv[0]); exit(EXIT_FAILURE); @@ -195,8 +223,8 @@ int main(int argc, char *argv[]) exitStat = EXIT_FAILURE; goto bailOut0; } - if (NULL == (shmTrans = ShmTrans_create("subevtqueue", 2 * theArgs->queueSize))) { - syslog(LOG_ERR, "creating shared memory \"subevtqueue\": %s"), strerror(errno); + if (NULL == (shmTrans = ShmTrans_create(shmname, 2 * theArgs->queueSize))) { + syslog(LOG_ERR, "creating shared memory \"%s\": %s"), shmname, strerror(errno); exitStat = EXIT_FAILURE; goto bailOut1; } diff --git a/hadaq/readout.c b/hadaq/readout.c index 3ce792a..4661fe8 100644 --- a/hadaq/readout.c +++ b/hadaq/readout.c @@ -1,10 +1,11 @@ -static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/readout.c,v 6.30 2006-04-11 17:39:31 hadaq Exp $"; +static char *rcsId = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/readout.c,v 6.31 2007-01-26 15:57:00 hadaq Exp $"; #define _POSIX_C_SOURCE 199309L #define SYSLOG_NAMES #include #include "grmblfx.h" +#include #include #include @@ -28,7 +29,8 @@ typedef struct TheArgsS { unsigned long priority; unsigned long queueSize; char verbosity[PARAM_MAX_VALUE_LEN]; - char subsystem[PARAM_MAX_VALUE_LEN]; + char subsystem[PARAM_MAX_VALUE_LEN]; + char shmnum[PARAM_MAX_VALUE_LEN]; } TheArgs; static jmp_buf terminateJmp; @@ -42,6 +44,7 @@ static void usage(const char *progName) { syslog(LOG_ERR, "Usage: %s [-a (agentCtrl)] [-p priority]", progName); syslog(LOG_ERR, "Usage: [-q queueSize] [-w waterMark]"); + syslog(LOG_ERR, "Usage: [--shmnum unique number for shared memory]" ); } static void argsDump(TheArgs *my) @@ -52,6 +55,9 @@ static void argsDump(TheArgs *my) syslog(LOG_DEBUG, "queueSize: %d", my->queueSize); syslog(LOG_DEBUG, "verbosity: %s", my->verbosity); syslog(LOG_DEBUG, "subsystem: %s", my->subsystem); + if(my->shmnum != 0){ + syslog (LOG_DEBUG, "shmnum: %d", my->shmnum); + } } static void argsDefault(TheArgs *my) @@ -62,38 +68,57 @@ static void argsDefault(TheArgs *my) my->queueSize = 1 * 1024 * 1024; strcpy(my->verbosity, "info"); strcpy(my->subsystem, "unknown"); + strcpy(my->shmnum, ""); } static int argsFromCL(TheArgs *my, int argc, char *argv[]) { - extern char *optarg; + extern char *optarg; int i; - - while ((i = getopt(argc, argv, "w:ap:q:s:v:")) != -1) { - switch (i) { - case 'w': - my->waterMark = atoi(optarg); - break; - case 'a': - my->isStandalone = 0; - break; - case 'p': - my->priority = atoi(optarg); - break; - case 'q': - my->queueSize = atoi(optarg); - break; - case 's': - strcpy(my->subsystem, optarg); - break; - case 'v': - strcpy(my->verbosity, optarg); - break; - default: - return -1; - break; - } - } + int option_index = 0; + + while (1) + { + static struct option long_options[] = + { + {"shmnum", 1, 0, 'z'}, + {0, 0, 0, 0} + }; + + i = getopt_long (argc, argv, "w:ap:q:s:v:z:", + long_options, &option_index); + + if (i == -1) + break; + + switch (i) { + case 'w': + my->waterMark = atoi(optarg); + break; + case 'a': + my->isStandalone = 0; + break; + case 'p': + my->priority = atoi(optarg); + break; + case 'q': + my->queueSize = atoi(optarg); + break; + case 's': + strcpy(my->subsystem, optarg); + break; + case 'v': + strcpy(my->verbosity, optarg); + break; + case 'z': + strcpy(my->shmnum, optarg); + break; + + default: + return -1; + break; + } + } return 0; } @@ -163,11 +188,11 @@ int readoutMain(int argc, char *argv[]) unsigned long *subevtsRead; unsigned long *subevtsDataErr; + char shmname[PARAM_MAX_VALUE_LEN] = "subevtqueue"; + openlog(argv[0], LOG_PID | LOG_PERROR, LOG_LOCAL0); setlogmask(LOG_UPTO(LOG_INFO)); - LVme_registerLogMsg(syslog); - argsDefault(theArgs); argsFromParam(theArgs, argc, argv); if (0 > argsFromCL(theArgs, argc, argv)) { @@ -184,6 +209,11 @@ int readoutMain(int argc, char *argv[]) argsDump(theArgs); + /* give unique name to shared memory*/ + strcat(shmname, theArgs->shmnum); + + printf("shared memory name: %s\n",shmname); + if (NULL == (worker = Worker_initBegin(argv[0], sigHandler, theArgs->priority, theArgs->isStandalone))) { syslog(LOG_ERR, "connecting to agent: %s", strerror(errno)); goto bailOut0; @@ -192,8 +222,8 @@ int readoutMain(int argc, char *argv[]) syslog(LOG_ERR, "initializing hardware: %s", strerror(errno)); goto bailOut1; } - if (NULL == (shmTrans = ShmTrans_open("subevtqueue", 2 * theArgs->queueSize))) { - syslog(LOG_ERR, "opening shared memory \"%s\": %s", "subevtqueue", strerror(errno)); + if (NULL == (shmTrans = ShmTrans_open(shmname, 2 * theArgs->queueSize))) { + syslog(LOG_ERR, "opening shared memory \"%s\": %s", shmname, strerror(errno)); goto bailOut2; } trigAccepted = Worker_addStatistic(worker, "trigAccepted");