=================================================================== RCS file: /home/cvs/OpenXM/src/kxx/oxmain.c,v retrieving revision 1.18 retrieving revision 1.23 diff -u -p -r1.18 -r1.23 --- OpenXM/src/kxx/oxmain.c 2004/09/17 07:27:28 1.18 +++ OpenXM/src/kxx/oxmain.c 2006/02/25 09:11:10 1.23 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/kxx/oxmain.c,v 1.17 2004/03/03 02:31:50 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kxx/oxmain.c,v 1.22 2006/02/04 10:44:22 takayama Exp $ */ /* nullserver01 */ #include #include @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,7 @@ static void errorToStartEngine(void); static int findOxServer(char *server); static void couldNotFind(char *s); /* gcc -v -c hoge.c */ +static void mywait(); void *sGC_malloc(int n) { return (void *)malloc(n); @@ -59,6 +61,9 @@ main(int argc, char *argv[]) { char *passData = NULL; int result; int sleepingTime = 0; + int authEncoding=0; + FILE *fp; + char *stmp; extern int OxTerminateMode; signal(SIGHUP,SIG_IGN); /* ignore x of xterm */ @@ -118,6 +123,14 @@ main(int argc, char *argv[]) { if (i 0 ) parentServerMain(fdControl,fdStream); @@ -215,7 +250,44 @@ main(int argc, char *argv[]) { } } + if (passControl != NULL) { + char *s; int mm; + fprintf(stderr,"passControl\n"); + mm = strlen(passControl); + s = (char *) malloc(mm+1); + if (s == NULL) {fprintf(stderr,"No more memory.\n"); exit(1); } + if (read(fdControl,s,mm+1) < 0) { + fprintf(stderr,"Read error to read passControl\n"); sleep(5); exit(1); + } + s[mm] = 0; + if (strcmp(s,passControl) != 0) { + fprintf(stderr,"s=%s and passControl=%s do not match.\n",s,passControl); sleep(5); exit(1); + } + free(s); + } + if (passData != NULL) { + char *s; int mm; + mm = strlen(passData); + fprintf(stderr,"passData\n"); + s = (char *) malloc(mm+1); + if (s == NULL) {fprintf(stderr,"No more memory.\n"); exit(1); } + if (read(fdStream,s,mm+1) < 0) { + fprintf(stderr,"Read error to read passData\n"); + errorToStartEngine(); + } + if (strcmp(s,passData) != 0) { + fprintf(stderr,"s=%s and passData=%s do not match.\n",s,passData); + errorToStartEngine(); + } + free(s); + } + if ((fdControl < 0) || (fdStream < 0)) { + fprintf(stderr,"Waiting for 10 seconds to show an error.\n"); + sleep(10); + } + + result = 0; if (portControl != -1) { MyServerPid = fork(); @@ -236,7 +308,7 @@ static void errorToStartEngine(void) { If you implement this, set Do_not_use_control_stream_to_tell_no_server to zero. */ - sleep(2); + sleep(10); exit(-1); } @@ -282,6 +354,7 @@ parentServerMain(int fdControl, int fdStream) { extern OxTerminateMode; extern void myServerExit(); + signal(SIGCHLD,mywait); if (OxTerminateMode) { /* OxTerminateMode cannot be used if you run ox by xterm -exec ox ... @@ -337,6 +410,7 @@ void myServerExit() { childServerMain(int fdControl, int fdStream) { int i; + struct rlimit res; close(fdControl); /* close(0); dup(fdStream); */ dup2(fdStream,3); dup2(fdStream,4); @@ -376,7 +450,12 @@ childServerMain(int fdControl, int fdStream) { putenv(s); } } - + getrlimit(RLIMIT_STACK,&res); + if (res.rlim_cur < 65536000) { + fprintf(stderr,"RLIMIT_STACK is increased to 65Mbytes by setrlimit.\n"); + res.rlim_cur = 65536000; + setrlimit(RLIMIT_STACK,&res); + } if (PacketMonitor) { if (execle(ServerName,ServerName,"-monitor",NULL,environ)) { fprintf(stderr,"%s cannot be executed with -monitor.\n",ServerName); @@ -438,5 +517,16 @@ static void couldNotFind(char *s) { } +static void mywait() { + int status; + int pid; + int i,j; + /* signal(SIGCHLD,SIG_IGN); */ + pid = wait(&status); + fprintf(stderr,"Control: child process %d is exiting.\n",pid); + fprintf(stderr,"Control: Shutting down the control server.\n"); + sleep(2); + exit(0); +}