version 1.21, 2005/02/28 12:53:44 |
version 1.26, 2016/03/30 09:20:40 |
|
|
/* $OpenXM: OpenXM/src/kxx/oxmain.c,v 1.20 2004/09/17 12:32:11 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kxx/oxmain.c,v 1.25 2006/06/05 04:40:15 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 */ |
/* nullserver01 */ |
#include <stdio.h> |
#include <stdio.h> |
#include <fcntl.h> |
#include <fcntl.h> |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <sys/socket.h> |
#include <sys/time.h> |
#include <sys/time.h> |
|
#include <sys/resource.h> |
#include <netinet/in.h> |
#include <netinet/in.h> |
#include <netdb.h> |
#include <netdb.h> |
#include <signal.h> |
#include <signal.h> |
|
|
int LocalMode = 1; |
int LocalMode = 1; |
int NotifyPortnumber = 0; |
int NotifyPortnumber = 0; |
int Do_not_use_control_stream_to_tell_no_server = 1; |
int Do_not_use_control_stream_to_tell_no_server = 1; |
|
int IgnoreSIGINT = 1; |
static void errorToStartEngine(void); |
static void errorToStartEngine(void); |
static int findOxServer(char *server); |
static int findOxServer(char *server); |
static void couldNotFind(char *s); |
static void couldNotFind(char *s); |
/* gcc -v -c hoge.c */ |
/* gcc -v -c hoge.c */ |
static void mywait(); |
static void mywait(int m); |
|
|
void *sGC_malloc(int n) { |
void *sGC_malloc(int n) { |
return (void *)malloc(n); |
return (void *)malloc(n); |
Line 60 main(int argc, char *argv[]) { |
|
Line 70 main(int argc, char *argv[]) { |
|
char *passData = NULL; |
char *passData = NULL; |
int result; |
int result; |
int sleepingTime = 0; |
int sleepingTime = 0; |
|
int authEncoding=0; |
|
FILE *fp; |
|
char *stmp; |
extern int OxTerminateMode; |
extern int OxTerminateMode; |
|
|
signal(SIGHUP,SIG_IGN); /* ignore x of xterm */ |
int sighup[]={SIGHUP,-1}; |
|
block_signal(sighup); /* ignore x of xterm */ |
strcpy(sname,"localhost"); |
strcpy(sname,"localhost"); |
strcpy(ServerName,SERVERNAME); |
strcpy(ServerName,SERVERNAME); |
i = 1; |
i = 1; |
Line 119 main(int argc, char *argv[]) { |
|
Line 133 main(int argc, char *argv[]) { |
|
if (i<argc) { |
if (i<argc) { |
sscanf(argv[i],"%d",&sleepingTime); |
sscanf(argv[i],"%d",&sleepingTime); |
} |
} |
|
}else if (strcmp(argv[i],"-authEncoding") == 0) { |
|
i++; |
|
if (strcmp(argv[i],"file") == 0) { |
|
authEncoding = 1; |
|
}else{ |
|
fprintf(stderr,"Unknown -authEncoding %s.\n",argv[i]); |
|
oxmainUsage(); exit(10); |
|
} |
|
}else if (strcmp(argv[i],"-ignoreSIGINT") == 0) { |
|
i++; |
|
if (i<argc) { |
|
sscanf(argv[i],"%d",&IgnoreSIGINT); |
|
} |
}else { |
}else { |
fprintf(stderr,"Unknown option %s.\n",argv[i]); |
fprintf(stderr,"Unknown option %s.\n",argv[i]); |
oxmainUsage(); exit(10); |
oxmainUsage(); exit(10); |
Line 148 main(int argc, char *argv[]) { |
|
Line 175 main(int argc, char *argv[]) { |
|
} |
} |
|
|
/* Decrypt passControl and passData, here. Lookup cryptmethod. */ |
/* Decrypt passControl and passData, here. Lookup cryptmethod. */ |
|
if (authEncoding == 1) { |
|
stmp = (char *)sGC_malloc(strlen(getenv("HOME"))+strlen(passControl)+ |
|
strlen(passData)+128); |
|
sprintf(stmp,"%s/.openxm/tmp.opt/%s",(char *)getenv("HOME"),passControl); |
|
fp = fopen(stmp,"r"); |
|
if (fp == NULL) { fprintf(stderr,"passControl file %s is not found.\n",stmp); exit(1);} |
|
fgets(stmp,127,fp); passControl = stmp; fclose(fp); |
|
|
|
stmp = (char *)sGC_malloc(strlen(getenv("HOME"))+strlen(passControl)+ |
|
strlen(passData)+128); |
|
sprintf(stmp,"%s/.openxm/tmp.opt/%s",(char *)getenv("HOME"),passData); |
|
fp = fopen(stmp,"r"); |
|
if (fp == NULL) { fprintf(stderr,"passData file %s is not found.\n",stmp); exit(1);} |
|
fgets(stmp,127,fp); passData = stmp; fclose(fp); |
|
} |
|
|
if (reverse) { |
if (reverse) { |
/* The order is very important. */ |
/* The order is very important. */ |
fdControl = socketConnectWithPass(sname,portControl,passControl); |
fdControl = socketConnectWithPass(sname,portControl,passControl); |
|
|
fprintf(stderr,"Usage: \n"); |
fprintf(stderr,"Usage: \n"); |
fprintf(stderr," ox [-ox serverprogram -host name -data portnum -control portnum -monitor]\n"); |
fprintf(stderr," ox [-ox serverprogram -host name -data portnum -control portnum -monitor]\n"); |
fprintf(stderr," [-insecure -portfile fname -reverse -passControl xxxyyyzzz -passData pppqqqrrr]"); |
fprintf(stderr," [-insecure -portfile fname -reverse -passControl xxxyyyzzz -passData pppqqqrrr]"); |
fprintf(stderr," [-finish]"); |
fprintf(stderr," [-finish] [-wait seconds] [-authEncoding [file]]"); |
|
fprintf(stderr," [-ignoreSIGINT [1|0]]"); |
fprintf(stderr,"\n"); |
fprintf(stderr,"\n"); |
fprintf(stderr,"-reverse: ox server connects to the client.\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"); |
Line 325 parentServerMain(int fdControl, int fdStream) { |
|
Line 368 parentServerMain(int fdControl, int fdStream) { |
|
int message = 1; |
int message = 1; |
int controlByteOrder; |
int controlByteOrder; |
extern OxTerminateMode; |
extern OxTerminateMode; |
extern void myServerExit(); |
extern void myServerExit(int m); |
|
|
signal(SIGCHLD,mywait); |
int sigchld[]={SIGCHLD,-1}; |
|
unblock_signal(sigchld); |
if (OxTerminateMode) { |
if (OxTerminateMode) { |
/* |
/* |
OxTerminateMode cannot be used if you run ox by xterm -exec ox ... |
OxTerminateMode cannot be used if you run ox by xterm -exec ox ... |
Line 343 parentServerMain(int fdControl, int fdStream) { |
|
Line 387 parentServerMain(int fdControl, int fdStream) { |
|
/* Set the network byte order. */ |
/* Set the network byte order. */ |
fprintf(stderr,"controlByteOrder=%x\n",controlByteOrder); |
fprintf(stderr,"controlByteOrder=%x\n",controlByteOrder); |
|
|
|
int sigint[]={SIGINT,-1}; |
signal(SIGINT,myServerExit); |
set_signal(sigint,myServerExit); |
|
unblock_signal(sigint); |
while(1) { |
while(1) { |
mtag = oxfdGetOXheader(fdControl,&SerialCurrentControl); |
mtag = oxfdGetOXheader(fdControl,&SerialCurrentControl); |
/* get the message_tag */ |
/* get the message_tag */ |
Line 356 parentServerMain(int fdControl, int fdStream) { |
|
Line 401 parentServerMain(int fdControl, int fdStream) { |
|
if (message) printf("[control] control_kill\n"); |
if (message) printf("[control] control_kill\n"); |
oxSendResultOfControl(fdControl); |
oxSendResultOfControl(fdControl); |
sleep(2); |
sleep(2); |
myServerExit(); |
myServerExit(0); |
break; |
break; |
case SM_control_reset_connection: |
case SM_control_reset_connection: |
if (message) printf("[control] control_reset_connection.\n"); |
if (message) printf("[control] control_reset_connection.\n"); |
Line 369 parentServerMain(int fdControl, int fdStream) { |
|
Line 414 parentServerMain(int fdControl, int fdStream) { |
|
default: |
default: |
fprintf(stderr,"[control] Unknown control message.\n"); |
fprintf(stderr,"[control] Unknown control message.\n"); |
fprintf(stderr,"Shutdown the server."); |
fprintf(stderr,"Shutdown the server."); |
myServerExit(); |
myServerExit(0); |
break; |
break; |
} |
} |
} |
} |
} |
} |
|
|
void myServerExit() { |
void myServerExit(int m) { |
printf("Sending the kill signal to the child.\n"); |
printf("Sending the kill signal to the child.\n"); |
kill(MyServerPid,SIGKILL); |
kill(MyServerPid,SIGKILL); |
exit(0); |
exit(0); |
Line 383 void myServerExit() { |
|
Line 428 void myServerExit() { |
|
|
|
childServerMain(int fdControl, int fdStream) { |
childServerMain(int fdControl, int fdStream) { |
int i; |
int i; |
|
struct rlimit res; |
close(fdControl); /* close(0); dup(fdStream); */ |
close(fdControl); /* close(0); dup(fdStream); */ |
dup2(fdStream,3); |
dup2(fdStream,3); |
dup2(fdStream,4); |
dup2(fdStream,4); |
Line 422 childServerMain(int fdControl, int fdStream) { |
|
Line 468 childServerMain(int fdControl, int fdStream) { |
|
putenv(s); |
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 (PacketMonitor) { |
if (execle(ServerName,ServerName,"-monitor",NULL,environ)) { |
if (execle(ServerName,ServerName,"-monitor",NULL,environ)) { |
fprintf(stderr,"%s cannot be executed with -monitor.\n",ServerName); |
fprintf(stderr,"%s cannot be executed with -monitor.\n",ServerName); |
Line 484 static void couldNotFind(char *s) { |
|
Line 539 static void couldNotFind(char *s) { |
|
} |
} |
|
|
|
|
static void mywait() { |
static void mywait(int m) { |
int status; |
int status; |
int pid; |
int pid; |
int i,j; |
int i,j; |