Bladeren bron

Don't hang up if shebang is not exists. Fix issue #86

git-svn-id: https://klish.googlecode.com/svn/trunk@528 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 12 jaren geleden
bovenliggende
commit
47b6e6b6d9
1 gewijzigde bestanden met toevoegingen van 12 en 4 verwijderingen
  1. 12 4
      clish/callback_script.c

+ 12 - 4
clish/callback_script.c

@@ -26,7 +26,7 @@ int clish_script_callback(clish_context_t *context,
 	clish_shell_t *this = context->shell;
 	const clish_command_t *cmd = context->cmd;
 	const char * shebang = NULL;
-	pid_t cpid;
+	pid_t cpid = -1;
 	int res;
 	const char *fifo_name;
 	FILE *rpipe, *wpipe;
@@ -114,9 +114,10 @@ int clish_script_callback(clish_context_t *context,
 			fprintf(stderr, "System error. Can't fork the script.\n"
 				"The ACTION will be not executed.\n");
 			lub_string_free(command);
-			kill(cpid, SIGTERM);
-			if (!is_sh)
+			if (!is_sh) {
+				kill(cpid, SIGTERM);
 				waitpid(cpid, NULL, 0);
+			}
 
 			/* Restore SIGINT and SIGQUIT */
 			sigaction(SIGINT, &sig_old_int, NULL);
@@ -130,8 +131,10 @@ int clish_script_callback(clish_context_t *context,
 		*out = konf_buf__dup_line(buf);
 		konf_buf_delete(buf);
 		/* Wait for the writing process */
-		if (!is_sh)
+		if (!is_sh) {
+			kill(cpid, SIGTERM);
 			waitpid(cpid, NULL, 0);
+		}
 		/* Wait for script */
 		res = pclose(rpipe);
 
@@ -140,6 +143,11 @@ int clish_script_callback(clish_context_t *context,
 		sigaction(SIGQUIT, &sig_old_quit, NULL);
 	} else {
 		res = system(command);
+		/* Wait for the writing process */
+		if (!is_sh) {
+			kill(cpid, SIGTERM);
+			waitpid(cpid, NULL, 0);
+		}
 	}
 	lub_string_free(command);