|
@@ -21,7 +21,7 @@
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
|
-CLISH_PLUGIN_SYM(clish_script)
|
|
|
+CLISH_PLUGIN_OSYM(clish_script)
|
|
|
{
|
|
|
clish_shell_t *this = clish_context__get_shell(clish_context);
|
|
|
const clish_action_t *action = clish_context__get_action(clish_context);
|
|
@@ -29,10 +29,8 @@ CLISH_PLUGIN_SYM(clish_script)
|
|
|
pid_t cpid = -1;
|
|
|
int res;
|
|
|
const char *fifo_name;
|
|
|
- FILE *rpipe, *wpipe;
|
|
|
+ FILE *wpipe;
|
|
|
char *command = NULL;
|
|
|
-
|
|
|
-
|
|
|
struct sigaction sig_old_int;
|
|
|
struct sigaction sig_old_quit;
|
|
|
struct sigaction sig_new;
|
|
@@ -86,53 +84,28 @@ CLISH_PLUGIN_SYM(clish_script)
|
|
|
lub_string_cat(&command, " ");
|
|
|
lub_string_cat(&command, fifo_name);
|
|
|
|
|
|
-
|
|
|
- if (out) {
|
|
|
- konf_buf_t *buf;
|
|
|
-
|
|
|
-
|
|
|
- sigemptyset(&sig_set);
|
|
|
- sig_new.sa_flags = 0;
|
|
|
- sig_new.sa_mask = sig_set;
|
|
|
- sig_new.sa_handler = SIG_IGN;
|
|
|
- sigaction(SIGINT, &sig_new, &sig_old_int);
|
|
|
- sigaction(SIGQUIT, &sig_new, &sig_old_quit);
|
|
|
-
|
|
|
-
|
|
|
- rpipe = popen(command, "r");
|
|
|
- if (!rpipe) {
|
|
|
- fprintf(stderr, "Error: Can't fork the script.\n"
|
|
|
- "Error: The ACTION will be not executed.\n");
|
|
|
- lub_string_free(command);
|
|
|
- kill(cpid, SIGTERM);
|
|
|
- waitpid(cpid, NULL, 0);
|
|
|
-
|
|
|
-
|
|
|
- sigaction(SIGINT, &sig_old_int, NULL);
|
|
|
- sigaction(SIGQUIT, &sig_old_quit, NULL);
|
|
|
-
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- buf = konf_buf_new(fileno(rpipe));
|
|
|
- while (konf_buf_read(buf) > 0);
|
|
|
- *out = konf_buf__dup_line(buf);
|
|
|
- konf_buf_delete(buf);
|
|
|
-
|
|
|
- kill(cpid, SIGTERM);
|
|
|
- waitpid(cpid, NULL, 0);
|
|
|
-
|
|
|
- res = pclose(rpipe);
|
|
|
-
|
|
|
-
|
|
|
- sigaction(SIGINT, &sig_old_int, NULL);
|
|
|
- sigaction(SIGQUIT, &sig_old_quit, NULL);
|
|
|
- } else {
|
|
|
- res = system(command);
|
|
|
-
|
|
|
- kill(cpid, SIGTERM);
|
|
|
- waitpid(cpid, NULL, 0);
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+ * from executed script. Because the executed script
|
|
|
+ * and klish have the same terminal.
|
|
|
+ */
|
|
|
+ sigemptyset(&sig_set);
|
|
|
+ sig_new.sa_flags = 0;
|
|
|
+ sig_new.sa_mask = sig_set;
|
|
|
+ sig_new.sa_handler = SIG_IGN;
|
|
|
+ sigaction(SIGINT, &sig_new, &sig_old_int);
|
|
|
+ sigaction(SIGQUIT, &sig_new, &sig_old_quit);
|
|
|
+
|
|
|
+ res = system(command);
|
|
|
+
|
|
|
+
|
|
|
+ sigaction(SIGINT, &sig_old_int, NULL);
|
|
|
+ sigaction(SIGQUIT, &sig_old_quit, NULL);
|
|
|
+
|
|
|
+
|
|
|
+ kill(cpid, SIGTERM);
|
|
|
+ waitpid(cpid, NULL, 0);
|
|
|
+
|
|
|
lub_string_free(command);
|
|
|
|
|
|
#ifdef DEBUG
|
|
@@ -140,5 +113,3 @@ CLISH_PLUGIN_SYM(clish_script)
|
|
|
#endif
|
|
|
return WEXITSTATUS(res);
|
|
|
}
|
|
|
-
|
|
|
-
|