=================================================================== RCS file: /home/cvs/OpenXM/src/kxx/oxd.c,v retrieving revision 1.2 retrieving revision 1.9 diff -u -p -r1.2 -r1.9 --- OpenXM/src/kxx/oxd.c 2002/10/20 23:38:12 1.2 +++ OpenXM/src/kxx/oxd.c 2016/03/31 05:27:34 1.9 @@ -1,5 +1,5 @@ /* - $OpenXM: OpenXM/src/kxx/oxd.c,v 1.1 2002/10/20 13:13:35 takayama Exp $ + $OpenXM: OpenXM/src/kxx/oxd.c,v 1.8 2004/09/17 03:28:21 takayama Exp $ */ #include @@ -17,6 +17,8 @@ #include "ox_kan.h" #include "serversm.h" +/* #define DEBUG */ + char *getTag(char *s); char *getKeyValue(char *s,char *key); char *getBody(char *s); @@ -31,9 +33,7 @@ int Serial = 0; int LocalMode = 1; static int findOxServer(char *server); static void couldNotFind(char *s); -#if defined(__CYGWIN__) -int errno; -#endif +#define NOBODY 65534 main(int argc, char *argv[]) { char sname[1024]; @@ -43,6 +43,7 @@ main(int argc, char *argv[]) { extern int Serial; int result; int fd; + int uid; strcpy(sname,"localhost"); i = 1; @@ -59,6 +60,14 @@ main(int argc, char *argv[]) { i++; } + uid = getuid(); + if (uid == 0) { + /* If I'm a super user, then change uid to nobody. */ + 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 (portControl != -1) { @@ -124,8 +133,11 @@ childServerMain(int fd) { char ccc[SIZE*3]; extern int Serial; char *openxm; + int resultCode; + int st; + /* Starting oxd session */ - signal(SIGALRM,exitServer); + mysignal(SIGALRM,exitServer); alarm(60); fp = fdopen(fd,"w+"); if (fp == NULL) oxdError("failed fdopen\n"); @@ -178,10 +190,29 @@ childServerMain(int fd) { openxm = getOpenXMpath(); sprintf(ccc,"%s %s",openxm,body); fprintf(stderr,"Serial=%d : Executing command=%s\n",Serial,ccc); + /* Old code. fprintf(fp,"\n"); fflush(NULL); - fclose(fp); /* close the connection */ + fclose(fp); system(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,"\n"); + }else{ + fprintf(fp,"\n",resultCode); + } + + GET_COMMAND /* expect */ + + 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() { @@ -213,4 +244,5 @@ oxdError(char *s) { } +void *sGC_malloc(int n) { return (void *) GC_malloc(n); }