|
@@ -44,6 +44,8 @@ static bool_t stdin_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
|
|
|
void *associated_data, void *user_data);
|
|
|
static bool_t sigwinch_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
|
|
|
void *associated_data, void *user_data);
|
|
|
+static bool_t ctrl_c_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
|
|
|
+ void *associated_data, void *user_data);
|
|
|
|
|
|
static void reset_hotkey_table(ctx_t *ctx);
|
|
|
static bool_t interactive_stdout_cb(ktp_session_t *ktp, const char *line, size_t len,
|
|
@@ -119,6 +121,12 @@ int klish_interactive_shell(ktp_session_t *ktp, struct options *opts)
|
|
|
|
|
|
eloop = ktp_session_eloop(ktp);
|
|
|
|
|
|
+ // Reassign signal handlers. Handlers are used to send SIGINT
|
|
|
+ // to non-interactive commands
|
|
|
+ faux_eloop_add_signal(eloop, SIGINT, ctrl_c_cb, &ctx);
|
|
|
+ faux_eloop_add_signal(eloop, SIGTERM, ctrl_c_cb, &ctx);
|
|
|
+ faux_eloop_add_signal(eloop, SIGQUIT, ctrl_c_cb, &ctx);
|
|
|
+
|
|
|
// Notify server about terminal window size change
|
|
|
faux_eloop_add_signal(eloop, SIGWINCH, sigwinch_cb, &ctx);
|
|
|
|
|
@@ -256,6 +264,9 @@ bool_t cmd_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *udata)
|
|
|
int rc = -1;
|
|
|
faux_error_t *error = NULL;
|
|
|
|
|
|
+ // Disable SIGINT caught for non-interactive commands
|
|
|
+ tinyrl_disable_isig(ctx->tinyrl);
|
|
|
+
|
|
|
process_prompt_param(ctx->tinyrl, msg);
|
|
|
process_hotkey_param(ctx, msg);
|
|
|
|
|
@@ -296,11 +307,15 @@ bool_t cmd_incompleted_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *u
|
|
|
{
|
|
|
ctx_t *ctx = (ctx_t *)udata;
|
|
|
|
|
|
- // Interactive command. So restore stdin handler.
|
|
|
- if ((ktp_session_state(ktp) == KTP_SESSION_STATE_WAIT_FOR_CMD) &&
|
|
|
- KTP_STATUS_IS_INTERACTIVE(ktp_session_cmd_features(ktp))) {
|
|
|
- faux_eloop_add_fd(ktp_session_eloop(ktp), STDIN_FILENO, POLLIN,
|
|
|
- stdin_cb, ctx);
|
|
|
+ if (ktp_session_state(ktp) == KTP_SESSION_STATE_WAIT_FOR_CMD) {
|
|
|
+ // Interactive command. So restore stdin handler.
|
|
|
+ if (KTP_STATUS_IS_INTERACTIVE(ktp_session_cmd_features(ktp))) {
|
|
|
+ // Disable SIGINT signal
|
|
|
+ tinyrl_disable_isig(ctx->tinyrl);
|
|
|
+ // Interactive command. So restore stdin handler.
|
|
|
+ faux_eloop_add_fd(ktp_session_eloop(ktp), STDIN_FILENO, POLLIN,
|
|
|
+ stdin_cb, ctx);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Happy compiler
|
|
@@ -406,6 +421,26 @@ static bool_t sigwinch_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
|
|
|
}
|
|
|
|
|
|
|
|
|
+static bool_t ctrl_c_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
|
|
|
+ void *associated_data, void *udata)
|
|
|
+{
|
|
|
+ ctx_t *ctx = (ctx_t *)udata;
|
|
|
+ char ctrl_c = KEY_ETX;
|
|
|
+
|
|
|
+ if (!ctx)
|
|
|
+ return BOOL_FALSE;
|
|
|
+
|
|
|
+ ktp_session_stdin(ctx->ktp, &ctrl_c, sizeof(ctrl_c));
|
|
|
+
|
|
|
+ // Happy compiler
|
|
|
+ eloop = eloop;
|
|
|
+ type = type;
|
|
|
+ associated_data = associated_data;
|
|
|
+
|
|
|
+ return BOOL_TRUE;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
static bool_t tinyrl_key_enter(tinyrl_t *tinyrl, unsigned char key)
|
|
|
{
|
|
|
const char *line = NULL;
|
|
@@ -426,6 +461,9 @@ static bool_t tinyrl_key_enter(tinyrl_t *tinyrl, unsigned char key)
|
|
|
|
|
|
tinyrl_reset_line(tinyrl);
|
|
|
tinyrl_set_busy(tinyrl, BOOL_TRUE);
|
|
|
+ // Suppose non-interactive command
|
|
|
+ // Caught SIGINT for non-interactive commands
|
|
|
+ tinyrl_enable_isig(ctx->tinyrl);
|
|
|
|
|
|
key = key; // Happy compiler
|
|
|
|