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