[BACK]Return to oxd.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kxx

Diff for /OpenXM/src/kxx/oxd.c between version 1.1 and 1.9

version 1.1, 2002/10/20 13:13:35 version 1.9, 2016/03/31 05:27:34
Line 1 
Line 1 
 /*  /*
  $OpenXM$   $OpenXM: OpenXM/src/kxx/oxd.c,v 1.8 2004/09/17 03:28:21 takayama Exp $
 */  */
   
 #include <stdio.h>  #include <stdio.h>
Line 17 
Line 17 
 #include "ox_kan.h"  #include "ox_kan.h"
 #include "serversm.h"  #include "serversm.h"
   
   /* #define DEBUG */
   
 char *getTag(char *s);  char *getTag(char *s);
 char *getKeyValue(char *s,char *key);  char *getKeyValue(char *s,char *key);
 char *getBody(char *s);  char *getBody(char *s);
   char *getOpenXMpath(void);
   void *xtagMalloc(int n);
   
 int MyServerPid;  int MyServerPid;
 #define SERVERNAME_SIZE 4096  #define SERVERNAME_SIZE 4096
Line 29  int Serial = 0;
Line 33  int Serial = 0;
 int LocalMode = 1;  int LocalMode = 1;
 static int findOxServer(char *server);  static int findOxServer(char *server);
 static void couldNotFind(char *s);  static void couldNotFind(char *s);
 #if defined(__CYGWIN__)  #define NOBODY 65534
 int errno;  
 #endif  
   
 main(int argc, char *argv[]) {  main(int argc, char *argv[]) {
   char sname[1024];    char sname[1024];
Line 39  main(int argc, char *argv[]) {
Line 41  main(int argc, char *argv[]) {
   int fdControl = -1; int portControl = 8089;    int fdControl = -1; int portControl = 8089;
   extern int OpenedSocket;    extern int OpenedSocket;
   extern int Serial;    extern int Serial;
   int sleepingTime = 0;  
   int result;    int result;
   int fd;    int fd;
     int uid;
   
   strcpy(sname,"localhost");    strcpy(sname,"localhost");
   i = 1;    i = 1;
   while (i<argc) {    while (i<argc) {
     if (strcmp(argv[i],"--control")==0) {      if (strcmp(argv[i],"--port")==0) {
       i++;        i++;
       if (i<argc) sscanf(argv[i],"%d",&portControl);        if (i<argc) sscanf(argv[i],"%d",&portControl);
     }else if (strcmp(argv[i],"--insecure") == 0) {      }else if (strcmp(argv[i],"--insecure") == 0) {
       LocalMode = 0;        LocalMode = 0;
     }else if (strcmp(argv[i],"--wait") == 0) {  
       i++;  
       if (i<argc) {  
         sscanf(argv[i],"%d",&sleepingTime);  
       }  
     }else {      }else {
       fprintf(stderr,"Unknown option %s.\n",argv[i]);        fprintf(stderr,"Unknown option %s.\n",argv[i]);
       oxdUsage(); exit(10);        oxdUsage(); exit(10);
Line 63  main(int argc, char *argv[]) {
Line 60  main(int argc, char *argv[]) {
     i++;      i++;
   }    }
   
   if (sleepingTime) {    uid = getuid();
     fprintf(stderr,"Waiting to connect for %d seconds...\n",sleepingTime);    if (uid == 0) {
     sleep(sleepingTime);          /* If I'm a super user, then change uid to nobody. */
     fprintf(stderr,"\nTrying to connect\n");          if (setuid(NOBODY) != 0) {
             oxdError("Failed to change uid to nobody (%d)\n",NOBODY);
           }
           fprintf(stderr,"uid is changed to nobody (%d).\n",NOBODY);
   }    }
   
   
   if (LocalMode) {    if (LocalMode) {
     if (portControl != -1) {      if (portControl != -1) {
       fdControl = socketOpen(sname,portControl);        fdControl = socketOpen(sname,portControl);
           if (fdControl < 0) oxdError("Could not open a socket.");            if (fdControl < 0) oxdError("Could not open a socket. \n\nPerhaps, oxd is already running on your machine.\nTo start oxd on a different port xyz, start oxd by oxd --port xyz");
       portControl = OpenedSocket;        portControl = OpenedSocket;
           while (1) {            while (1) {
                 /* fdControl : fd for the wait queue */                  /* fdControl : fd for the wait queue */
Line 102  main(int argc, char *argv[]) {
Line 101  main(int argc, char *argv[]) {
   
 oxdUsage() {  oxdUsage() {
   fprintf(stderr,"Usage: \n");    fprintf(stderr,"Usage: \n");
   fprintf(stderr,"  oxd \n");    fprintf(stderr,"  oxd [--port xyz]\n");
   fprintf(stderr,"\n");    fprintf(stderr,"\n");
 }  }
   
Line 132  childServerMain(int fd) {
Line 131  childServerMain(int fd) {
   char fname[SIZE*2];    char fname[SIZE*2];
   char fnameBody[SIZE];    char fnameBody[SIZE];
   char ccc[SIZE*3];    char ccc[SIZE*3];
     extern int Serial;
     char *openxm;
     int resultCode;
     int st;
   
   /* Starting oxd session */    /* Starting oxd session */
   signal(SIGALRM,exitServer);    mysignal(SIGALRM,exitServer);
   alarm(60);    alarm(60);
   fp = fdopen(fd,"w+");    fp = fdopen(fd,"w+");
   if (fp == NULL) oxdError("failed fdopen\n");    if (fp == NULL) oxdError("failed fdopen\n");
Line 183  childServerMain(int fd) {
Line 187  childServerMain(int fd) {
   
   body = getBody(comm);    body = getBody(comm);
   if (strlen(body) > SIZE*2) exitServer2(fp,"too big body.");    if (strlen(body) > SIZE*2) exitServer2(fp,"too big body.");
   sprintf(ccc,"/usr/local/bin/openxm %s",body);    openxm = getOpenXMpath();
   fprintf(stderr,"Serial=%d : Executing command=%s\n",ccc);    sprintf(ccc,"%s %s",openxm,body);
     fprintf(stderr,"Serial=%d : Executing command=%s\n",Serial,ccc);
     /*  Old code.
   fprintf(fp,"<bye/>\n"); fflush(NULL);    fprintf(fp,"<bye/>\n"); fflush(NULL);
   fclose(fp); /* close the connection */    fclose(fp);
   system(ccc);    system(ccc);
   fprintf(stderr,"Serial=%d : The following command is finished : %s\n",ccc);    fprintf(stderr,"Serial=%d : The following command is finished : %s\n",Serial,ccc);
      */
     /* New code. It requires  ox with -finish option. */
     resultCode = system(ccc);
     fprintf(stderr,"Serial=%d : The following command is finished : %s, resultCode=%d\n",Serial,ccc,resultCode);
     if (resultCode == 0) {
           fprintf(fp,"<suceeded/>\n");
     }else{
           fprintf(fp,"<failed code=\"%d\"/>\n",resultCode);
     }
   
     GET_COMMAND   /* expect <login/> */
   
     fclose(fp); /* close the connection */
     fprintf(stderr,"Waiting the termination of the child process (ox server).\n");
     fflush(NULL);
     wait(&st);
     fprintf(stderr,"%d: The child process is terminated.\n",Serial);
     exit(0);
 }  }
   
   char *getOpenXMpath() {
     char *s;
     char *sss;
     s = getenv("OpenXM_HOME");
     if (s == NULL) {
           s = getenv("OPENXM_HOME");
     }
     if (s == NULL) sss="/usr/local/bin/openxm";
     else {
           sss = (char *) xtagMalloc(strlen(s)+20);
           sprintf(sss,"%s/bin/openxm",s);
     }
     if (access(sss,X_OK&R_OK) == 0) {
     }else{
           oxdError("The shell script openxm does not exists. It is usually generated under OpenXM/rc");
     }
     return sss;
   }
   
 /* These are dummy.  It is defined in stackmachine.c */  /* These are dummy.  It is defined in stackmachine.c */
 unlockCtrlCForOx() { ; }  unlockCtrlCForOx() { ; }
Line 202  oxdError(char *s) {
Line 244  oxdError(char *s) {
 }  }
   
   
   void *sGC_malloc(int n) { return (void *) GC_malloc(n); }
   

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.9

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>