Annotation of OpenXM/src/kxx/ox100start.c, Revision 1.4
1.4 ! takayama 1: /* $OpenXM: OpenXM/src/kxx/ox100start.c,v 1.3 2003/07/21 12:41:21 takayama Exp $ */
1.1 takayama 2: /* Moved from misc-2003/07/cygwin/test.c */
3: #include <stdio.h>
4: #include <sys/types.h>
5: #include <sys/stat.h>
6: #include <fcntl.h>
7: #include <stdlib.h>
8: #include <unistd.h>
9: #include <sys/wait.h>
10: #include <signal.h>
11: #include <ctype.h>
1.2 takayama 12: #include "ox_pathfinder.h"
1.1 takayama 13:
1.2 takayama 14: static void usage(void);
1.1 takayama 15: static int forkExec(char **argv);
1.3 takayama 16: void *sGC_malloc(int size) {
17: return ((void *)malloc(size));
18: }
1.1 takayama 19:
1.2 takayama 20: extern char **environ;
1.1 takayama 21:
22: main(int argc,char *argv[]) {
23: char *s;
24: char s2[1024];
25: char buf[1024];
26: FILE *fp;
27: char **aaa;
28: char **eee;
29: int i;
30: char *serverName;
31:
1.4 ! takayama 32:
1.2 takayama 33: /*
1.1 takayama 34: printf("ostype=%s\n",getOStypes());
35: printf("OpenXM_HOME=%s\n",getOpenXM_HOME());
36: printf("sm lib =%s\n",get_sm1_lib_path());
37: printf("k0 lib =%s\n",get_k0_lib_path());
38: printf("ox_asir =%s\n",get_ox_asir_path());
1.2 takayama 39: */
1.4 ! takayama 40: ox_pathfinderVerbose(1);
! 41:
1.1 takayama 42:
43: /* Initialize parameters */
44: serverName = NULL;
45: aaa = NULL;
46:
47: for (i=1 ; i<argc; i++) {
48: if (strcmp(argv[i],"-e")==0) {
49: if (aaa == NULL) {
50: fprintf(stderr,"Server is not found or not specified by -oxserver options.\n");
51: exit(1);
52: }
53: aaa = catArgv(aaa,&(argv[i+1]));
54: break;
55: }else if (strcmp(argv[i],"-oxserver")==0) {
56: i++;
57: serverName = argv[i];
58: aaa = getServerEnv(serverName);
59: }else if (strcmp(argv[i],"-nox")==0) {
1.2 takayama 60: ox_pathfinderNoX(1);
1.1 takayama 61: }else{
62: fprintf(stderr,"Unknown option.\n");
63: usage();
64: exit(10);
65: }
66: }
67:
68: forkExec(aaa);
1.2 takayama 69: }
1.1 takayama 70:
1.2 takayama 71: #define MYFORKCP_SIZE 100
72: static int Myforkchildren[MYFORKCP_SIZE];
73: static int Myforkcp=0;
74: static void myforkwait() {
75: int status;
76: int pid;
77: int i,j;
78: signal(SIGCHLD,SIG_IGN);
79: pid = wait(&status);
80: fprintf(stderr,"Child process %d is exiting.\n",pid);
81: for (i=0; i<Myforkcp; i++) {
82: if (Myforkchildren[i] == pid) {
83: for (j=i; j<Myforkcp-1; j++) {
84: Myforkchildren[j] = Myforkchildren[j+1];
85: }
86: if (Myforkcp > 0) Myforkcp--;
87: }
88: }
89: signal(SIGCHLD,myforkwait);
1.1 takayama 90: }
91:
92: static void usage() {
93: fprintf(stderr,"oxstart100 -oxserver xxx [-e args]\n");
94: fprintf(stderr,"Examples: \n");
95: fprintf(stderr," oxstart100 -oxserver bin/ox_sm1 -e -reverse -data 3010 --control 3012 -pass 1121343432434 \n");
96: }
97:
98: static int forkExec(char **argv) {
99: int pid;
100: char **eee;
101: int m;
102: m = 0;
103: if (argv == NULL) {
104: fprintf(stderr,"Cannot fork and exec.\n"); return -1;
105: }
106: if ((pid = fork()) > 0) {
107: if (m&2) {
108: /* Do not call singal to turn around a trouble on cygwin. BUG. */
109: }else{
110: signal(SIGCHLD,myforkwait); /* to kill Zombie */
111: }
112: Myforkchildren[Myforkcp++] = pid;
113: if (Myforkcp >= MYFORKCP_SIZE-1) {
114: fprintf(stderr,"Child process table is full.\n");
115: Myforkcp = 0;
116: }
117: }else{
118: /* close the specified files */
119: if (m&1) {
120: sigset_t sss;
121: sigemptyset(&sss);
122: sigaddset(&sss,SIGINT);
123: sigprocmask(SIG_BLOCK,&sss,NULL);
124: }
1.2 takayama 125: if (ox_pathfinderNoX(-1)) {
1.1 takayama 126: FILE *null;
127: null = fopen("/dev/null","wb");
128: dup2(fileno(null),1);
129: dup2(fileno(null),2);
130: }
131: execve(argv[0],argv,environ);
132: /* This place will never be reached unless execv fails. */
133: fprintf(stderr,"forkExec fails: ");
134: }
135: }
136:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>