=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/plugin/oxmisc.c,v retrieving revision 1.25 retrieving revision 1.32 diff -u -p -r1.25 -r1.32 --- OpenXM/src/kan96xx/plugin/oxmisc.c 2005/07/03 11:08:54 1.25 +++ OpenXM/src/kan96xx/plugin/oxmisc.c 2020/10/06 11:33:47 1.32 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/kan96xx/plugin/oxmisc.c,v 1.24 2005/06/16 05:07:24 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kan96xx/plugin/oxmisc.c,v 1.31 2016/08/29 01:15:01 takayama Exp $ */ #include #include #include @@ -13,6 +13,7 @@ #include #include #include +#include #define SET_MYERROROUT { if (MyErrorOut == NULL) MyErrorOut=stdout; } /* It is also defined in oxmisc2.c */ FILE *MyErrorOut = NULL; @@ -23,7 +24,10 @@ FILE *MyErrorOut = NULL; #include "../Kan/extern.h" #include "ox_kan.h" +#include "mysig.h" +void restoreLockCtrlCForOx(); // defined in Kan/stackmachine.c + #define READBUFSIZE 5000 int OxVersion = 200012030; @@ -175,10 +179,31 @@ int oxWaitSyncBall(ox_stream ostream) { int sss; int mtag; + int com; while ((mtag = oxGetOXheader(ostream,&sss)) != OX_SYNC_BALL) { - fprintf(stderr,"Looking for the next message tag. mtag=%d\n",mtag); + switch (mtag) { + case OX_COMMAND: + fprintf(stderr,"Waiting for command body: "); fflush(NULL); + com=oxGetInt32(ostream); + fprintf(stderr,"%d. Done\n",com); + break; + default: /* Todo, need support OX_DATA */ + fprintf(stderr,"Looking for the next message tag. Current unknown or unimplented mtag=%d\n",mtag); + if (UseOXPacketSerial) fprintf(stderr,"Note that we expect the OX message tag with a serial number.\n"); + if (UseOXPacketSerial && (sss == OX_SYNC_BALL)) { + /* dirty trick, it might cause a trouble. */ + fprintf(stderr,"We assume that the serial number is OX_SYNC_BALL\n"); + oxGetInt32(ostream); // discard the serial of OX_SYNC_BALL + goto aaa ; + } + break; + } + aaa: /* or stdout */ fflush(NULL); + if (mtag == -1) { + fprintf(stderr,"Your peer seems to be dead.\n"); return 0; + } } } @@ -220,7 +245,7 @@ void oxfdSendCmoNull(int fd) { char data[4]; *((int *)&data[0]) = htonl(CMO_NULL); - write(fd,data,4); + {int r; r=write(fd,data,4);} fflush((FILE *)NULL); } void oxSendCmoNull(ox_stream os) @@ -252,7 +277,7 @@ void oxfdSendInt32(int fd,int k) { char data[4]; *((int *)&data[0]) = htonl(k); - write(fd,data,4); + {int r; r=write(fd,data,4);} fflush((FILE *)NULL); } void oxSendInt32(ox_stream os,int k) @@ -268,7 +293,7 @@ void oxfdSendCmoInt32(int fd,int k) char data[4*2]; *((int *)&data[0]) = htonl(CMO_INT32); *((int *)&data[4]) = htonl(k); - write(fd,data,4*2); + {int r; r=write(fd,data,4*2);} fflush((FILE *)NULL); } void oxSendCmoInt32(ox_stream os,int k) @@ -289,9 +314,9 @@ void oxfdSendCmoString(int fd,char *s) } *((int *)&data[0]) = htonl(CMO_STRING); *((int *)&data[4]) = htonl(n); - write(fd,data,4*2); + {int r; r=write(fd,data,4*2);} if (s != NULL) { - write(fd,s,n); + {int r; r=write(fd,s,n);} } fflush((FILE *)NULL); } @@ -327,7 +352,7 @@ void oxSendResultOfControlInt32(int fd,int i) oxfdSendOXheader(fd,OX_DATA,SerialOX++); *((int *)&data[0]) = htonl(CMO_INT32); *((int *)&data[4]) = htonl(i); - write(fd,data,4*2); + {int r; r=write(fd,data,4*2);} fflush((FILE *)NULL); } @@ -336,7 +361,7 @@ void oxSendResultOfControl(int fd) char data[4*1]; oxfdSendOXheader(fd,OX_DATA,SerialOX++); *((int *)&data[0]) = htonl(CMO_NULL); - write(fd,data,4*1); + {int r; r=write(fd,data,4*1);} fflush((FILE *)NULL); } @@ -816,7 +841,7 @@ int oxGetOXheader(ox_stream ostream,int *sss) } -oxWritePortFile(int func,int port,char *fname) { +int oxWritePortFile(int func,int port,char *fname) { char name[1024]; FILE *fp; strcpy(name,fname); @@ -832,7 +857,7 @@ oxWritePortFile(int func,int port,char *fname) { fclose(fp); } } -oxReadPortFile(int func,char *fname) { +int oxReadPortFile(int func,char *fname) { int port = 0; char name[1024]; FILE *fp; @@ -840,12 +865,12 @@ oxReadPortFile(int func,char *fname) { if (func == 0) { strcat(name,".control"); fp = fopen(name,"r"); - fscanf(fp,"%d",&port); + {int r; r=fscanf(fp,"%d",&port);} fclose(fp); }else { strcat(name,".data"); fp = fopen(name,"r"); - fscanf(fp,"%d",&port); + {int r; r=fscanf(fp,"%d",&port);} fclose(fp); } return(port); @@ -899,12 +924,12 @@ char *oxGenPass(void) { char *s; int i,n; if (seed == 0) { - seed = (int) time(NULL) + (int) &p; + seed = (int) time(NULL) + (int) ((long) &p); srandom((unsigned int) seed); } s = (char *)malloc(128*sizeof(char)); if (s == NULL) { fprintf(stderr,"No more memory.\n"); return(s); } - n = (((int) s) + (int) time(NULL)) % 100; + n = (((int)((long) s)) + (int) time(NULL)) % 100; for (i=0; i < n ; i++) random(); p = random(); sprintf(s,"%ld",p); @@ -918,12 +943,12 @@ static void cancelConnection() { #else extern jmp_buf MyEnv_oxmisc; #endif - signal(SIGALRM,SIG_IGN); + mysignal(SIGALRM,SIG_IGN); fprintf(stderr,"Time out in TCP/IP connection.\n"); #if defined(__CYGWIN__) - siglongjmp(MyEnv_oxmisc,1); + MYSIGLONGJMP(MyEnv_oxmisc,1); #else - longjmp(MyEnv_oxmisc,1); + MYLONGJMP(MyEnv_oxmisc,1); #endif } @@ -947,15 +972,15 @@ oxclientp oxCreateClient2(int fdstream,int portStream, v = !Quiet; #if defined(__CYGWIN__) - if (sigsetjmp(MyEnv_oxmisc,1)) { + if (MYSIGSETJMP(MyEnv_oxmisc,1)) { #else - if (setjmp(MyEnv_oxmisc)) { + if (MYSETJMP(MyEnv_oxmisc)) { #endif return(NULL); }else{ } alarm((unsigned int) 20); /* setup timeout. */ - signal(SIGALRM,cancelConnection); + mysignal(SIGALRM,cancelConnection); switch(ipmask) { case 0:/* only local */ @@ -981,7 +1006,7 @@ oxclientp oxCreateClient2(int fdstream,int portStream, if (m > 0) { s = (char *)mymalloc(sizeof(char)*(m+1)); m = strlen(passControl); s[0] = 0; - read(fdControl,s,m+1); s[m] = '\0'; + {int r; r=read(fdControl,s,m+1);} s[m] = '\0'; if (strcmp(s,passControl) != 0) { fprintf(stderr,"s=%s, passControl=%s\n",s,passControl); fprintf(stderr,"oxCreateClient2(): password authentication failed for control channel.\n"); @@ -989,7 +1014,7 @@ oxclientp oxCreateClient2(int fdstream,int portStream, return(NULL); } m = strlen(passData); s[0] = 0; - read(fdStream,s,m+1); s[m] = '\0'; + {int r; r=read(fdStream,s,m+1);} s[m] = '\0'; if (strcmp(s,passData) != 0) { fprintf(stderr,"s=%s, passData=%s\n",s,passData); fprintf(stderr,"oxCreateClient2(): password authentication failed for data channel.\n"); @@ -997,7 +1022,7 @@ oxclientp oxCreateClient2(int fdstream,int portStream, return(NULL); } } - signal(SIGALRM,SIG_IGN); + mysignal(SIGALRM,SIG_IGN); controlByteOrder = oxSetByteOrder(fdControl); if (v) fprintf(stderr,"Byte order for control process is %s.\n", @@ -1033,12 +1058,12 @@ int oxSetByteOrder(int fd) { int peertype; /* It is for client. read and next write. */ /* oxSocketSelect0(fd,10); wait. */ - read(fd,data,1); + {int r; r=read(fd,data,1);} peertype = (unsigned char) data[0]; /* We support only Network byte order */ data[0] = OX_BYTE_NETWORK_BYTE_ORDER; - write(fd,data,1); + {int r; r=write(fd,data,1);} return(OX_BYTE_NETWORK_BYTE_ORDER); } @@ -1050,10 +1075,10 @@ int oxTellMyByteOrder(int fdOut, int fdIn) { /* We support only Network byte order */ data[0] = OX_BYTE_NETWORK_BYTE_ORDER; - write(fdOut,data,1); + {int r; r=write(fdOut,data,1);} fsync(fdOut); /* returns 0 if normal. Does it work for socket? */ - read(fdIn,data,1); /* Read pear's byte order */ + {int r; r=read(fdIn,data,1);} /* Read pear's byte order */ return(OX_BYTE_NETWORK_BYTE_ORDER); }