|
@@ -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;
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
-
|
|
|
- if (!is_sh) {
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- if (cpid == 0) {
|
|
|
- wpipe = fopen(fifo_name, "w");
|
|
|
- if (!wpipe)
|
|
|
- _exit(-1);
|
|
|
- fwrite(script, strlen(script) + 1, 1, wpipe);
|
|
|
- fclose(wpipe);
|
|
|
- _exit(0);
|
|
|
- }
|
|
|
+
|
|
|
+ if (cpid == 0) {
|
|
|
+ wpipe = fopen(fifo_name, "w");
|
|
|
+ if (!wpipe)
|
|
|
+ _exit(-1);
|
|
|
+ fwrite(script, strlen(script) + 1, 1, wpipe);
|
|
|
+ fclose(wpipe);
|
|
|
+ _exit(0);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- 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 (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);
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
- if (!is_sh) {
|
|
|
- kill(cpid, SIGTERM);
|
|
|
- waitpid(cpid, NULL, 0);
|
|
|
- }
|
|
|
+ kill(cpid, SIGTERM);
|
|
|
+ waitpid(cpid, NULL, 0);
|
|
|
|
|
|
res = pclose(rpipe);
|
|
|
|
|
@@ -144,10 +130,8 @@ CLISH_PLUGIN_SYM(clish_script)
|
|
|
} else {
|
|
|
res = system(command);
|
|
|
|
|
|
- if (!is_sh) {
|
|
|
- kill(cpid, SIGTERM);
|
|
|
- waitpid(cpid, NULL, 0);
|
|
|
- }
|
|
|
+ kill(cpid, SIGTERM);
|
|
|
+ waitpid(cpid, NULL, 0);
|
|
|
}
|
|
|
lub_string_free(command);
|
|
|
|