=================================================================== RCS file: /home/cvs/OpenXM/src/kxx/oxmain.c,v retrieving revision 1.12 retrieving revision 1.20 diff -u -p -r1.12 -r1.20 --- OpenXM/src/kxx/oxmain.c 2002/10/28 00:38:32 1.12 +++ OpenXM/src/kxx/oxmain.c 2004/09/17 12:32:11 1.20 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/kxx/oxmain.c,v 1.11 2002/05/02 08:33:47 ohara Exp $ */ +/* $OpenXM: OpenXM/src/kxx/oxmain.c,v 1.19 2004/09/17 08:46:10 takayama Exp $ */ /* nullserver01 */ #include #include @@ -10,12 +10,14 @@ #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; @@ -34,11 +36,12 @@ int Do_not_use_control_stream_to_tell_no_server = 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 */ +void *sGC_malloc(int n) { + return (void *)malloc(n); +} + main(int argc, char *argv[]) { int fd; int size; @@ -52,10 +55,13 @@ 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; extern int OxTerminateMode; + signal(SIGHUP,SIG_IGN); /* ignore x of xterm */ strcpy(sname,"localhost"); strcpy(ServerName,SERVERNAME); i = 1; @@ -97,6 +103,16 @@ main(int argc, char *argv[]) { if (i 0 ) parentServerMain(fdControl,fdStream); @@ -192,7 +222,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 +280,21 @@ 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," [-insecure -portfile fname -reverse -passControl xxxyyyzzz -passData pppqqqrrr]"); fprintf(stderr," [-finish]"); 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"); @@ -269,7 +337,7 @@ parentServerMain(int fdControl, int fdStream) { } } - controlByteOrder = oxTellMyByteOrder(fdControl); + controlByteOrder = oxTellMyByteOrder(fdControl,fdControl); /* Set the network byte order. */ fprintf(stderr,"controlByteOrder=%x\n",controlByteOrder); @@ -326,14 +394,41 @@ 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); + } + } + 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 +445,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) {