[BACK]Return to oxmain.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kxx

Annotation of OpenXM/src/kxx/oxmain.c, Revision 1.28

1.28    ! takayama    1: /*  $OpenXM: OpenXM/src/kxx/oxmain.c,v 1.27 2016/03/30 21:34:03 takayama Exp $  */
1.25      takayama    2: /*  Note on IntelMac. [2006.06.05]
                      3:     SIGINT does not seem to be blocked on the rosetta emulator of ppc
                      4:     on the IntelMac's. "ox" should be universal binary.
                      5:    A dirty hack to generate a universal binary of ox is as follows.
                      6:    (1) Add -arch ppc -arch i386 to CFLAGS in src/kxx/Makefile
                      7:        and src/kan96xx/plugin/Makefile
                      8:    (2) Build ox
                      9: */
1.1       maekawa    10: /* nullserver01 */
                     11: #include <stdio.h>
1.4       takayama   12: #include <fcntl.h>
1.10      takayama   13: #include <unistd.h>
1.1       maekawa    14: #include <sys/types.h>
                     15: #include <sys/socket.h>
                     16: #include <sys/time.h>
1.23      takayama   17: #include <sys/resource.h>
1.1       maekawa    18: #include <netinet/in.h>
                     19: #include <netdb.h>
                     20: #include <signal.h>
                     21: #include <setjmp.h>
1.14      takayama   22: #include <stdlib.h>
1.1       maekawa    23: /* -lnsl -lsocket /usr/ucblib/libucb.a */
                     24: #include "ox_kan.h"
                     25: #include "serversm.h"
                     26:
1.4       takayama   27: #define SERVERNAME "ox_sm1"
1.1       maekawa    28:
1.14      takayama   29: extern char **environ;
1.1       maekawa    30: int OxCritical = 0;
                     31: int OxInterruptFlag = 0;
1.12      takayama   32: int OxTerminateMode = 0;
1.1       maekawa    33:
                     34: int SerialCurrentControl;
                     35:
                     36: int MyServerPid;
1.4       takayama   37: #define SERVERNAME_SIZE 4096
                     38: char ServerName[SERVERNAME_SIZE];
1.1       maekawa    39: int PacketMonitor = 0;
                     40: int Quiet = 0;
                     41:
                     42: int LocalMode = 1;
                     43: int NotifyPortnumber = 0;
1.4       takayama   44: int Do_not_use_control_stream_to_tell_no_server = 1;
1.24      takayama   45: int IgnoreSIGINT = 1;
1.28    ! takayama   46: int Ox_protocol_1999 = 0;
1.4       takayama   47: static void errorToStartEngine(void);
                     48: static int findOxServer(char *server);
                     49: static void couldNotFind(char *s);
1.8       takayama   50: /*  gcc -v -c hoge.c */
1.26      takayama   51: static void mywait(int m);
1.15      takayama   52:
                     53: void *sGC_malloc(int n) {
                     54:   return (void *)malloc(n);
                     55: }
1.1       maekawa    56:
                     57: main(int argc, char *argv[]) {
                     58:   int fd;
                     59:   int size;
                     60:   char sname[1024];
                     61:   int tmp[1];
                     62:   char *buf;
                     63:   int i;
                     64:   int fdControl = -1; int portControl = 1200;
                     65:   int fdStream = -1;  int portStream = 1300;
                     66:   int reverse = 0;
                     67:   extern int OpenedSocket;
                     68:   char portfile[1024];
1.12      takayama   69:   char *pass = NULL;
1.18      takayama   70:   char *passControl = NULL;
                     71:   char *passData = NULL;
1.4       takayama   72:   int result;
1.9       takayama   73:   int sleepingTime = 0;
1.22      takayama   74:   int authEncoding=0;
                     75:   FILE *fp;
                     76:   char *stmp;
1.12      takayama   77:   extern int OxTerminateMode;
1.1       maekawa    78:
1.26      takayama   79:   int sighup[]={SIGHUP,-1};
                     80:   block_signal(sighup);  /* ignore x of xterm */
1.1       maekawa    81:   strcpy(sname,"localhost");
                     82:   strcpy(ServerName,SERVERNAME);
                     83:   i = 1;
1.2       takayama   84:   if (argc == 1) {
                     85:     oxmainUsage();
1.12      takayama   86:     exit(10);
1.2       takayama   87:   }
1.1       maekawa    88:   while (i<argc) {
                     89:     if (strcmp(argv[i],"-host") == 0) {
                     90:       i++;
                     91:       if (i<argc) strcpy(sname,argv[i]);
                     92:     }else if (strcmp(argv[i],"-data")==0) {
                     93:       i++;
                     94:       if (i<argc) sscanf(argv[i],"%d",&portStream);
                     95:     }else if (strcmp(argv[i],"-control")==0) {
                     96:       i++;
                     97:       if (i<argc) sscanf(argv[i],"%d",&portControl);
                     98:     }else if (strcmp(argv[i],"-ox") == 0) {
                     99:       i++;
                    100:       if (i<argc) strcpy(ServerName,argv[i]);
                    101:     }else if (strcmp(argv[i],"-monitor") == 0) {
                    102:       PacketMonitor = 1;
                    103:     }else if (strcmp(argv[i],"-insecure") == 0) {
                    104:       LocalMode = 0;
                    105:     }else if (strcmp(argv[i],"-reverse") == 0) {
                    106:       reverse = 1;
1.12      takayama  107:     }else if (strcmp(argv[i],"-finish") == 0) {
                    108:       OxTerminateMode = 1;
1.1       maekawa   109:     }else if (strcmp(argv[i],"-portfile") == 0) {
                    110:       i++;
                    111:       if (i<argc) {
1.7       takayama  112:         sscanf(argv[i],"%s",portfile);
                    113:         portControl = 0;
                    114:         portStream = 0;
                    115:         NotifyPortnumber = 1;
1.1       maekawa   116:       }
                    117:     }else if (strcmp(argv[i],"-pass") == 0) {
                    118:       i++;
                    119:       if (i<argc) {
1.7       takayama  120:         pass = argv[i];
1.1       maekawa   121:       }
1.18      takayama  122:     }else if (strcmp(argv[i],"-passData") == 0) {
                    123:       i++;
                    124:       if (i<argc) {
                    125:         passData = argv[i];
                    126:       }
                    127:     }else if (strcmp(argv[i],"-passControl") == 0) {
                    128:       i++;
                    129:       if (i<argc) {
                    130:         passControl = argv[i];
                    131:       }
1.9       takayama  132:     }else if (strcmp(argv[i],"-wait") == 0) {
                    133:       i++;
                    134:       if (i<argc) {
                    135:         sscanf(argv[i],"%d",&sleepingTime);
                    136:       }
1.22      takayama  137:     }else if (strcmp(argv[i],"-authEncoding") == 0) {
                    138:       i++;
                    139:       if (strcmp(argv[i],"file") == 0) {
                    140:         authEncoding = 1;
                    141:       }else{
                    142:         fprintf(stderr,"Unknown -authEncoding %s.\n",argv[i]);
                    143:         oxmainUsage(); exit(10);
                    144:       }
1.24      takayama  145:     }else if (strcmp(argv[i],"-ignoreSIGINT") == 0) {
                    146:       i++;
                    147:       if (i<argc) {
1.25      takayama  148:         sscanf(argv[i],"%d",&IgnoreSIGINT);
1.24      takayama  149:       }
1.28    ! takayama  150:     }else if (strcmp(argv[i],"-protocol_1999") == 0) {
        !           151:       Ox_protocol_1999=1;
1.1       maekawa   152:     }else {
                    153:       fprintf(stderr,"Unknown option %s.\n",argv[i]);
                    154:       oxmainUsage(); exit(10);
                    155:     }
                    156:     i++;
                    157:   }
                    158:
1.4       takayama  159:   if (Do_not_use_control_stream_to_tell_no_server) {
1.7       takayama  160:     if (findOxServer(ServerName) < 0) {
                    161:       fprintf(stderr,"Sleeping five seconds...\n");
                    162:       sleep(5);
                    163:       exit(-1);
                    164:     }
1.9       takayama  165:   }
                    166:
                    167:   if (sleepingTime) {
                    168:     fprintf(stderr,"Waiting to connect for %d seconds...\n",sleepingTime);
                    169:     sleep(sleepingTime);
                    170:     fprintf(stderr,"\nTrying to connect\n");
1.4       takayama  171:   }
                    172:
1.18      takayama  173:   if ((pass != NULL) && (passData == NULL)) {
                    174:        passData = pass;
                    175:   }
                    176:   if ((pass != NULL) && (passControl == NULL)) {
                    177:     passControl = pass;
                    178:   }
                    179:
1.19      takayama  180:   /* Decrypt passControl and passData, here. Lookup cryptmethod. */
1.22      takayama  181:   if (authEncoding == 1) {
                    182:        stmp = (char *)sGC_malloc(strlen(getenv("HOME"))+strlen(passControl)+
                    183:                                                          strlen(passData)+128);
                    184:        sprintf(stmp,"%s/.openxm/tmp.opt/%s",(char *)getenv("HOME"),passControl);
                    185:        fp = fopen(stmp,"r");
                    186:        if (fp == NULL) { fprintf(stderr,"passControl file %s is not found.\n",stmp); exit(1);}
                    187:        fgets(stmp,127,fp); passControl = stmp; fclose(fp);
                    188:
                    189:        stmp = (char *)sGC_malloc(strlen(getenv("HOME"))+strlen(passControl)+
                    190:                                                          strlen(passData)+128);
                    191:        sprintf(stmp,"%s/.openxm/tmp.opt/%s",(char *)getenv("HOME"),passData);
                    192:        fp = fopen(stmp,"r");
                    193:        if (fp == NULL) { fprintf(stderr,"passData file %s is not found.\n",stmp); exit(1);}
                    194:        fgets(stmp,127,fp); passData = stmp; fclose(fp);
                    195:   }
1.19      takayama  196:
1.1       maekawa   197:   if (reverse) {
                    198:     /* The order is very important. */
1.18      takayama  199:     fdControl = socketConnectWithPass(sname,portControl,passControl);
                    200:     fdStream = socketConnectWithPass(sname,portStream,passData);
1.1       maekawa   201:
                    202:     fprintf(stderr,"Connected: control = %d, data = %d.\n",fdControl,fdStream);
1.7       takayama  203:     result = 0;
1.5       takayama  204:
                    205:
1.20      takayama  206:     if ((fdControl < 0) ||  (fdStream < 0)) {
                    207:       fprintf(stderr,"Waiting for 10 seconds to show an error.\n");
                    208:       sleep(10);
                    209:     }
                    210:
1.1       maekawa   211:     if (portControl != -1) {
                    212:       MyServerPid = fork();
                    213:       if (MyServerPid > 0 ) parentServerMain(fdControl,fdStream);
1.4       takayama  214:       else result=childServerMain(fdControl,fdStream);
1.1       maekawa   215:     }else{
1.4       takayama  216:       result=childServerMain(fdControl,fdStream);
1.1       maekawa   217:     }
1.4       takayama  218:     /* This line will be never executed in case of success */
1.7       takayama  219:     if (result < 0 ) {
                    220:       errorToStartEngine();
                    221:     }
1.1       maekawa   222:   }
                    223:
                    224:   /* non-reverse case. */
                    225:   fprintf(stderr,"Hostname is %s \n",sname);
                    226:   fprintf(stderr,"Port for data (-data) = %d \n",portStream);
                    227:   fprintf(stderr,"Port for control message (-control) = %d \n",portControl);
                    228:   fflush(NULL);
                    229:
                    230:
                    231:   if (LocalMode) {
                    232:     if (portControl != -1) {
                    233:       fdControl = socketOpen(sname,portControl);
                    234:       portControl = OpenedSocket;
                    235:       if (NotifyPortnumber) {
1.7       takayama  236:         oxWritePortFile(0,portControl,portfile);
1.1       maekawa   237:       }
                    238:       fdControl = socketAcceptLocal(fdControl);
                    239:       fprintf(stderr,"\n control port %d : Connected.\n",portControl);
                    240:     }
                    241:     if (portStream != -1) {
                    242:       fdStream = socketOpen(sname,portStream);
                    243:       portStream = OpenedSocket;
                    244:       if (NotifyPortnumber) {
1.7       takayama  245:         oxWritePortFile(1,portStream,portfile);
1.1       maekawa   246:       }
                    247:       fdStream = socketAcceptLocal(fdStream);
                    248:       fprintf(stderr,"\n stream port %d : Connected.\n",portStream);
                    249:     }
                    250:   }else{
                    251:     if (portControl != -1) {
                    252:       fdControl = socketOpen(sname,portControl);
                    253:       portControl = OpenedSocket;
                    254:       if (NotifyPortnumber) {
1.7       takayama  255:         oxWritePortFile(0,portControl,portfile);
1.1       maekawa   256:       }
                    257:       fdControl = socketAccept(fdControl);
                    258:       fprintf(stderr,"\n control port %d : Connected.\n",portControl);
                    259:     }
                    260:     if (portStream != -1) {
                    261:       fdStream = socketOpen(sname,portStream);
                    262:       portStream = OpenedSocket;
                    263:       if (NotifyPortnumber) {
1.7       takayama  264:         oxWritePortFile(1,portStream,portfile);
1.1       maekawa   265:       }
                    266:       fdStream = socketAccept(fdStream);
                    267:       fprintf(stderr,"\n stream port %d : Connected.\n",portStream);
                    268:     }
                    269:   }
                    270:
1.19      takayama  271:   if (passControl != NULL) {
                    272:        char *s; int mm;
                    273:        fprintf(stderr,"passControl\n");
                    274:        mm = strlen(passControl);
                    275:        s = (char *) malloc(mm+1);
                    276:     if (s == NULL) {fprintf(stderr,"No more memory.\n"); exit(1); }
                    277:        if (read(fdControl,s,mm+1) < 0) {
                    278:          fprintf(stderr,"Read error to read passControl\n"); sleep(5); exit(1);
                    279:        }
                    280:     s[mm] = 0;
                    281:        if (strcmp(s,passControl) != 0) {
                    282:          fprintf(stderr,"s=%s and passControl=%s  do not match.\n",s,passControl); sleep(5); exit(1);
                    283:        }
                    284:        free(s);
                    285:   }
                    286:   if (passData != NULL) {
                    287:        char *s; int mm;
                    288:        mm = strlen(passData);
                    289:        fprintf(stderr,"passData\n");
                    290:        s = (char *) malloc(mm+1);
                    291:     if (s == NULL) {fprintf(stderr,"No more memory.\n"); exit(1); }
                    292:        if (read(fdStream,s,mm+1) < 0) {
                    293:          fprintf(stderr,"Read error to read passData\n");
                    294:          errorToStartEngine();
                    295:        }
                    296:        if (strcmp(s,passData) != 0) {
                    297:          fprintf(stderr,"s=%s and passData=%s  do not match.\n",s,passData);
                    298:          errorToStartEngine();
                    299:        }
                    300:     free(s);
                    301:   }
1.1       maekawa   302:
1.20      takayama  303:   if ((fdControl < 0) ||  (fdStream < 0)) {
                    304:     fprintf(stderr,"Waiting for 10 seconds to show an error.\n");
                    305:     sleep(10);
                    306:   }
                    307:
                    308:
1.4       takayama  309:   result = 0;
1.1       maekawa   310:   if (portControl != -1) {
                    311:     MyServerPid = fork();
                    312:     if (MyServerPid > 0 ) parentServerMain(fdControl,fdStream);
1.4       takayama  313:     else result = childServerMain(fdControl,fdStream);
1.1       maekawa   314:   }else{
1.4       takayama  315:     result = childServerMain(fdControl,fdStream);
1.1       maekawa   316:   }
1.4       takayama  317:   if (result < 0) errorToStartEngine();
                    318: }
1.1       maekawa   319:
1.4       takayama  320: static void errorToStartEngine(void) {
                    321:   fprintf(stderr,"Failed to start the engine. Childing process is terminating.\n");
                    322:   /* You have to tell to the control server that there is no engine.
1.7       takayama  323:      And, the control server must tell the client that there is no
                    324:      engine.
                    325:      This part has not yet been implemented.
                    326:      If you implement this, set Do_not_use_control_stream_to_tell_no_server to
                    327:      zero.
                    328:   */
1.20      takayama  329:   sleep(10);
1.4       takayama  330:   exit(-1);
1.1       maekawa   331: }
                    332:
                    333: oxmainUsage() {
                    334:   fprintf(stderr,"Usage: \n");
                    335:   fprintf(stderr,"  ox [-ox serverprogram -host name -data portnum -control portnum -monitor]\n");
1.18      takayama  336:   fprintf(stderr," [-insecure -portfile fname -reverse -passControl xxxyyyzzz -passData pppqqqrrr]");
1.24      takayama  337:   fprintf(stderr," [-finish]  [-wait seconds] [-authEncoding [file]]");
                    338:   fprintf(stderr," [-ignoreSIGINT [1|0]]");
1.1       maekawa   339:   fprintf(stderr,"\n");
1.2       takayama  340:   fprintf(stderr,"-reverse: ox server connects to the client.\n");
1.18      takayama  341:   fprintf(stderr,"          The client must give a one time password to ox server to connect to the client with -pass* option.\n");
1.2       takayama  342:   fprintf(stderr,"          The one time password can be seen by ps command, so you must not use this one time password system on an untrustful host.\n");
                    343:   fprintf(stderr,"          The one time password should be sent by a safe communication line like ssh and the ox server should be started by ssh. Do not use rsh\n");
1.18      takayama  344:   fprintf(stderr,"          (The option -pass is obsolete.)\n");
1.2       takayama  345:   fprintf(stderr,"          If -reverse is not given, the client connect to the ox server\n");
                    346:   fprintf(stderr,"          See OpenXM/src/SSkan/Doc/ox.sm1, /sm1connectr\n");
                    347:   fprintf(stderr,"-insecure : \n");
                    348:   fprintf(stderr,"          If you access to the server from a localhost, you do not need one time password. However, if you access outside of the localhost, a one time password is required. To turn off this restriction, -insecure option is used.\n");
1.4       takayama  349:   fprintf(stderr,"\n");
                    350:   fprintf(stderr,"If ox fails to find the serverprogram, it tries to look for it in /usr/local/OpenXM/bin and $OpenXM_HOME/bin.\n");
                    351:   fprintf(stderr,"\n");
1.2       takayama  352:   fprintf(stderr,"Example 1:\n");
1.3       takayama  353:   fprintf(stderr,"(Start the ox server): dc1%% ox -ox ~/OpenXM/bin/ox_sm1 -host dc1.math.kobe-u.ac.jp -insecure -control 1200 -data 1300\n");
1.2       takayama  354:   fprintf(stderr,"(client):  sm1\n ");
                    355:   fprintf(stderr,"           (ox.sm1) run ; \n");
1.1       maekawa   356:   fprintf(stderr,"           sm1>[(dc1.math.kobe-u.ac.jp) 1300 1200] oxconnect /ox.ccc set\n");
1.2       takayama  357:   fprintf(stderr,"Example 2:\n");
                    358:   fprintf(stderr,"(Start the ox server): dc1%% ox -ox ~/OpenXM/bin/ox_sm1\n");
                    359:   fprintf(stderr,"(client): dc1%% sm1\n ");
                    360:   fprintf(stderr,"           (ox.sm1) run ; \n");
                    361:   fprintf(stderr,"           sm1>[(localhost) 1300 1200] oxconnect /ox.ccc set\n");
1.1       maekawa   362:   fprintf(stderr,"\n");
                    363: }
                    364:
                    365: parentServerMain(int fdControl, int fdStream) {
                    366:   int id;
                    367:   int mtag;
                    368:   int size;
                    369:   int n;
                    370:   int r;
                    371:   int message = 1;
                    372:   int controlByteOrder;
1.12      takayama  373:   extern OxTerminateMode;
1.26      takayama  374:   extern void myServerExit(int m);
1.1       maekawa   375:
1.26      takayama  376:   int sigchld[]={SIGCHLD,-1};
                    377:   unblock_signal(sigchld);
1.12      takayama  378:   if (OxTerminateMode) {
                    379:        /*
                    380:          OxTerminateMode cannot be used if you run ox by xterm -exec ox ...
                    381:         */
                    382:        if (fork()) {
                    383:          close(fdControl); close(fdStream);
                    384:          /* Parent */
                    385:          exit(0);  /*Tell the caller that launching is successfully finished.*/
                    386:        }
                    387:   }
                    388:
1.13      takayama  389:   controlByteOrder = oxTellMyByteOrder(fdControl,fdControl);
1.1       maekawa   390:   /* Set the network byte order. */
                    391:   fprintf(stderr,"controlByteOrder=%x\n",controlByteOrder);
                    392:
1.26      takayama  393:   int sigint[]={SIGINT,-1};
1.27      takayama  394:   set_signal(sigint[0],myServerExit);
1.26      takayama  395:   unblock_signal(sigint);
1.1       maekawa   396:   while(1) {
                    397:     mtag = oxfdGetOXheader(fdControl,&SerialCurrentControl);
                    398:     /* get the message_tag */
                    399:     /* message_body */
                    400:     id = oxfdGetInt32(fdControl);   /* get the function_id */
                    401:     if (message) {printf("\n[control] control function_id is %d\n",id);}
                    402:     switch( id ) {
                    403:     case SM_control_kill:
                    404:       if (message) printf("[control] control_kill\n");
1.28    ! takayama  405:       /* oxSendResultOfControl(fdControl); */
1.1       maekawa   406:       sleep(2);
1.26      takayama  407:       myServerExit(0);
1.1       maekawa   408:       break;
                    409:     case SM_control_reset_connection:
                    410:       if (message) printf("[control] control_reset_connection.\n");
                    411:       if (message) printf("Sending the SIGUSR1 signal to %d:  ",MyServerPid);
                    412:       r=kill(MyServerPid,SIGUSR1);
                    413:       if (message) printf("Result = %d\n",r);
1.28    ! takayama  414:       if (Ox_protocol_1999) {
        !           415:        if (message) printf("[obsolete protocol of ox-rfc-100 in 1999] Sending the result packet to the control channel.\n",r);
        !           416:         oxSendResultOfControlInt32(fdControl,0);
        !           417:       }
1.1       maekawa   418:       fflush(NULL);
1.7       takayama  419:       /*      oxSendResultOfControlInt32(fdControl,0); */
1.1       maekawa   420:       break;
                    421:     default:
                    422:       fprintf(stderr,"[control] Unknown control message.\n");
                    423:       fprintf(stderr,"Shutdown the server.");
1.26      takayama  424:       myServerExit(0);
1.1       maekawa   425:       break;
                    426:     }
                    427:   }
                    428: }
                    429:
1.26      takayama  430: void myServerExit(int m) {
1.1       maekawa   431:   printf("Sending the kill signal to the child.\n");
                    432:   kill(MyServerPid,SIGKILL);
1.12      takayama  433:   exit(0);
1.1       maekawa   434: }
                    435:
                    436: childServerMain(int fdControl, int fdStream) {
                    437:   int i;
1.23      takayama  438:   struct rlimit res;
1.1       maekawa   439:   close(fdControl);   /* close(0); dup(fdStream); */
                    440:   dup2(fdStream,3);
                    441:   dup2(fdStream,4);
1.4       takayama  442:   /*close(0);
1.7       takayama  443:     #include <sys/param.h>
                    444:     for (i=5; i<NOFILE; i++) close(i);
                    445:   */
1.4       takayama  446:   if (!Do_not_use_control_stream_to_tell_no_server) {
1.7       takayama  447:     if (findOxServer(ServerName) < 0) {
                    448:       return(-1);
                    449:     }
1.4       takayama  450:   }
1.5       takayama  451:   fprintf(stderr,"childServerMain: Starting the server %s\n",ServerName); fflush(NULL);
1.14      takayama  452:
                    453:   /*
                    454:   {
                    455:        int i;
                    456:        i=0;
                    457:        while (environ[i] != NULL) {
                    458:          fprintf(stderr,"%s ",environ[i++]);
                    459:        }
                    460:        fprintf(stderr,"\n");
                    461:   }
                    462:   */
                    463:   /* bug: xterm of potato does not seem to pass the LD_LIBRARY_PATH.
                    464:       So, the new gc does not work.
                    465:      it is an workaround for OpenXM */
                    466:   if (getenv("LD_LIBRARY_PATH") == (char *)NULL) {
                    467:        char *s,*o;
                    468:     fprintf(stderr,"Hmm... LD_LIBRARY_PATH does not seem to be set.\n");
                    469:     o = getenv("OpenXM_HOME");
                    470:        if (o == NULL) {
                    471:          fprintf(stderr,"Giving up to set the LD_LIBRARY_PATH variable.\n");
                    472:        }else{
                    473:          s = (char *)malloc(strlen(o)+64);
                    474:          sprintf(s,"LD_LIBRARY_PATH=%s/lib",o);
                    475:          putenv(s);
                    476:        }
                    477:   }
1.23      takayama  478:   getrlimit(RLIMIT_STACK,&res);
                    479:   if (res.rlim_cur < 65536000) {
                    480:     fprintf(stderr,"RLIMIT_STACK is increased to 65Mbytes by setrlimit.\n");
                    481:        res.rlim_cur = 65536000;
                    482:        setrlimit(RLIMIT_STACK,&res);
                    483:   }
1.24      takayama  484:
1.26      takayama  485:   int sigint[]={SIGINT,-1};
                    486:   if (IgnoreSIGINT) { block_signal(sigint); fprintf(stderr,"SIGING\n");}
1.24      takayama  487:
1.1       maekawa   488:   if (PacketMonitor) {
1.14      takayama  489:     if (execle(ServerName,ServerName,"-monitor",NULL,environ)) {
1.1       maekawa   490:       fprintf(stderr,"%s cannot be executed with -monitor.\n",ServerName);
1.7       takayama  491:       fflush(NULL);
                    492:       return(-1);
1.1       maekawa   493:     }
                    494:   }else {
1.14      takayama  495:     if (execle(ServerName,ServerName,NULL,environ)) {
1.1       maekawa   496:       fprintf(stderr,"%s cannot be executed.\n",ServerName);
1.7       takayama  497:       fflush(NULL);
                    498:       return(-1);
1.1       maekawa   499:     }
                    500:   }
1.4       takayama  501:   /* never reached. */
1.1       maekawa   502: }
                    503:
                    504:
                    505: /* These are dummy.  It is defined in stackmachine.c */
                    506: unlockCtrlCForOx() { ; }
                    507: restoreLockCtrlCForOx() { ; }
                    508:
1.4       takayama  509: static int findOxServer(char *server) {
                    510:   char *p;
                    511:   char *p2;
                    512:   if (strlen(server) == 0) return(-1);
1.10      takayama  513:   /* fd = open(server,O_RDONLY); */
1.11      ohara     514:   if (access(server,X_OK&R_OK) == 0) {
1.7       takayama  515:     fprintf(stderr,"Starting OX server : %s\n",server);
                    516:     return(0);
1.4       takayama  517:   }
                    518:   if (server[0] == '/') {
1.7       takayama  519:     couldNotFind(server);
                    520:     return(-1);
1.4       takayama  521:   }
                    522:   fprintf(stderr,"The server %s was not found. Trying to find it under OpenXM/bin\n",server);
                    523:   p = getenv("OpenXM_HOME");
                    524:   if (p == NULL) {
                    525:     p = "/usr/local/OpenXM";
                    526:   }
                    527:   p2 = (char *) malloc(sizeof(char)*(strlen(p)+strlen("/bin/")+3+strlen(server)));
                    528:   if (p2 == NULL) { fprintf(stderr,"No more memory.\n"); exit(10); }
                    529:   strcpy(p2,p); strcat(p2,"/bin/"); strcat(p2,server);
1.10      takayama  530:   /* fd = open(p2,O_RDONLY); */
1.11      ohara     531:   if (access(p2,X_OK&R_OK) == 0) {
1.7       takayama  532:     fprintf(stderr,"Starting OX server : %s\n",p2);
                    533:     if (strlen(p2) < SERVERNAME_SIZE) strcpy(server,p2);
                    534:     else {
                    535:       couldNotFind("Too long ox server name.");
                    536:       return(-1);
                    537:     }
                    538:     return(0);
1.4       takayama  539:   }
                    540:   couldNotFind(p2);
                    541:   return(-1);
                    542: }
1.1       maekawa   543:
1.4       takayama  544: static void couldNotFind(char *s) {
                    545:   fprintf(stderr,"OX server %s could not be found.\n",s);
                    546: }
1.1       maekawa   547:
                    548:
1.26      takayama  549: static void mywait(int m) {
1.21      takayama  550:   int status;
                    551:   int pid;
                    552:   int i,j;
                    553:   /* signal(SIGCHLD,SIG_IGN); */
                    554:   pid = wait(&status);
                    555:   fprintf(stderr,"Control: child process %d is exiting.\n",pid);
                    556:   fprintf(stderr,"Control: Shutting down the control server.\n");
                    557:   sleep(2);
                    558:   exit(0);
                    559: }
1.1       maekawa   560:
                    561:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>