=================================================================== RCS file: /home/cvs/OpenXM/src/kxx/oxmain.c,v retrieving revision 1.13 retrieving revision 1.27 diff -u -p -r1.13 -r1.27 --- OpenXM/src/kxx/oxmain.c 2003/11/18 11:08:27 1.13 +++ OpenXM/src/kxx/oxmain.c 2016/03/30 21:34:03 1.27 @@ -1,4 +1,12 @@ -/* $OpenXM: OpenXM/src/kxx/oxmain.c,v 1.12 2002/10/28 00:38:32 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kxx/oxmain.c,v 1.26 2016/03/30 09:20:40 takayama Exp $ */ +/* Note on IntelMac. [2006.06.05] + SIGINT does not seem to be blocked on the rosetta emulator of ppc + on the IntelMac's. "ox" should be universal binary. + A dirty hack to generate a universal binary of ox is as follows. + (1) Add -arch ppc -arch i386 to CFLAGS in src/kxx/Makefile + and src/kan96xx/plugin/Makefile + (2) Build ox +*/ /* nullserver01 */ #include #include @@ -6,16 +14,19 @@ #include #include #include +#include #include #include #include #include +#include /* -lnsl -lsocket /usr/ucblib/libucb.a */ #include "ox_kan.h" #include "serversm.h" #define SERVERNAME "ox_sm1" +extern char **environ; int OxCritical = 0; int OxInterruptFlag = 0; int OxTerminateMode = 0; @@ -31,14 +42,17 @@ int Quiet = 0; int LocalMode = 1; int NotifyPortnumber = 0; int Do_not_use_control_stream_to_tell_no_server = 1; +int IgnoreSIGINT = 1; static void errorToStartEngine(void); static int findOxServer(char *server); static void couldNotFind(char *s); -#if defined(__CYGWIN__) -int errno; -#endif /* gcc -v -c hoge.c */ +static void mywait(int m); +void *sGC_malloc(int n) { + return (void *)malloc(n); +} + main(int argc, char *argv[]) { int fd; int size; @@ -52,10 +66,17 @@ main(int argc, char *argv[]) { extern int OpenedSocket; char portfile[1024]; char *pass = NULL; + char *passControl = NULL; + char *passData = NULL; int result; int sleepingTime = 0; + int authEncoding=0; + FILE *fp; + char *stmp; extern int OxTerminateMode; + int sighup[]={SIGHUP,-1}; + block_signal(sighup); /* ignore x of xterm */ strcpy(sname,"localhost"); strcpy(ServerName,SERVERNAME); i = 1; @@ -97,11 +118,34 @@ main(int argc, char *argv[]) { if (i 0 ) parentServerMain(fdControl,fdStream); @@ -192,7 +265,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(); @@ -213,20 +323,22 @@ 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); } oxmainUsage() { fprintf(stderr,"Usage: \n"); fprintf(stderr," ox [-ox serverprogram -host name -data portnum -control portnum -monitor]\n"); - fprintf(stderr," [-insecure -portfile fname -reverse -pass xxxyyyzzz]"); - fprintf(stderr," [-finish]"); + fprintf(stderr," [-insecure -portfile fname -reverse -passControl xxxyyyzzz -passData pppqqqrrr]"); + fprintf(stderr," [-finish] [-wait seconds] [-authEncoding [file]]"); + fprintf(stderr," [-ignoreSIGINT [1|0]]"); fprintf(stderr,"\n"); fprintf(stderr,"-reverse: ox server connects to the client.\n"); - fprintf(stderr," The client must give a one time password to ox server to connect to the client with -pass option.\n"); + fprintf(stderr," The client must give a one time password to ox server to connect to the client with -pass* option.\n"); 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"); 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"); + fprintf(stderr," (The option -pass is obsolete.)\n"); fprintf(stderr," If -reverse is not given, the client connect to the ox server\n"); fprintf(stderr," See OpenXM/src/SSkan/Doc/ox.sm1, /sm1connectr\n"); fprintf(stderr,"-insecure : \n"); @@ -256,8 +368,10 @@ parentServerMain(int fdControl, int fdStream) { int message = 1; int controlByteOrder; extern OxTerminateMode; - extern void myServerExit(); + extern void myServerExit(int m); + int sigchld[]={SIGCHLD,-1}; + unblock_signal(sigchld); if (OxTerminateMode) { /* OxTerminateMode cannot be used if you run ox by xterm -exec ox ... @@ -273,8 +387,9 @@ parentServerMain(int fdControl, int fdStream) { /* Set the network byte order. */ fprintf(stderr,"controlByteOrder=%x\n",controlByteOrder); - - signal(SIGINT,myServerExit); + int sigint[]={SIGINT,-1}; + set_signal(sigint[0],myServerExit); + unblock_signal(sigint); while(1) { mtag = oxfdGetOXheader(fdControl,&SerialCurrentControl); /* get the message_tag */ @@ -286,7 +401,7 @@ parentServerMain(int fdControl, int fdStream) { if (message) printf("[control] control_kill\n"); oxSendResultOfControl(fdControl); sleep(2); - myServerExit(); + myServerExit(0); break; case SM_control_reset_connection: if (message) printf("[control] control_reset_connection.\n"); @@ -299,13 +414,13 @@ parentServerMain(int fdControl, int fdStream) { default: fprintf(stderr,"[control] Unknown control message.\n"); fprintf(stderr,"Shutdown the server."); - myServerExit(); + myServerExit(0); break; } } } -void myServerExit() { +void myServerExit(int m) { printf("Sending the kill signal to the child.\n"); kill(MyServerPid,SIGKILL); exit(0); @@ -313,6 +428,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); @@ -326,14 +442,50 @@ childServerMain(int fdControl, int fdStream) { } } fprintf(stderr,"childServerMain: Starting the server %s\n",ServerName); fflush(NULL); + + /* + { + int i; + i=0; + while (environ[i] != NULL) { + fprintf(stderr,"%s ",environ[i++]); + } + fprintf(stderr,"\n"); + } + */ + /* bug: xterm of potato does not seem to pass the LD_LIBRARY_PATH. + So, the new gc does not work. + it is an workaround for OpenXM */ + if (getenv("LD_LIBRARY_PATH") == (char *)NULL) { + char *s,*o; + fprintf(stderr,"Hmm... LD_LIBRARY_PATH does not seem to be set.\n"); + o = getenv("OpenXM_HOME"); + if (o == NULL) { + fprintf(stderr,"Giving up to set the LD_LIBRARY_PATH variable.\n"); + }else{ + s = (char *)malloc(strlen(o)+64); + sprintf(s,"LD_LIBRARY_PATH=%s/lib",o); + 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); + } + + int sigint[]={SIGINT,-1}; + if (IgnoreSIGINT) { block_signal(sigint); fprintf(stderr,"SIGING\n");} + if (PacketMonitor) { - if (execl(ServerName,ServerName,"-monitor",NULL)) { + if (execle(ServerName,ServerName,"-monitor",NULL,environ)) { fprintf(stderr,"%s cannot be executed with -monitor.\n",ServerName); fflush(NULL); return(-1); } }else { - if (execl(ServerName,ServerName,NULL)) { + if (execle(ServerName,ServerName,NULL,environ)) { fprintf(stderr,"%s cannot be executed.\n",ServerName); fflush(NULL); return(-1); @@ -350,7 +502,6 @@ restoreLockCtrlCForOx() { ; } static int findOxServer(char *server) { char *p; char *p2; - char *getenv(char *s); if (strlen(server) == 0) return(-1); /* fd = open(server,O_RDONLY); */ if (access(server,X_OK&R_OK) == 0) { @@ -388,5 +539,16 @@ static void couldNotFind(char *s) { } +static void mywait(int m) { + 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); +}