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

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

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

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