|
@@ -89,6 +89,7 @@ static bool_t ctrl_c_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
|
|
|
static void reset_hotkey_table(ctx_t *ctx);
|
|
|
static bool_t send_winch_notification(ctx_t *ctx);
|
|
|
static bool_t send_next_command(ctx_t *ctx);
|
|
|
+static void signal_handler_empty(int signo);
|
|
|
|
|
|
|
|
|
static bool_t tinyrl_key_enter(tinyrl_t *tinyrl, unsigned char key);
|
|
@@ -109,6 +110,8 @@ int main(int argc, char **argv)
|
|
|
tinyrl_t *tinyrl = NULL;
|
|
|
char *hist_path = NULL;
|
|
|
int stdin_flags = 0;
|
|
|
+ struct sigaction sig_act = {};
|
|
|
+ sigset_t sig_set = {};
|
|
|
|
|
|
#ifdef HAVE_LOCALE_H
|
|
|
|
|
@@ -164,6 +167,18 @@ int main(int argc, char **argv)
|
|
|
|
|
|
faux_eloop_add_signal(eloop, SIGWINCH, sigwinch_cb, &ctx);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ sigemptyset(&sig_set);
|
|
|
+ sig_act.sa_flags = 0;
|
|
|
+ sig_act.sa_mask = sig_set;
|
|
|
+ sig_act.sa_handler = &signal_handler_empty;
|
|
|
+ sigaction(SIGINT, &sig_act, NULL);
|
|
|
+ sigaction(SIGTERM, &sig_act, NULL);
|
|
|
+ sigaction(SIGQUIT, &sig_act, NULL);
|
|
|
+
|
|
|
|
|
|
ktp = ktp_session_new(unix_sock, eloop);
|
|
|
assert(ktp);
|
|
@@ -179,7 +194,8 @@ int main(int argc, char **argv)
|
|
|
|
|
|
|
|
|
stdin_flags = fcntl(STDIN_FILENO, F_GETFL, 0);
|
|
|
- fcntl(STDIN_FILENO, F_SETFL, stdin_flags | O_NONBLOCK);
|
|
|
+ if (ctx.mode != MODE_STDIN)
|
|
|
+ fcntl(STDIN_FILENO, F_SETFL, stdin_flags | O_NONBLOCK);
|
|
|
|
|
|
|
|
|
if (ctx.mode == MODE_INTERACTIVE)
|
|
@@ -512,12 +528,11 @@ bool_t cmd_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *udata)
|
|
|
tinyrl_set_busy(ctx->tinyrl, BOOL_FALSE);
|
|
|
if (!ktp_session_done(ktp))
|
|
|
tinyrl_redisplay(ctx->tinyrl);
|
|
|
+
|
|
|
+ faux_eloop_add_fd(ktp_session_eloop(ktp), STDIN_FILENO, POLLIN,
|
|
|
+ stdin_cb, ctx);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- faux_eloop_add_fd(ktp_session_eloop(ktp), STDIN_FILENO, POLLIN,
|
|
|
- stdin_cb, ctx);
|
|
|
-
|
|
|
|
|
|
send_next_command(ctx);
|
|
|
|
|
@@ -532,6 +547,11 @@ bool_t cmd_incompleted_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *u
|
|
|
{
|
|
|
ctx_t *ctx = (ctx_t *)udata;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ if (ctx->mode == MODE_STDIN)
|
|
|
+ return BOOL_TRUE;
|
|
|
+
|
|
|
if (ktp_session_state(ktp) == KTP_SESSION_STATE_WAIT_FOR_CMD) {
|
|
|
|
|
|
if (KTP_STATUS_IS_NEED_STDIN(ktp_session_cmd_features(ktp))) {
|
|
@@ -664,10 +684,12 @@ static bool_t ctrl_c_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
|
|
|
if (!ctx)
|
|
|
return BOOL_FALSE;
|
|
|
|
|
|
+ if (ctx->mode != MODE_INTERACTIVE)
|
|
|
+ return BOOL_FALSE;
|
|
|
+
|
|
|
state = ktp_session_state(ctx->ktp);
|
|
|
- if (state != KTP_SESSION_STATE_WAIT_FOR_CMD)
|
|
|
- return BOOL_TRUE;
|
|
|
- ktp_session_stdin(ctx->ktp, &ctrl_c, sizeof(ctrl_c));
|
|
|
+ if (state == KTP_SESSION_STATE_WAIT_FOR_CMD)
|
|
|
+ ktp_session_stdin(ctx->ktp, &ctrl_c, sizeof(ctrl_c));
|
|
|
|
|
|
|
|
|
eloop = eloop;
|
|
@@ -1028,3 +1050,9 @@ static bool_t stdout_cb(ktp_session_t *ktp, const char *line, size_t len,
|
|
|
|
|
|
return BOOL_TRUE;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+static void signal_handler_empty(int signo)
|
|
|
+{
|
|
|
+ signo = signo;
|
|
|
+}
|