Browse Source

Don't use /bin/sh -c for ACTIONs

Conflicts:
	plugins/clish/sym_script.c
Serj Kalichev 9 years ago
parent
commit
445250107f
1 changed files with 31 additions and 47 deletions
  1. 31 47
      plugins/clish/sym_script.c

+ 31 - 47
plugins/clish/sym_script.c

@@ -31,7 +31,6 @@ CLISH_PLUGIN_SYM(clish_script)
 	const char *fifo_name;
 	FILE *rpipe, *wpipe;
 	char *command = NULL;
-	bool_t is_sh = BOOL_FALSE;
 
 	/* Signal vars */
 	struct sigaction sig_old_int;
@@ -49,52 +48,43 @@ CLISH_PLUGIN_SYM(clish_script)
 	if (!shebang)
 		shebang = clish_shell__get_default_shebang(this);
 	assert(shebang);
-	if (0 == lub_string_nocasecmp(shebang, "/bin/sh"))
-		is_sh = BOOL_TRUE;
 
 #ifdef DEBUG
 	fprintf(stderr, "SHEBANG: #!%s\n", shebang);
 	fprintf(stderr, "SCRIPT: %s\n", script);
 #endif /* DEBUG */
 
-	/* If /bin/sh we don't need FIFO */
-	if (!is_sh) {
-		/* Get FIFO */
-		fifo_name = clish_shell__get_fifo(this);
-		if (!fifo_name) {
-			fprintf(stderr, "Error: Can't create temporary FIFO.\n"
-				"Error: The ACTION will be not executed.\n");
-			return -1;
-		}
+	/* Get FIFO */
+	fifo_name = clish_shell__get_fifo(this);
+	if (!fifo_name) {
+		fprintf(stderr, "Error: Can't create temporary FIFO.\n"
+			"Error: The ACTION will be not executed.\n");
+		return -1;
+	}
 
-		/* Create process to write to FIFO */
-		cpid = fork();
-		if (cpid == -1) {
-			fprintf(stderr, "Error: Can't fork the write process.\n"
-				"Error: The ACTION will be not executed.\n");
-			return -1;
-		}
+	/* Create process to write to FIFO */
+	cpid = fork();
+	if (cpid == -1) {
+		fprintf(stderr, "Error: Can't fork the write process.\n"
+			"Error: The ACTION will be not executed.\n");
+		return -1;
+	}
 
-		/* Child: write to FIFO */
-		if (cpid == 0) {
-			wpipe = fopen(fifo_name, "w");
-			if (!wpipe)
-				_exit(-1);
-			fwrite(script, strlen(script) + 1, 1, wpipe);
-			fclose(wpipe);
-			_exit(0);
-		}
+	/* Child: write to FIFO */
+	if (cpid == 0) {
+		wpipe = fopen(fifo_name, "w");
+		if (!wpipe)
+			_exit(-1);
+		fwrite(script, strlen(script) + 1, 1, wpipe);
+		fclose(wpipe);
+		_exit(0);
 	}
 
 	/* Parent */
 	/* Prepare command */
-	if (!is_sh) {
-		lub_string_cat(&command, shebang);
-		lub_string_cat(&command, " ");
-		lub_string_cat(&command, fifo_name);
-	} else {
-		lub_string_cat(&command, script);
-	}
+	lub_string_cat(&command, shebang);
+	lub_string_cat(&command, " ");
+	lub_string_cat(&command, fifo_name);
 
 	/* If the stdout of script is needed */
 	if (out) {
@@ -114,10 +104,8 @@ CLISH_PLUGIN_SYM(clish_script)
 			fprintf(stderr, "Error: Can't fork the script.\n"
 				"Error: The ACTION will be not executed.\n");
 			lub_string_free(command);
-			if (!is_sh) {
-				kill(cpid, SIGTERM);
-				waitpid(cpid, NULL, 0);
-			}
+			kill(cpid, SIGTERM);
+			waitpid(cpid, NULL, 0);
 
 			/* Restore SIGINT and SIGQUIT */
 			sigaction(SIGINT, &sig_old_int, NULL);
@@ -131,10 +119,8 @@ CLISH_PLUGIN_SYM(clish_script)
 		*out = konf_buf__dup_line(buf);
 		konf_buf_delete(buf);
 		/* Wait for the writing process */
-		if (!is_sh) {
-			kill(cpid, SIGTERM);
-			waitpid(cpid, NULL, 0);
-		}
+		kill(cpid, SIGTERM);
+		waitpid(cpid, NULL, 0);
 		/* Wait for script */
 		res = pclose(rpipe);
 
@@ -144,10 +130,8 @@ CLISH_PLUGIN_SYM(clish_script)
 	} else {
 		res = system(command);
 		/* Wait for the writing process */
-		if (!is_sh) {
-			kill(cpid, SIGTERM);
-			waitpid(cpid, NULL, 0);
-		}
+		kill(cpid, SIGTERM);
+		waitpid(cpid, NULL, 0);
 	}
 	lub_string_free(command);