]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
added RPC-ProgId Option to trbnetd, now serveral trbnetd can run on one machine,...
authorhadaq <hadaq>
Wed, 10 Oct 2012 16:39:51 +0000 (16:39 +0000)
committerhadaq <hadaq>
Wed, 10 Oct 2012 16:39:51 +0000 (16:39 +0000)
trbnetd/server/trbnetd.c
trbnetd/trbnetrpc.c

index b51def0e7e9fe1a4ad5829128785bfcefcc68cca..a3409ce7a92719ce1a5a56a98b08260c6948a320 100644 (file)
@@ -14,7 +14,8 @@
 
 #include "trbrpc.h"
 
-static const char trbnetd_version[] = "$Revision: 1.13 $";
+static const char trbnetd_version[] = "$Revision: 1.14 $";
+static uint32_t server_rpc_prog_id = TRBNETRPCPROG;
 
 static int daemon_lock = 0;
 
@@ -490,9 +491,10 @@ static void blockDaemon(int sig) {
 
 void usage(const char *progName)
 {
-  fprintf(stdout, "Usage: %s [-h] [-f]\n", progName);
+  fprintf(stdout, "Usage: %s [-h] [-f] [-i progId]\n", progName);
   fprintf(stdout, "Options:\n");
   fprintf(stdout, "  -h    give this help\n");
+  fprintf(stdout, "  -i    set an individual RPC-ProgId (0-255), default 0\n");
   fprintf(stdout, "  -f    execute as foreground process\n");
   fprintf(stdout, "  -V    version number\n");
   fprintf(stdout, "\nSignals:\n");
@@ -510,7 +512,7 @@ int main(int argc, char **argv)
   int opt;
   
   optind = 1;
-  while ((opt = getopt(argc, argv, "+hfVd:")) != -1) {
+  while ((opt = getopt(argc, argv, "+hfi:Vd:")) != -1) {
     switch (opt) {
     case '?':
       usage(basename(argv[0]));
@@ -518,11 +520,15 @@ int main(int argc, char **argv)
     case 'h':
       usage(basename(argv[0]));
       return 0;
+    case 'i':
+      server_rpc_prog_id = ((server_rpc_prog_id & 0xffff00ff) | 
+                            ((strtoul(optarg, NULL, 0) & 0xff) << 8));
+      break;
     case 'f':
       daemonMode = 0;
       break;
     case 'd':
-      trb_debug = strtoul(optarg, NULL, 0);
+      trb_debug = strtoul(optarg, NULL, 0); 
       break;
     case 'V':      
       printf("%s %s, using libtrbnet %s\n",
@@ -534,7 +540,7 @@ int main(int argc, char **argv)
       break;
     }
   }
-  
+
   /* Block Signal SIGPIPE */
   sigemptyset(&blockSet);
   sigaddset(&blockSet, SIGPIPE);
@@ -544,7 +550,7 @@ int main(int argc, char **argv)
   if (signal(SIGUSR1, blockDaemon) == SIG_ERR) abort();
   if (signal(SIGUSR2, blockDaemon) == SIG_ERR) abort();
 
-  pmap_unset(TRBNETRPCPROG, TRBNETRPCVERS);
+  pmap_unset(server_rpc_prog_id, TRBNETRPCVERS);
 
   transp = svctcp_create(RPC_ANYSOCK, 0, 0);
   if (transp == NULL) {
@@ -552,9 +558,9 @@ int main(int argc, char **argv)
     exit(EXIT_FAILURE);
   }
   if (!svc_register
-      (transp, TRBNETRPCPROG, TRBNETRPCVERS, trbnetrpcprog_1, IPPROTO_TCP)) {
+      (transp, server_rpc_prog_id, TRBNETRPCVERS, trbnetrpcprog_1, IPPROTO_TCP)) {
     fprintf(stderr, "%s",
-            "unable to register (TRBNETRPCPROG, TRBNETRPCVERS, tcp).");
+            "unable to register (server_rpc_prog_id, TRBNETRPCVERS, tcp).");
     exit(EXIT_FAILURE);
   }
 
index 18a82769305eba6e11bdbd963964ad7dcb3985fa..34f15b6da776ffdac79ac70ea3a35e6b18cec372 100644 (file)
@@ -1,12 +1,13 @@
 #include <stdio.h>
 #include <rpc/rpc.h>            /* always needed  */
 #include <unistd.h>
+#include <strings.h>
 #include "trbrpc.h"             /* will be generated by rpcgen */
 #include <trberror.h>
 
 #include "trbnet.h"
 
-const char trbnet_version[] = "$Revision: 1.12 $  RPC";
+const char trbnet_version[] = "$Revision: 1.13 $  RPC";
 unsigned int trb_debug = 0;
 unsigned int trb_dma = 0;
 static CLIENT *trb_client = NULL;
@@ -24,18 +25,28 @@ static void copyStatus(const Status* status)
 
 int trb_connect(const char *server)
 {
+  uint32_t server_rpc_prog_id = TRBNETRPCPROG;
+
   if (server == NULL) {
     char *tmp;
     tmp = getenv("DAQOPSERVER");
     if (tmp != NULL) {
+      uint32_t id = 0;
+      char* separator =  NULL;
+      if ((separator = rindex(tmp, ':')) != NULL) {
+        *separator = '\0';
+        id = strtoul(separator + 1, NULL, 0);
+      }
       strncpy(trb_server, tmp, 128);
+      server_rpc_prog_id = ((server_rpc_prog_id & 0xffff00ff) | (id << 8));
     } else {
       sprintf(trb_server, "etraxp023");
     }
   } else {
     strncpy(trb_server, server, 128);
   }
-  trb_client = clnt_create(trb_server, TRBNETRPCPROG, TRBNETRPCVERS, "tcp");
+  trb_client = clnt_create(trb_server, server_rpc_prog_id, 
+                           TRBNETRPCVERS, "tcp");
   if (trb_client == NULL) {
     /*
      * Couldn't establish connection with server.