Browse Source

Close unneeded descriptors

git-svn-id: https://klish.googlecode.com/svn/trunk@276 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
04b1b50125
3 changed files with 10 additions and 1 deletions
  1. 5 1
      clish/clish_script_callback.c
  2. 4 0
      clish/shell.h
  3. 1 0
      clish/shell/module.am

+ 5 - 1
clish/clish_script_callback.c

@@ -68,10 +68,14 @@ bool_t clish_script_callback(const clish_shell_t * this,
 	if (cpid == 0) {
 	if (cpid == 0) {
 		FILE *wpipe;
 		FILE *wpipe;
 		int retval;
 		int retval;
+		int so; /* saved stdout */
 		close(pipefd[0]); /* Close unused read end */
 		close(pipefd[0]); /* Close unused read end */
+		so = dup(STDOUT_FILENO);
 		dup2(pipefd[1], STDOUT_FILENO);
 		dup2(pipefd[1], STDOUT_FILENO);
-		wpipe = popen(shebang, "w");
 		close(pipefd[1]); /* Close write end */
 		close(pipefd[1]); /* Close write end */
+		wpipe = popen(shebang, "w");
+		dup2(so, STDOUT_FILENO);
+		close(so);
 		if (!wpipe)
 		if (!wpipe)
 			_exit(-1);
 			_exit(-1);
 		fwrite(script, strlen(script) + 1, 1, wpipe);
 		fwrite(script, strlen(script) + 1, 1, wpipe);

+ 4 - 0
clish/shell.h

@@ -380,6 +380,10 @@ void clish_shell__set_startup_view(clish_shell_t * instance, const char * viewna
 void clish_shell__set_startup_viewid(clish_shell_t * instance, const char * viewid);
 void clish_shell__set_startup_viewid(clish_shell_t * instance, const char * viewid);
 void clish_shell__set_default_shebang(clish_shell_t * instance, const char * shebang);
 void clish_shell__set_default_shebang(clish_shell_t * instance, const char * shebang);
 const char * clish_shell__get_default_shebang(const clish_shell_t * instance);
 const char * clish_shell__get_default_shebang(const clish_shell_t * instance);
+char * clish_shell__expand_text(const clish_shell_t *instance,
+	clish_command_t *cmd, clish_pargv_t *pargv, const char *text);
+char * clish_shell__expand_variable(const clish_shell_t *instance,
+	clish_command_t *cmd, clish_pargv_t *pargv, const char *var);
 
 
 _END_C_DECL
 _END_C_DECL
 
 

+ 1 - 0
clish/shell/module.am

@@ -27,4 +27,5 @@ libclish_la_SOURCES +=	\
             clish/shell/shell_pwd.c                 \
             clish/shell/shell_pwd.c                 \
             clish/shell/shell_tinyrl.c              \
             clish/shell/shell_tinyrl.c              \
             clish/shell/shell_tinyxml_read.cpp      \
             clish/shell/shell_tinyxml_read.cpp      \
+            clish/shell/shell_expand.c              \
             clish/shell/private.h
             clish/shell/private.h