added EXEC_DEFAULT compile option for srfsh which is set by default.
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 20 Jul 2005 16:19:08 +0000 (16:19 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 20 Jul 2005 16:19:08 +0000 (16:19 +0000)
when set, srfsh will send all misunderstood commands to a subshell for
execution

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@408 9efc2488-bf62-4759-914b-345cdb29e865

src/srfsh/Makefile
src/srfsh/srfsh.c
src/srfsh/srfsh.h

index 8699397..58fb93e 100644 (file)
@@ -1,4 +1,6 @@
-LD_OPTS        += -lobjson -lreadline -lxml2 -lopensrf_transport -lopensrf_stack -lncurses -lc_utils
+# if EXEC_DEFAULT is defined, then srfsh will send all unknown commands to the shell for execution
+
+LD_OPTS        += -lobjson -lreadline -lxml2 -lopensrf_transport -lopensrf_stack -lncurses -lc_utils -DEXEC_DEFAULT
 
 all: srfsh
 
index 492b9d7..1d3b87d 100644 (file)
@@ -105,6 +105,7 @@ int parse_error( char* words[] ) {
        if( ! words )
                return 0;
 
+
        int i = 0;
        char* current;
        char buffer[256];
@@ -181,8 +182,13 @@ int parse_request( char* request ) {
        else if (words[0][0] == '!')
                ret_val = handle_exec( words );
 
-       if(!ret_val)
-               return parse_error( words );
+       if(!ret_val) {
+               #ifdef EXEC_DEFAULT
+                       return handle_exec( words );
+               #else
+                       return parse_error( words );
+               #endif
+       }
 
        return 1;
 
@@ -370,27 +376,32 @@ int handle_router( char* words[] ) {
 
 int handle_exec(char* words[]) {
 
-       int len = strlen(words[0]);
-       char command[len];
-       memset(command,0,len);
+       if(!words[0]) return 0;
 
-       int i; /* chop out the ! */
-       for( i=1; i!= len; i++) {
-               command[i-1] = words[0][i];
+       if( words[0] && words[0][0] == '!') {
+               int len = strlen(words[0]);
+               char command[len];
+               memset(command,0,len);
+       
+               int i; /* chop out the ! */
+               for( i=1; i!= len; i++) {
+                       command[i-1] = words[0][i];
+               }
+       
+               free(words[0]);
+               words[0] = strdup(command);
        }
 
-       free(words[0]);
-       words[0] = strdup(command);
        signal(SIGCHLD,sig_child_handler);
+
        if(fork()) {
-               while(1) {
-                       sleep(100);
-                       if(child_dead) {
-                               signal(SIGCHLD,sig_child_handler);
-                               child_dead = 0;
-                               break;
-                       }
+
+               waitpid(-1, 0, 0);
+               if(child_dead) {
+                       signal(SIGCHLD,sig_child_handler);
+                       child_dead = 0;
                }
+
        } else {
                execvp( words[0], words );
                exit(0);
index ef403d2..38bf3e7 100644 (file)
@@ -4,6 +4,8 @@
 #include "opensrf/osrf_config.h"
 #include <time.h>
 #include <sys/timeb.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
 #include "md5.h"
 #include "utils.h"
@@ -33,6 +35,7 @@ char* login_session = NULL;
 
 /* true if we're pretty printing json results */
 int pretty_print = 1;
+int raw_print = 0;
 
 /* our jabber connection */
 transport_client* client = NULL;