From: erickson Date: Wed, 20 Jul 2005 16:19:08 +0000 (+0000) Subject: added EXEC_DEFAULT compile option for srfsh which is set by default. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=8aa33c9f7537ec78dd600be4091b5e709c2955f3;p=opensrf%2Fbjwebb.git added EXEC_DEFAULT compile option for srfsh which is set by default. 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 --- diff --git a/src/srfsh/Makefile b/src/srfsh/Makefile index 8699397..58fb93e 100644 --- a/src/srfsh/Makefile +++ b/src/srfsh/Makefile @@ -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 diff --git a/src/srfsh/srfsh.c b/src/srfsh/srfsh.c index 492b9d7..1d3b87d 100644 --- a/src/srfsh/srfsh.c +++ b/src/srfsh/srfsh.c @@ -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); diff --git a/src/srfsh/srfsh.h b/src/srfsh/srfsh.h index ef403d2..38bf3e7 100644 --- a/src/srfsh/srfsh.h +++ b/src/srfsh/srfsh.h @@ -4,6 +4,8 @@ #include "opensrf/osrf_config.h" #include #include +#include +#include #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;