Browse Source

Don't use stdin, stdout, stderr names for fields.

The stdin, stdout, stderr are the macros by the C and POSIX standard and can be
expanded to something else. For example FreeBSD expands them to the internal
variables names. When "stdin" etc. are used in nested macros then they are
expanded to their values but not names. The main problem was kcontext function
names defined by nested macros and building on FreeBSD.
Serj Kalichev 21 hours ago
parent
commit
ed9ddd7377

+ 41 - 41
bin/klish/klish.c

@@ -64,16 +64,16 @@ typedef struct ctx_s {
 	faux_list_node_t *cmdline_iter; // MODE_CMDLINE
 	faux_list_node_t *files_iter; // MODE_FILES
 	faux_file_t *files_fd; // MODE_FILES
-	faux_file_t *stdin_fd; // MODE_STDIN
+	faux_file_t *std_in_fd; // MODE_STDIN
 } ctx_t;
 
 
 // KTP session static functions
-static bool_t async_stdin_sent_cb(ktp_session_t *ktp, size_t len,
+static bool_t async_std_in_sent_cb(ktp_session_t *ktp, size_t len,
 	void *user_data);
-static bool_t stdout_cb(ktp_session_t *ktp, const char *line, size_t len,
+static bool_t std_out_cb(ktp_session_t *ktp, const char *line, size_t len,
 	void *user_data);
-static bool_t stderr_cb(ktp_session_t *ktp, const char *line, size_t len,
+static bool_t std_err_cb(ktp_session_t *ktp, const char *line, size_t len,
 	void *user_data);
 static bool_t auth_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *udata);
 static bool_t cmd_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *udata);
@@ -85,7 +85,7 @@ static bool_t notification_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *u
 // Eloop callbacks
 //static bool_t stop_loop_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 //	void *associated_data, void *user_data);
-static bool_t stdin_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
+static bool_t std_in_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);
@@ -116,7 +116,7 @@ int main(int argc, char **argv)
 	ctx_t ctx = {};
 	tinyrl_t *tinyrl = NULL;
 	char *hist_path = NULL;
-	int stdin_flags = 0;
+	int std_in_flags = 0;
 	struct sigaction sig_act = {};
 	sigset_t sig_set = {};
 
@@ -200,9 +200,9 @@ int main(int argc, char **argv)
 	ktp_session_set_stop_on_answer(ktp, BOOL_FALSE);
 
 	// Set stdin to O_NONBLOCK mode
-	stdin_flags = fcntl(STDIN_FILENO, F_GETFL, 0);
+	std_in_flags = fcntl(STDIN_FILENO, F_GETFL, 0);
 	if (ctx.mode != MODE_STDIN)
-		fcntl(STDIN_FILENO, F_SETFL, stdin_flags | O_NONBLOCK);
+		fcntl(STDIN_FILENO, F_SETFL, std_in_flags | O_NONBLOCK);
 
 	// TiniRL
 	if (ctx.mode == MODE_INTERACTIVE)
@@ -219,9 +219,9 @@ int main(int argc, char **argv)
 	ctx.opts = opts;
 	ctx.pager_working = TRI_UNDEFINED;
 
-	ktp_session_set_cb(ktp, KTP_SESSION_CB_STDIN, async_stdin_sent_cb, &ctx);
-	ktp_session_set_cb(ktp, KTP_SESSION_CB_STDOUT, stdout_cb, &ctx);
-	ktp_session_set_cb(ktp, KTP_SESSION_CB_STDERR, stderr_cb, &ctx);
+	ktp_session_set_cb(ktp, KTP_SESSION_CB_STDIN, async_std_in_sent_cb, &ctx);
+	ktp_session_set_cb(ktp, KTP_SESSION_CB_STDOUT, std_out_cb, &ctx);
+	ktp_session_set_cb(ktp, KTP_SESSION_CB_STDERR, std_err_cb, &ctx);
 	ktp_session_set_cb(ktp, KTP_SESSION_CB_AUTH_ACK, auth_ack_cb, &ctx);
 	ktp_session_set_cb(ktp, KTP_SESSION_CB_CMD_ACK, cmd_ack_cb, &ctx);
 	ktp_session_set_cb(ktp, KTP_SESSION_CB_CMD_ACK_INCOMPLETED,
@@ -268,7 +268,7 @@ int main(int argc, char **argv)
 	retval = 0;
 err:
 	// Restore stdin mode
-	fcntl(STDIN_FILENO, F_SETFL, stdin_flags);
+	fcntl(STDIN_FILENO, F_SETFL, std_in_flags);
 	reset_hotkey_table(&ctx);
 	if (tinyrl) {
 		if (tinyrl_busy(tinyrl))
@@ -321,12 +321,12 @@ static bool_t send_next_command(ctx_t *ctx)
 
 	// Commands from stdin
 	} else if (ctx->mode == MODE_STDIN) {
-		if (!ctx->stdin_fd)
-			ctx->stdin_fd = faux_file_fdopen(STDIN_FILENO);
-		if (ctx->stdin_fd)
-			line = faux_file_getline(ctx->stdin_fd);
+		if (!ctx->std_in_fd)
+			ctx->std_in_fd = faux_file_fdopen(STDIN_FILENO);
+		if (ctx->std_in_fd)
+			line = faux_file_getline(ctx->std_in_fd);
 		if (!line) // EOF
-			faux_file_close(ctx->stdin_fd);
+			faux_file_close(ctx->std_in_fd);
 	}
 
 	if (!line) {
@@ -355,7 +355,7 @@ static bool_t send_next_command(ctx_t *ctx)
 }
 
 
-static bool_t stderr_cb(ktp_session_t *ktp, const char *line, size_t len,
+static bool_t std_err_cb(ktp_session_t *ktp, const char *line, size_t len,
 	void *user_data)
 {
 	if (faux_write_block(STDERR_FILENO, line, len) < 0)
@@ -471,7 +471,7 @@ bool_t auth_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *udata)
 	if (ctx->mode == MODE_INTERACTIVE) {
 		// Start getting stdin
 		faux_eloop_add_fd(ktp_session_eloop(ktp), STDIN_FILENO, POLLIN,
-			stdin_cb, ctx);
+			std_in_cb, ctx);
 		// Print prompt for interactive command
 		tinyrl_redisplay(ctx->tinyrl);
 	} else {
@@ -511,11 +511,11 @@ bool_t cmd_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *udata)
 	// Sometimes output stream from server doesn't contain final crlf so
 	// goto newline itself
 	if (ktp_session_last_stream(ktp) == STDERR_FILENO) {
-		if (ktp_session_stderr_need_newline(ktp))
+		if (ktp_session_std_err_need_newline(ktp))
 			fprintf(stderr, "\n");
 	} else {
 		// Pager adds newline itself
-		if (ktp_session_stdout_need_newline(ktp) && !it_was_pager)
+		if (ktp_session_std_out_need_newline(ktp) && !it_was_pager)
 			tinyrl_crlf(ctx->tinyrl);
 	}
 
@@ -547,7 +547,7 @@ bool_t cmd_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *udata)
 			tinyrl_redisplay(ctx->tinyrl);
 		// Operation is finished so restore stdin handler
 		faux_eloop_add_fd(ktp_session_eloop(ktp), STDIN_FILENO, POLLIN,
-			stdin_cb, ctx);
+			std_in_cb, ctx);
 	}
 
 	// Send next command for non-interactive modes
@@ -580,7 +580,7 @@ bool_t cmd_incompleted_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *u
 			// themself interactively.)
 			tinyrl_disable_isig(ctx->tinyrl);
 			faux_eloop_add_fd(ktp_session_eloop(ktp), STDIN_FILENO, POLLIN,
-				stdin_cb, ctx);
+				std_in_cb, ctx);
 		} else {
 			// Raw mode setting can disable ISIG internally.
 			// So restore it
@@ -595,14 +595,14 @@ bool_t cmd_incompleted_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *u
 }
 
 
-static bool_t stdin_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
+static bool_t std_in_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
 	void *associated_data, void *udata)
 {
 	bool_t rc = BOOL_TRUE;
 	ctx_t *ctx = (ctx_t *)udata;
 	ktp_session_state_e state = KTP_SESSION_STATE_ERROR;
 	faux_eloop_info_fd_t *info = (faux_eloop_info_fd_t *)associated_data;
-	bool_t close_stdin = BOOL_FALSE;
+	bool_t close_std_in = BOOL_FALSE;
 	size_t obuf_len = 0;
 
 	if (!ctx)
@@ -611,7 +611,7 @@ static bool_t stdin_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
 	// Some errors or fd is closed so stop interactive session
 	// Non-interactive session just removes stdin callback
 	if (info->revents & (POLLHUP | POLLERR | POLLNVAL))
-		close_stdin = BOOL_TRUE;
+		close_std_in = BOOL_TRUE;
 
 	// Temporarily stop stdin reading because too much data is buffered
 	// and all data can't be sent to server yet
@@ -627,7 +627,7 @@ static bool_t stdin_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
 	if ((state == KTP_SESSION_STATE_IDLE) &&
 		(ctx->mode == MODE_INTERACTIVE)) {
 		tinyrl_read(ctx->tinyrl);
-		if (close_stdin) {
+		if (close_std_in) {
 			faux_eloop_del_fd(eloop, STDIN_FILENO);
 			rc = BOOL_FALSE;
 		}
@@ -643,10 +643,10 @@ static bool_t stdin_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
 		// Allow another handlers to push already received data to
 		// server
 		if ((bytes_readed = read(fd, buf, sizeof(buf))) > 0)
-			ktp_session_stdin(ctx->ktp, buf, bytes_readed);
+			ktp_session_std_in(ctx->ktp, buf, bytes_readed);
 		// Actually close stdin only when all data is read
-		if (close_stdin && (bytes_readed <= 0)) {
-			ktp_session_stdin_close(ctx->ktp);
+		if (close_std_in && (bytes_readed <= 0)) {
+			ktp_session_std_in_close(ctx->ktp);
 			faux_eloop_del_fd(eloop, STDIN_FILENO);
 		}
 
@@ -665,7 +665,7 @@ static bool_t stdin_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
 }
 
 
-static bool_t async_stdin_sent_cb(ktp_session_t *ktp, size_t len,
+static bool_t async_std_in_sent_cb(ktp_session_t *ktp, size_t len,
 	void *user_data)
 {
 	ctx_t *ctx = (ctx_t *)user_data;
@@ -676,7 +676,7 @@ static bool_t async_stdin_sent_cb(ktp_session_t *ktp, size_t len,
 	// to server socket. So if stdin transmit was stopped due to obuf
 	// overflow it's time to rearm transmission
 	faux_eloop_add_fd(ktp_session_eloop(ktp), STDIN_FILENO, POLLIN,
-		stdin_cb, ctx);
+		std_in_cb, ctx);
 
 	len = len; // Happy compiler
 
@@ -744,7 +744,7 @@ static bool_t ctrl_c_cb(faux_eloop_t *eloop, faux_eloop_type_e type,
 
 	state = ktp_session_state(ctx->ktp);
 	if (state == KTP_SESSION_STATE_WAIT_FOR_CMD)
-		ktp_session_stdin(ctx->ktp, &ctrl_c, sizeof(ctrl_c));
+		ktp_session_std_in(ctx->ktp, &ctrl_c, sizeof(ctrl_c));
 
 	// Happy compiler
 	eloop = eloop;
@@ -963,7 +963,7 @@ bool_t completion_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *udata)
 
 	// Operation is finished so restore stdin handler
 	faux_eloop_add_fd(ktp_session_eloop(ktp), STDIN_FILENO, POLLIN,
-		stdin_cb, ctx);
+		std_in_cb, ctx);
 
 	// Happy compiler
 	ktp = ktp;
@@ -1052,7 +1052,7 @@ bool_t help_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *udata)
 
 	// Operation is finished so restore stdin handler
 	faux_eloop_add_fd(ktp_session_eloop(ktp), STDIN_FILENO, POLLIN,
-		stdin_cb, ctx);
+		std_in_cb, ctx);
 
 	ktp = ktp; // happy compiler
 
@@ -1060,18 +1060,18 @@ bool_t help_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *udata)
 }
 
 
-//size_t max_stdout_len = 0;
+//size_t max_std_out_len = 0;
 
-static bool_t stdout_cb(ktp_session_t *ktp, const char *line, size_t len,
+static bool_t std_out_cb(ktp_session_t *ktp, const char *line, size_t len,
 	void *udata)
 {
 	ctx_t *ctx = (ctx_t *)udata;
 
 	assert(ctx);
 
-//if (len > max_stdout_len) {
-//max_stdout_len = len;
-//fprintf(stderr, "max_stdout_len=%ld\n", max_stdout_len);
+//if (len > max_std_out_len) {
+//max_std_out_len = len;
+//fprintf(stderr, "max_std_out_len=%ld\n", max_std_out_len);
 //}
 
 	// Start pager if necessary
@@ -1094,7 +1094,7 @@ static bool_t stdout_cb(ktp_session_t *ktp, const char *line, size_t len,
 		if (faux_write_block(fileno(ctx->pager_pipe), line, len) <= 0) {
 			// If we can't write to pager pipe then send
 			// "SIGPIPE" to server. Pager is finished or broken.
-			ktp_session_stdout_close(ktp);
+			ktp_session_std_out_close(ktp);
 			ctx->pager_working = TRI_FALSE;
 			return BOOL_TRUE; // Don't break the loop
 		}

+ 6 - 6
klish/kcontext.h

@@ -62,16 +62,16 @@ faux_list_node_t *kcontext_action_iter(const kcontext_t *context);
 FAUX_HIDDEN bool_t kcontext_set_action_iter(kcontext_t *context, faux_list_node_t *action_iter);
 
 // STDIN
-int kcontext_stdin(const kcontext_t *context);
-FAUX_HIDDEN bool_t kcontext_set_stdin(kcontext_t *context, int stdin);
+int kcontext_std_in(const kcontext_t *context);
+FAUX_HIDDEN bool_t kcontext_set_std_in(kcontext_t *context, int std_in);
 
 // STDOUT
-int kcontext_stdout(const kcontext_t *context);
-FAUX_HIDDEN bool_t kcontext_set_stdout(kcontext_t *context, int stdout);
+int kcontext_std_out(const kcontext_t *context);
+FAUX_HIDDEN bool_t kcontext_set_std_out(kcontext_t *context, int std_out);
 
 // STDERR
-int kcontext_stderr(const kcontext_t *context);
-FAUX_HIDDEN bool_t kcontext_set_stderr(kcontext_t *context, int stderr);
+int kcontext_std_err(const kcontext_t *context);
+FAUX_HIDDEN bool_t kcontext_set_std_err(kcontext_t *context, int std_err);
 
 // bufout
 faux_buf_t *kcontext_bufout(const kcontext_t *context);

+ 7 - 7
klish/kexec.h

@@ -25,14 +25,14 @@ void kexec_free(kexec_t *exec);
 bool_t kexec_dry_run(const kexec_t *exec);
 bool_t kexec_set_dry_run(kexec_t *exec, bool_t dry_run);
 // STDIN
-int kexec_stdin(const kexec_t *exec);
-bool_t kexec_set_stdin(kexec_t *exec, int stdin);
+int kexec_std_in(const kexec_t *exec);
+bool_t kexec_set_std_in(kexec_t *exec, int std_in);
 // STDOUT
-int kexec_stdout(const kexec_t *exec);
-bool_t kexec_set_stdout(kexec_t *exec, int stdout);
+int kexec_std_out(const kexec_t *exec);
+bool_t kexec_set_std_out(kexec_t *exec, int std_out);
 // STDERR
-int kexec_stderr(const kexec_t *exec);
-bool_t kexec_set_stderr(kexec_t *exec, int stderr);
+int kexec_std_err(const kexec_t *exec);
+bool_t kexec_set_std_err(kexec_t *exec, int std_err);
 // BUFIN
 faux_buf_t *kexec_bufin(const kexec_t *exec);
 bool_t kexec_set_bufin(kexec_t *exec, faux_buf_t *bufin);
@@ -60,7 +60,7 @@ kcontext_t *kexec_contexts_each(kexec_contexts_node_t **iter);
 
 bool_t kexec_continue_command_execution(kexec_t *exec, pid_t pid, int wstatus);
 bool_t kexec_exec(kexec_t *exec);
-bool_t kexec_need_stdin(const kexec_t *exec);
+bool_t kexec_need_std_in(const kexec_t *exec);
 bool_t kexec_interactive(const kexec_t *exec);
 bool_t kexec_set_winsize(kexec_t *exec);
 const kaction_t *kexec_current_action(const kexec_t *exec);

+ 6 - 6
klish/ksession.h

@@ -50,12 +50,12 @@ const char *ksession_user(const ksession_t *session);
 bool_t ksession_set_user(ksession_t *session, const char *user);
 
 // Client isatty
-bool_t ksession_isatty_stdin(const ksession_t *session);
-bool_t ksession_set_isatty_stdin(ksession_t *session, bool_t isatty_stdin);
-bool_t ksession_isatty_stdout(const ksession_t *session);
-bool_t ksession_set_isatty_stdout(ksession_t *session, bool_t isatty_stdout);
-bool_t ksession_isatty_stderr(const ksession_t *session);
-bool_t ksession_set_isatty_stderr(ksession_t *session, bool_t isatty_stderr);
+bool_t ksession_isatty_std_in(const ksession_t *session);
+bool_t ksession_set_isatty_std_in(ksession_t *session, bool_t isatty_std_in);
+bool_t ksession_isatty_std_out(const ksession_t *session);
+bool_t ksession_set_isatty_std_out(ksession_t *session, bool_t isatty_std_out);
+bool_t ksession_isatty_std_err(const ksession_t *session);
+bool_t ksession_set_isatty_std_err(ksession_t *session, bool_t isatty_std_err);
 
 C_DECL_END
 

+ 18 - 18
klish/ksession/kcontext.c

@@ -30,9 +30,9 @@ struct kcontext_s {
 	const kexec_t *parent_exec; // Parent exec (if available)
 	faux_list_node_t *action_iter; // Current action
 	ksym_t *sym;
-	int stdin;
-	int stdout;
-	int stderr;
+	int std_in;
+	int std_out;
+	int std_err;
 	faux_buf_t *bufout; // Don't free. Just a link
 	faux_buf_t *buferr; // Don't free. Just a link
 	pid_t pid;
@@ -85,16 +85,16 @@ KGET(context, faux_list_node_t *, action_iter);
 FAUX_HIDDEN KSET(context, faux_list_node_t *, action_iter);
 
 // STDIN
-KGET(context, int, stdin);
-FAUX_HIDDEN KSET(context, int, stdin);
+KGET(context, int, std_in);
+FAUX_HIDDEN KSET(context, int, std_in);
 
 // STDOUT
-KGET(context, int, stdout);
-FAUX_HIDDEN KSET(context, int, stdout);
+KGET(context, int, std_out);
+FAUX_HIDDEN KSET(context, int, std_out);
 
 // STDERR
-KGET(context, int, stderr);
-FAUX_HIDDEN KSET(context, int, stderr);
+KGET(context, int, std_err);
+FAUX_HIDDEN KSET(context, int, std_err);
 
 // bufout
 KGET(context, faux_buf_t *, bufout);
@@ -149,9 +149,9 @@ kcontext_t *kcontext_new(kcontext_type_e type)
 	context->parent_exec = NULL; // Don't free
 	context->action_iter = NULL;
 	context->sym = NULL;
-	context->stdin = -1;
-	context->stdout = -1;
-	context->stderr = -1;
+	context->std_in = -1;
+	context->std_out = -1;
+	context->std_err = -1;
 	context->bufout = NULL;
 	context->buferr = NULL;
 	context->pid = -1; // PID of currently executed ACTION
@@ -172,12 +172,12 @@ void kcontext_free(kcontext_t *context)
 
 	kpargv_free(context->pargv);
 
-	if (context->stdin != -1)
-		close(context->stdin);
-	if (context->stdout != -1)
-		close(context->stdout);
-	if (context->stderr != -1)
-		close(context->stderr);
+	if (context->std_in != -1)
+		close(context->std_in);
+	if (context->std_out != -1)
+		close(context->std_out);
+	if (context->std_err != -1)
+		close(context->std_err);
 
 	faux_str_free(context->line);
 

+ 78 - 78
klish/ksession/kexec.c

@@ -36,9 +36,9 @@ struct kexec_s {
 	ksession_t *session;
 	faux_list_t *contexts;
 	bool_t dry_run;
-	int stdin;
-	int stdout;
-	int stderr;
+	int std_in;
+	int std_out;
+	int std_err;
 	faux_buf_t *bufin;
 	faux_buf_t *bufout;
 	faux_buf_t *buferr;
@@ -53,16 +53,16 @@ KGET_BOOL(exec, dry_run);
 KSET_BOOL(exec, dry_run);
 
 // STDIN
-KGET(exec, int, stdin);
-KSET(exec, int, stdin);
+KGET(exec, int, std_in);
+KSET(exec, int, std_in);
 
 // STDOUT
-KGET(exec, int, stdout);
-KSET(exec, int, stdout);
+KGET(exec, int, std_out);
+KSET(exec, int, std_out);
 
 // STDERR
-KGET(exec, int, stderr);
-KSET(exec, int, stderr);
+KGET(exec, int, std_err);
+KSET(exec, int, std_err);
 
 // BufIN
 KGET(exec, faux_buf_t *, bufin);
@@ -122,9 +122,9 @@ kexec_t *kexec_new(ksession_t *session, kcontext_type_e type)
 	assert(exec->contexts);
 
 	// I/O
-	exec->stdin = -1;
-	exec->stdout = -1;
-	exec->stderr = -1;
+	exec->std_in = -1;
+	exec->std_out = -1;
+	exec->std_err = -1;
 
 	exec->bufin = faux_buf_new(0);
 	exec->bufout = faux_buf_new(0);
@@ -145,12 +145,12 @@ void kexec_free(kexec_t *exec)
 
 	faux_list_free(exec->contexts);
 
-	if (exec->stdin != -1)
-		close(exec->stdin);
-	if (exec->stdout != -1)
-		close(exec->stdout);
-	if (exec->stderr != -1)
-		close(exec->stderr);
+	if (exec->std_in != -1)
+		close(exec->std_in);
+	if (exec->std_out != -1)
+		close(exec->std_out);
+	if (exec->std_err != -1)
+		close(exec->std_err);
 
 	faux_buf_free(exec->bufin);
 	faux_buf_free(exec->bufout);
@@ -311,14 +311,14 @@ static bool_t kexec_prepare(kexec_t *exec)
 {
 	int pipefd[2] = {};
 	faux_list_node_t *iter = NULL;
-	int global_stderr = -1;
+	int global_std_err = -1;
 	int fflags = 0;
 	int r_end = -1;
 	int w_end = -1;
 	// Pseudoterminal related vars
-	bool_t isatty_stdin = BOOL_FALSE;
-	bool_t isatty_stdout = BOOL_FALSE;
-	bool_t isatty_stderr = BOOL_FALSE;
+	bool_t isatty_std_in = BOOL_FALSE;
+	bool_t isatty_std_out = BOOL_FALSE;
+	bool_t isatty_std_err = BOOL_FALSE;
 	int pts = -1;
 	int ptm = -1;
 	char *pts_name = NULL;
@@ -335,15 +335,15 @@ static bool_t kexec_prepare(kexec_t *exec)
 	// pseudoterminal. Service actions (internal actions like PTYPE checks)
 	// never get terminal
 	if (exec->type == KCONTEXT_TYPE_ACTION) {
-		isatty_stdin = ksession_isatty_stdin(exec->session);
+		isatty_std_in = ksession_isatty_std_in(exec->session);
 		// Only if last command in pipeline is interactive then stdout
 		// can be pts. Because client adds its own pager to pipeline in
 		// a case of non-interactive commands
 		if (kexec_interactive(exec))
-			isatty_stdout = ksession_isatty_stdout(exec->session);
-		isatty_stderr = ksession_isatty_stderr(exec->session);
+			isatty_std_out = ksession_isatty_std_out(exec->session);
+		isatty_std_err = ksession_isatty_std_err(exec->session);
 	}
-	if (isatty_stdin || isatty_stdout || isatty_stderr) {
+	if (isatty_std_in || isatty_std_out || isatty_std_err) {
 		ptm = open(PTMX_PATH, O_RDWR, O_NOCTTY);
 		if (ptm < 0)
 			return BOOL_FALSE;
@@ -372,7 +372,7 @@ static bool_t kexec_prepare(kexec_t *exec)
 	// Create "global" stdin, stdout, stderr for the whole job execution.
 
 	// STDIN
-	if (isatty_stdin) {
+	if (isatty_std_in) {
 		r_end = pts;
 		w_end = ptm;
 	} else {
@@ -384,12 +384,12 @@ static bool_t kexec_prepare(kexec_t *exec)
 		r_end = pipefd[0];
 		w_end = pipefd[1];
 	}
-	kcontext_set_stdin(faux_list_data(
+	kcontext_set_std_in(faux_list_data(
 		faux_list_head(exec->contexts)), r_end); // Read end
-	kexec_set_stdin(exec, w_end); // Write end
+	kexec_set_std_in(exec, w_end); // Write end
 
 	// STDOUT
-	if (isatty_stdout) {
+	if (isatty_std_out) {
 		r_end = ptm;
 		w_end = pts;
 	} else {
@@ -401,12 +401,12 @@ static bool_t kexec_prepare(kexec_t *exec)
 		r_end = pipefd[0];
 		w_end = pipefd[1];
 	}
-	kexec_set_stdout(exec, r_end); // Read end
-	kcontext_set_stdout(
+	kexec_set_std_out(exec, r_end); // Read end
+	kcontext_set_std_out(
 		faux_list_data(faux_list_tail(exec->contexts)), w_end); // Write end
 
 	// STDERR
-	if (isatty_stderr) {
+	if (isatty_std_err) {
 		r_end = ptm;
 		w_end = pts;
 	} else {
@@ -418,9 +418,9 @@ static bool_t kexec_prepare(kexec_t *exec)
 		r_end = pipefd[0];
 		w_end = pipefd[1];
 	}
-	kexec_set_stderr(exec, r_end); // Read end
+	kexec_set_std_err(exec, r_end); // Read end
 	// STDERR write end will be set to all list members as stderr
-	global_stderr = w_end; // Write end
+	global_std_err = w_end; // Write end
 
 	// Save current path
 	if (ksession_path(exec->session))
@@ -433,15 +433,15 @@ static bool_t kexec_prepare(kexec_t *exec)
 		kcontext_t *context = (kcontext_t *)faux_list_data(iter);
 
 		// Set the same STDERR to all contexts
-		kcontext_set_stderr(context, global_stderr);
+		kcontext_set_std_err(context, global_std_err);
 
 		// Create pipes beetween processes
 		if (next) {
 			kcontext_t *next_context = (kcontext_t *)faux_list_data(next);
 			if (pipe(pipefd) < 0)
 				return BOOL_FALSE;
-			kcontext_set_stdout(context, pipefd[1]); // Write end
-			kcontext_set_stdin(next_context, pipefd[0]); // Read end
+			kcontext_set_std_out(context, pipefd[1]); // Write end
+			kcontext_set_std_in(next_context, pipefd[0]); // Read end
 		}
 	}
 
@@ -461,8 +461,8 @@ static bool_t exec_action_sync(const kexec_t *exec, kcontext_t *context,
 	ksym_fn fn = NULL;
 	int exitcode = 0;
 	pid_t child_pid = -1;
-	int pipe_stdout[2] = {};
-	int pipe_stderr[2] = {};
+	int pipe_std_out[2] = {};
+	int pipe_std_err[2] = {};
 	ksym_t *sym = NULL;
 
 	sym = kaction_sym(action);
@@ -481,11 +481,11 @@ static bool_t exec_action_sync(const kexec_t *exec, kcontext_t *context,
 //fprintf(stderr, "sync %s\n", ksym_name(sym));
 
 	// Create pipes beetween sym function and grabber
-	if (pipe(pipe_stdout) < 0)
+	if (pipe(pipe_std_out) < 0)
 		return BOOL_FALSE;
-	if (pipe(pipe_stderr) < 0) {
-		close(pipe_stdout[0]);
-		close(pipe_stdout[1]);
+	if (pipe(pipe_std_err) < 0) {
+		close(pipe_std_out[0]);
+		close(pipe_std_out[1]);
 		return BOOL_FALSE;
 	}
 
@@ -496,17 +496,17 @@ static bool_t exec_action_sync(const kexec_t *exec, kcontext_t *context,
 	// Fork the grabber
 	child_pid = fork();
 	if (child_pid == -1) {
-		close(pipe_stdout[0]);
-		close(pipe_stdout[1]);
-		close(pipe_stderr[0]);
-		close(pipe_stderr[1]);
+		close(pipe_std_out[0]);
+		close(pipe_std_out[1]);
+		close(pipe_std_err[0]);
+		close(pipe_std_err[1]);
 		return BOOL_FALSE;
 	}
 
 	// Parent
 	if (child_pid != 0) {
-		int saved_stdout = -1;
-		int saved_stderr = -1;
+		int saved_std_out = -1;
+		int saved_std_err = -1;
 
 		// Save pid of grabber
 		if (pid)
@@ -514,15 +514,15 @@ static bool_t exec_action_sync(const kexec_t *exec, kcontext_t *context,
 
 		// Temporarily replace orig output streams by pipe
 		// stdout
-		saved_stdout = dup(STDOUT_FILENO);
-		dup2(pipe_stdout[1], STDOUT_FILENO);
-		close(pipe_stdout[0]);
-		close(pipe_stdout[1]);
+		saved_std_out = dup(STDOUT_FILENO);
+		dup2(pipe_std_out[1], STDOUT_FILENO);
+		close(pipe_std_out[0]);
+		close(pipe_std_out[1]);
 		// stderr
-		saved_stderr = dup(STDERR_FILENO);
-		dup2(pipe_stderr[1], STDERR_FILENO);
-		close(pipe_stderr[0]);
-		close(pipe_stderr[1]);
+		saved_std_err = dup(STDERR_FILENO);
+		dup2(pipe_std_err[1], STDERR_FILENO);
+		close(pipe_std_err[0]);
+		close(pipe_std_err[1]);
 
 		// Execute sym function right here
 		exitcode = fn(context);
@@ -533,21 +533,21 @@ static bool_t exec_action_sync(const kexec_t *exec, kcontext_t *context,
 		// stdout
 		fflush(stdout);
 		close(STDOUT_FILENO);
-		dup2(saved_stdout, STDOUT_FILENO);
-		close(saved_stdout);
+		dup2(saved_std_out, STDOUT_FILENO);
+		close(saved_std_out);
 		// stderr
 		fflush(stderr);
 		close(STDERR_FILENO);
-		dup2(saved_stderr, STDERR_FILENO);
-		close(saved_stderr);
+		dup2(saved_std_err, STDERR_FILENO);
+		close(saved_std_err);
 
 		return BOOL_TRUE;
 
 	// Child (Output grabber)
 	} else {
 		int fds[][2] = {
-			{pipe_stdout[0], kcontext_stdout(context)},
-			{pipe_stderr[0], kcontext_stderr(context)},
+			{pipe_std_out[0], kcontext_std_out(context)},
+			{pipe_std_err[0], kcontext_std_err(context)},
 			{-1, -1},
 		};
 		grabber(fds); // Grabber will not return
@@ -612,17 +612,17 @@ static bool_t exec_action_async(const kexec_t *exec, kcontext_t *context,
 		fd = open(exec->pts_fname, O_RDWR, 0);
 		if (fd < 0)
 			_exit(-1);
-		if (isatty(kcontext_stdin(context)))
-			kcontext_set_stdin(context, fd);
-		if (isatty(kcontext_stdout(context)))
-			kcontext_set_stdout(context, fd);
-		if (isatty(kcontext_stderr(context)))
-			kcontext_set_stderr(context, fd);
+		if (isatty(kcontext_std_in(context)))
+			kcontext_set_std_in(context, fd);
+		if (isatty(kcontext_std_out(context)))
+			kcontext_set_std_out(context, fd);
+		if (isatty(kcontext_std_err(context)))
+			kcontext_set_std_err(context, fd);
 	}
 
-	dup2(kcontext_stdin(context), STDIN_FILENO);
-	dup2(kcontext_stdout(context), STDOUT_FILENO);
-	dup2(kcontext_stderr(context), STDERR_FILENO);
+	dup2(kcontext_std_in(context), STDIN_FILENO);
+	dup2(kcontext_std_out(context), STDOUT_FILENO);
+	dup2(kcontext_std_err(context), STDERR_FILENO);
 
 	// Close all inherited fds except stdin, stdout, stderr
 	fdmax = (int)sysconf(_SC_OPEN_MAX);
@@ -721,14 +721,14 @@ static bool_t exec_action_sequence(const kexec_t *exec, kcontext_t *context,
 			// Close the stdout of finished ACTION sequence to inform
 			// process next in pipe about EOF. Else filter will not
 			// stop at all.
-			close(kcontext_stdout(context));
-			kcontext_set_stdout(context, -1);
+			close(kcontext_std_out(context));
+			kcontext_set_std_out(context, -1);
 
 			// Close the stdin of finished ACTION sequence to inform
 			// process previous in pipe. Else previous command will
 			// try to write to the pipe continously.
-			close(kcontext_stdin(context));
-			kcontext_set_stdin(context, -1);
+			close(kcontext_std_in(context));
+			kcontext_set_std_in(context, -1);
 
 			return BOOL_TRUE;
 		}
@@ -851,7 +851,7 @@ bool_t kexec_interactive(const kexec_t *exec)
 
 // If some kexec's kentry has tty as "in" then consider kexec as need_stdin.
 // The first kentry with "in=true" also does kexec need_stdin
-bool_t kexec_need_stdin(const kexec_t *exec)
+bool_t kexec_need_std_in(const kexec_t *exec)
 {
 	faux_list_node_t *iter = NULL;
 	size_t num = 0;

+ 12 - 12
klish/ksession/ksession.c

@@ -23,9 +23,9 @@ struct ksession_s {
 	pid_t pid; // Client's PID
 	uid_t uid; // Client's UID
 	char *user; // Client's user name (get by uid)
-	bool_t isatty_stdin;
-	bool_t isatty_stdout;
-	bool_t isatty_stderr;
+	bool_t isatty_std_in;
+	bool_t isatty_std_out;
+	bool_t isatty_std_err;
 };
 
 
@@ -64,12 +64,12 @@ KSET_STR(session, user);
 KGET_STR(session, user);
 
 // isatty
-KGET_BOOL(session, isatty_stdin);
-KSET_BOOL(session, isatty_stdin);
-KGET_BOOL(session, isatty_stdout);
-KSET_BOOL(session, isatty_stdout);
-KGET_BOOL(session, isatty_stderr);
-KSET_BOOL(session, isatty_stderr);
+KGET_BOOL(session, isatty_std_in);
+KSET_BOOL(session, isatty_std_in);
+KGET_BOOL(session, isatty_std_out);
+KSET_BOOL(session, isatty_std_out);
+KGET_BOOL(session, isatty_std_err);
+KSET_BOOL(session, isatty_std_err);
 
 
 ksession_t *ksession_new(kscheme_t *scheme, const char *starting_entry)
@@ -108,9 +108,9 @@ ksession_t *ksession_new(kscheme_t *scheme, const char *starting_entry)
 	session->pid = -1;
 	session->uid = -1;
 	session->user = NULL;
-	session->isatty_stdin = BOOL_FALSE;
-	session->isatty_stdout = BOOL_FALSE;
-	session->isatty_stderr = BOOL_FALSE;
+	session->isatty_std_in = BOOL_FALSE;
+	session->isatty_std_out = BOOL_FALSE;
+	session->isatty_std_err = BOOL_FALSE;
 	session->spid = getpid(); // For forked processes
 
 	return session;

+ 7 - 7
klish/ksession/ksession_parse.c

@@ -767,7 +767,7 @@ static bool_t stop_loop_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 }
 
 
-static bool_t get_stdout(kexec_t *exec)
+static bool_t get_std_out(kexec_t *exec)
 {
 	ssize_t r = -1;
 	faux_buf_t *faux_buf = NULL;
@@ -777,7 +777,7 @@ static bool_t get_stdout(kexec_t *exec)
 	if (!exec)
 		return BOOL_FALSE;
 
-	fd = kexec_stdout(exec);
+	fd = kexec_std_out(exec);
 	assert(fd != -1);
 	faux_buf = kexec_bufout(exec);
 	assert(faux_buf);
@@ -815,7 +815,7 @@ static bool_t action_terminated_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	// Check if kexec is done now
 	if (kexec_done(exec)) {
 		// May be buffer still contains data
-		get_stdout(exec);
+		get_std_out(exec);
 		return BOOL_FALSE; // To break a loop
 	}
 
@@ -828,7 +828,7 @@ static bool_t action_terminated_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 }
 
 
-static bool_t action_stdout_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
+static bool_t action_std_out_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	void *associated_data, void *user_data)
 {
 	kexec_t *exec = (kexec_t *)user_data;
@@ -838,7 +838,7 @@ static bool_t action_stdout_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	type = type;
 	associated_data = associated_data;
 
-	return get_stdout(exec);
+	return get_std_out(exec);
 }
 
 
@@ -885,8 +885,8 @@ bool_t ksession_exec_locally(ksession_t *session, kentry_t *entry,
 		faux_eloop_add_signal(eloop, SIGTERM, stop_loop_ev, session);
 		faux_eloop_add_signal(eloop, SIGQUIT, stop_loop_ev, session);
 		faux_eloop_add_signal(eloop, SIGCHLD, action_terminated_ev, exec);
-		faux_eloop_add_fd(eloop, kexec_stdout(exec), POLLIN,
-			action_stdout_ev, exec);
+		faux_eloop_add_fd(eloop, kexec_std_out(exec), POLLIN,
+			action_std_out_ev, exec);
 		faux_eloop_loop(eloop);
 		faux_eloop_free(eloop);
 		kexec_retcode(exec, retcode);

+ 26 - 25
klish/ktp/ktp_session.c

@@ -35,8 +35,8 @@ struct ktp_session_s {
 	ktp_status_e cmd_features;
 	bool_t cmd_features_available;
 	bool_t stop_on_answer; // Stop the loop when answer is received (for non-interactive mode)
-	bool_t stdout_need_newline; // Does stdout has final line feed. If no then newline is needed
-	bool_t stderr_need_newline; // Does stderr has final line feed. If no then newline is needed
+	bool_t std_out_need_newline; // Does stdout has final line feed. If no then newline is needed
+	bool_t std_err_need_newline; // Does stderr has final line feed. If no then newline is needed
 	int last_stream; // Last active stream: stdout or stderr
 };
 
@@ -73,8 +73,8 @@ ktp_session_t *ktp_session_new(int sock, faux_eloop_t *eloop)
 	ktp->request_done = BOOL_FALSE;
 	ktp->cmd_features = KTP_STATUS_NONE;
 	ktp->cmd_features_available = BOOL_FALSE;
-	ktp->stdout_need_newline = BOOL_FALSE;
-	ktp->stderr_need_newline = BOOL_FALSE;
+	ktp->std_out_need_newline = BOOL_FALSE;
+	ktp->std_err_need_newline = BOOL_FALSE;
 	ktp->last_stream = STDOUT_FILENO;
 
 	// Async object
@@ -264,7 +264,7 @@ static bool_t server_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 		}
 		// Execute external callback
 		if (ktp->cb[KTP_SESSION_CB_STDIN].fn)
-			((ktp_session_stdin_cb_fn)
+			((ktp_session_std_in_cb_fn)
 				ktp->cb[KTP_SESSION_CB_STDIN].fn)(
 				ktp, len, ktp->cb[KTP_SESSION_CB_STDIN].udata);
 	}
@@ -297,7 +297,8 @@ static bool_t server_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 }
 
 
-static bool_t ktp_session_process_stdout(ktp_session_t *ktp, const faux_msg_t *msg)
+static bool_t ktp_session_process_std_out(ktp_session_t *ktp,
+	const faux_msg_t *msg)
 {
 	char *line = NULL;
 	unsigned int len = 0;
@@ -313,18 +314,18 @@ static bool_t ktp_session_process_stdout(ktp_session_t *ktp, const faux_msg_t *m
 
 	if (len > 0) {
 		if (line[len - 1] == '\n')
-			ktp->stdout_need_newline = BOOL_FALSE;
+			ktp->std_out_need_newline = BOOL_FALSE;
 		else
-			ktp->stdout_need_newline = BOOL_TRUE;
+			ktp->std_out_need_newline = BOOL_TRUE;
 		ktp->last_stream = STDOUT_FILENO;
 	}
 
-	return ((ktp_session_stdout_cb_fn)ktp->cb[KTP_SESSION_CB_STDOUT].fn)(
+	return ((ktp_session_std_out_cb_fn)ktp->cb[KTP_SESSION_CB_STDOUT].fn)(
 		ktp, line, len, ktp->cb[KTP_SESSION_CB_STDOUT].udata);
 }
 
 
-static bool_t ktp_session_process_stderr(ktp_session_t *ktp, const faux_msg_t *msg)
+static bool_t ktp_session_process_std_err(ktp_session_t *ktp, const faux_msg_t *msg)
 {
 	char *line = NULL;
 	unsigned int len = 0;
@@ -341,13 +342,13 @@ static bool_t ktp_session_process_stderr(ktp_session_t *ktp, const faux_msg_t *m
 
 	if (len > 0) {
 		if (line[len - 1] == '\n')
-			ktp->stderr_need_newline = BOOL_FALSE;
+			ktp->std_err_need_newline = BOOL_FALSE;
 		else
-			ktp->stderr_need_newline = BOOL_TRUE;
+			ktp->std_err_need_newline = BOOL_TRUE;
 		ktp->last_stream = STDERR_FILENO;
 	}
 
-	return ((ktp_session_stdout_cb_fn)ktp->cb[KTP_SESSION_CB_STDERR].fn)(
+	return ((ktp_session_std_out_cb_fn)ktp->cb[KTP_SESSION_CB_STDERR].fn)(
 		ktp, line, len, ktp->cb[KTP_SESSION_CB_STDERR].udata);
 }
 
@@ -582,14 +583,14 @@ static bool_t ktp_session_dispatch(ktp_session_t *ktp, faux_msg_t *msg)
 			syslog(LOG_WARNING, "Unexpected KTP_STDOUT was received\n");
 			break;
 		}
-		rc = ktp_session_process_stdout(ktp, msg);
+		rc = ktp_session_process_std_out(ktp, msg);
 		break;
 	case KTP_STDERR:
 		if (ktp->state != KTP_SESSION_STATE_WAIT_FOR_CMD) {
 			syslog(LOG_WARNING, "Unexpected KTP_STDERR was received\n");
 			break;
 		}
-		rc = ktp_session_process_stderr(ktp, msg);
+		rc = ktp_session_process_std_err(ktp, msg);
 		break;
 	case KTP_NOTIFICATION:
 		rc = ktp_session_process_notification(ktp, msg);
@@ -678,8 +679,8 @@ static bool_t ktp_session_drop_state(ktp_session_t *ktp, faux_error_t *error)
 	ktp->request_done = BOOL_FALSE;
 	ktp->cmd_features = KTP_STATUS_NONE;
 	ktp->cmd_features_available = BOOL_FALSE;
-	ktp->stdout_need_newline = BOOL_FALSE;
-	ktp->stderr_need_newline = BOOL_FALSE;
+	ktp->std_out_need_newline = BOOL_FALSE;
+	ktp->std_err_need_newline = BOOL_FALSE;
 	ktp->last_stream = STDOUT_FILENO;
 
 	return BOOL_TRUE;
@@ -784,7 +785,7 @@ bool_t ktp_session_help(ktp_session_t *ktp, const char *line)
 }
 
 
-bool_t ktp_session_stdin(ktp_session_t *ktp, const char *line, size_t line_len)
+bool_t ktp_session_std_in(ktp_session_t *ktp, const char *line, size_t line_len)
 {
 	if (!ktp_session_req(ktp, KTP_STDIN, line, line_len,
 		NULL, BOOL_TRUE, BOOL_FALSE))
@@ -794,7 +795,7 @@ bool_t ktp_session_stdin(ktp_session_t *ktp, const char *line, size_t line_len)
 }
 
 
-bool_t ktp_session_stdin_close(ktp_session_t *ktp)
+bool_t ktp_session_std_in_close(ktp_session_t *ktp)
 {
 	if (!ktp_session_req(ktp, KTP_STDIN_CLOSE, NULL, 0,
 		NULL, BOOL_TRUE, BOOL_FALSE))
@@ -804,7 +805,7 @@ bool_t ktp_session_stdin_close(ktp_session_t *ktp)
 }
 
 
-bool_t ktp_session_stdout_close(ktp_session_t *ktp)
+bool_t ktp_session_std_out_close(ktp_session_t *ktp)
 {
 	if (!ktp_session_req(ktp, KTP_STDOUT_CLOSE, NULL, 0,
 		NULL, BOOL_TRUE, BOOL_FALSE))
@@ -814,7 +815,7 @@ bool_t ktp_session_stdout_close(ktp_session_t *ktp)
 }
 
 
-bool_t ktp_session_stderr_close(ktp_session_t *ktp)
+bool_t ktp_session_std_err_close(ktp_session_t *ktp)
 {
 	if (!ktp_session_req(ktp, KTP_STDERR_CLOSE, NULL, 0,
 		NULL, BOOL_TRUE, BOOL_FALSE))
@@ -836,21 +837,21 @@ bool_t ktp_session_retcode(ktp_session_t *ktp, int *retcode)
 }
 
 
-bool_t ktp_session_stdout_need_newline(ktp_session_t *ktp)
+bool_t ktp_session_std_out_need_newline(ktp_session_t *ktp)
 {
 	if (!ktp)
 		return BOOL_FALSE;
 
-	return ktp->stdout_need_newline;
+	return ktp->std_out_need_newline;
 }
 
 
-bool_t ktp_session_stderr_need_newline(ktp_session_t *ktp)
+bool_t ktp_session_std_err_need_newline(ktp_session_t *ktp)
 {
 	if (!ktp)
 		return BOOL_FALSE;
 
-	return ktp->stderr_need_newline;
+	return ktp->std_err_need_newline;
 }
 
 

+ 51 - 51
klish/ktp/ktpd_session.c

@@ -51,7 +51,7 @@ struct ktpd_session_s {
 	faux_eloop_t *eloop; // External link, dont's free()
 	kexec_t *exec;
 	bool_t exit;
-	bool_t stdin_must_be_closed;
+	bool_t std_in_must_be_closed;
 };
 
 
@@ -66,11 +66,11 @@ static bool_t ktpd_session_log(ktpd_session_t *ktpd, const kexec_t *exec);
 static bool_t ktpd_session_exec(ktpd_session_t *ktpd, const char *line,
 	int *retcode, faux_error_t *error,
 	bool_t dry_run, bool_t *view_was_changed);
-static bool_t action_stdout_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
+static bool_t action_std_out_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	void *associated_data, void *user_data);
-static bool_t action_stderr_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
+static bool_t action_std_err_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	void *associated_data, void *user_data);
-static bool_t get_stream(ktpd_session_t *ktpd, kexec_t *exec, int fd, bool_t is_stderr,
+static bool_t get_stream(ktpd_session_t *ktpd, kexec_t *exec, int fd, bool_t is_std_err,
 	bool_t process_all_data);
 
 
@@ -102,7 +102,7 @@ ktpd_session_t *ktpd_session_new(int sock, kscheme_t *scheme,
 	// Client can send command to close stdin but it can't be done
 	// immediately because stdin buffer can still contain data. So really
 	// close stdin after all data is written.
-	ktpd->stdin_must_be_closed = BOOL_FALSE;
+	ktpd->std_in_must_be_closed = BOOL_FALSE;
 	// Exit flag. It differs from ksession done flag because KTPD session
 	// can't exit immediately. It must finish current command processing
 	// before really stop the event loop. Note: User defined plugin
@@ -335,11 +335,11 @@ static bool_t ktpd_session_process_auth(ktpd_session_t *ktpd, faux_msg_t *msg)
 
 	// Get tty information from auth message status
 	client_status = faux_msg_get_status(msg);
-	ksession_set_isatty_stdin(ktpd->session,
+	ksession_set_isatty_std_in(ktpd->session,
 		KTP_STATUS_IS_TTY_STDIN(client_status));
-	ksession_set_isatty_stdout(ktpd->session,
+	ksession_set_isatty_std_out(ktpd->session,
 		KTP_STATUS_IS_TTY_STDOUT(client_status));
-	ksession_set_isatty_stderr(ktpd->session,
+	ksession_set_isatty_std_err(ktpd->session,
 		KTP_STATUS_IS_TTY_STDERR(client_status));
 
 	// init session for plugins
@@ -423,7 +423,7 @@ static bool_t ktpd_session_process_cmd(ktpd_session_t *ktpd, faux_msg_t *msg)
 		ktp_status_e status = KTP_STATUS_INCOMPLETED;
 		if (kexec_interactive(ktpd->exec))
 			status |= KTP_STATUS_INTERACTIVE;
-		if (kexec_need_stdin(ktpd->exec))
+		if (kexec_need_std_in(ktpd->exec))
 			status |= KTP_STATUS_NEED_STDIN;
 		ack = ktp_msg_preform(cmd, status);
 		faux_msg_send_async(ack, ktpd->async);
@@ -520,14 +520,14 @@ static bool_t ktpd_session_exec(ktpd_session_t *ktpd, const char *line,
 
 	// Set stdin, stdout, stderr handlers. It's so complex because stdin,
 	// stdout and stderr actually can be the same fd
-	faux_eloop_add_fd(ktpd->eloop, kexec_stdin(exec), 0,
-		action_stdout_ev, ktpd);
-	faux_eloop_add_fd(ktpd->eloop, kexec_stdout(exec), 0,
-		action_stdout_ev, ktpd);
-	faux_eloop_add_fd(ktpd->eloop, kexec_stderr(exec), 0,
-		action_stderr_ev, ktpd);
-	faux_eloop_include_fd_event(ktpd->eloop, kexec_stdout(exec), POLLIN);
-	faux_eloop_include_fd_event(ktpd->eloop, kexec_stderr(exec), POLLIN);
+	faux_eloop_add_fd(ktpd->eloop, kexec_std_in(exec), 0,
+		action_std_out_ev, ktpd);
+	faux_eloop_add_fd(ktpd->eloop, kexec_std_out(exec), 0,
+		action_std_out_ev, ktpd);
+	faux_eloop_add_fd(ktpd->eloop, kexec_std_err(exec), 0,
+		action_std_err_ev, ktpd);
+	faux_eloop_include_fd_event(ktpd->eloop, kexec_std_out(exec), POLLIN);
+	faux_eloop_include_fd_event(ktpd->eloop, kexec_std_err(exec), POLLIN);
 
 	return BOOL_TRUE;
 }
@@ -566,11 +566,11 @@ static bool_t wait_for_actions_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	// Sometimes SIGCHILD signal can appear before all data were really read
 	// from process stdout buffer. So read the least data before closing
 	// file descriptors and send it to client.
-	get_stream(ktpd, ktpd->exec, kexec_stdout(ktpd->exec), BOOL_FALSE, BOOL_TRUE);
-	get_stream(ktpd, ktpd->exec, kexec_stderr(ktpd->exec), BOOL_TRUE, BOOL_TRUE);
-	faux_eloop_del_fd(eloop, kexec_stdin(ktpd->exec));
-	faux_eloop_del_fd(eloop, kexec_stdout(ktpd->exec));
-	faux_eloop_del_fd(eloop, kexec_stderr(ktpd->exec));
+	get_stream(ktpd, ktpd->exec, kexec_std_out(ktpd->exec), BOOL_FALSE, BOOL_TRUE);
+	get_stream(ktpd, ktpd->exec, kexec_std_err(ktpd->exec), BOOL_TRUE, BOOL_TRUE);
+	faux_eloop_del_fd(eloop, kexec_std_in(ktpd->exec));
+	faux_eloop_del_fd(eloop, kexec_std_out(ktpd->exec));
+	faux_eloop_del_fd(eloop, kexec_std_err(ktpd->exec));
 
 	ktpd_session_log(ktpd, ktpd->exec);
 	view_was_changed = !kpath_is_equal(
@@ -958,7 +958,7 @@ static bool_t ktpd_session_process_help(ktpd_session_t *ktpd, faux_msg_t *msg)
 }
 
 
-static ssize_t stdin_out(int fd, faux_buf_t *buf, bool_t process_all_data)
+static ssize_t std_in_out(int fd, faux_buf_t *buf, bool_t process_all_data)
 {
 	ssize_t total_written = 0;
 
@@ -1002,7 +1002,7 @@ static ssize_t stdin_out(int fd, faux_buf_t *buf, bool_t process_all_data)
 }
 
 
-static bool_t push_stdin(ktpd_session_t *ktpd)
+static bool_t push_std_in(ktpd_session_t *ktpd)
 {
 	faux_buf_t *bufin = NULL;
 	int fd = -1;
@@ -1011,13 +1011,13 @@ static bool_t push_stdin(ktpd_session_t *ktpd)
 		return BOOL_TRUE;
 	if (!ktpd->exec)
 		return BOOL_TRUE;
-	fd = kexec_stdin(ktpd->exec);
+	fd = kexec_std_in(ktpd->exec);
 	if (fd < 0) // May be fd is already closed
 		return BOOL_FALSE;
 
 	bufin = kexec_bufin(ktpd->exec);
 	assert(bufin);
-	stdin_out(fd, bufin, BOOL_FALSE); // Non-blocking write
+	std_in_out(fd, bufin, BOOL_FALSE); // Non-blocking write
 	// Restore data receiving from client
 	if (faux_buf_len(bufin) < BUF_LIMIT)
 		faux_eloop_include_fd_event(ktpd->eloop,
@@ -1027,16 +1027,16 @@ static bool_t push_stdin(ktpd_session_t *ktpd)
 
 	// All data is written
 	faux_eloop_exclude_fd_event(ktpd->eloop, fd, POLLOUT);
-	if (ktpd->stdin_must_be_closed) {
+	if (ktpd->std_in_must_be_closed) {
 		close(fd);
-//		kexec_set_stdin(ktpd->exec, -1);
+//		kexec_set_std_in(ktpd->exec, -1);
 	}
 
 	return BOOL_TRUE;
 }
 
 
-static bool_t ktpd_session_process_stdin(ktpd_session_t *ktpd, faux_msg_t *msg)
+static bool_t ktpd_session_process_std_in(ktpd_session_t *ktpd, faux_msg_t *msg)
 {
 	char *line = NULL;
 	unsigned int len = 0;
@@ -1050,7 +1050,7 @@ static bool_t ktpd_session_process_stdin(ktpd_session_t *ktpd, faux_msg_t *msg)
 
 	if (!ktpd->exec)
 		return BOOL_FALSE;
-	fd = kexec_stdin(ktpd->exec);
+	fd = kexec_std_in(ktpd->exec);
 	if (fd < 0)
 		return BOOL_FALSE;
 
@@ -1085,7 +1085,7 @@ static bool_t ktpd_session_process_stdin(ktpd_session_t *ktpd, faux_msg_t *msg)
 		faux_buf_write(bufin, line, len);
 	}
 
-	stdin_out(fd, bufin, BOOL_FALSE); // Non-blocking write
+	std_in_out(fd, bufin, BOOL_FALSE); // Non-blocking write
 	if (faux_buf_len(bufin) == 0)
 		return BOOL_TRUE;
 
@@ -1153,7 +1153,7 @@ static bool_t ktpd_session_process_notification(ktpd_session_t *ktpd, faux_msg_t
 }
 
 
-static bool_t ktpd_session_process_stdin_close(ktpd_session_t *ktpd,
+static bool_t ktpd_session_process_std_in_close(ktpd_session_t *ktpd,
 	faux_msg_t *msg)
 {
 	int fd = -1;
@@ -1163,18 +1163,18 @@ static bool_t ktpd_session_process_stdin_close(ktpd_session_t *ktpd,
 
 	if (!ktpd->exec)
 		return BOOL_FALSE;
-	fd = kexec_stdin(ktpd->exec);
+	fd = kexec_std_in(ktpd->exec);
 	if (fd < 0)
 		return BOOL_FALSE;
 	// Schedule to close stdin
-	ktpd->stdin_must_be_closed = BOOL_TRUE;
-	push_stdin(ktpd);
+	ktpd->std_in_must_be_closed = BOOL_TRUE;
+	push_std_in(ktpd);
 
 	return BOOL_TRUE;
 }
 
 
-static bool_t ktpd_session_process_stdout_close(ktpd_session_t *ktpd,
+static bool_t ktpd_session_process_std_out_close(ktpd_session_t *ktpd,
 	faux_msg_t *msg)
 {
 	int fd = -1;
@@ -1184,7 +1184,7 @@ static bool_t ktpd_session_process_stdout_close(ktpd_session_t *ktpd,
 
 	if (!ktpd->exec)
 		return BOOL_FALSE;
-	fd = kexec_stdout(ktpd->exec);
+	fd = kexec_std_out(ktpd->exec);
 	if (fd < 0)
 		return BOOL_FALSE;
 	close(fd);
@@ -1196,7 +1196,7 @@ static bool_t ktpd_session_process_stdout_close(ktpd_session_t *ktpd,
 }
 
 
-static bool_t ktpd_session_process_stderr_close(ktpd_session_t *ktpd,
+static bool_t ktpd_session_process_std_err_close(ktpd_session_t *ktpd,
 	faux_msg_t *msg)
 {
 	int fd = -1;
@@ -1206,7 +1206,7 @@ static bool_t ktpd_session_process_stderr_close(ktpd_session_t *ktpd,
 
 	if (!ktpd->exec)
 		return BOOL_FALSE;
-	fd = kexec_stderr(ktpd->exec);
+	fd = kexec_std_err(ktpd->exec);
 	if (fd < 0)
 		return BOOL_FALSE;
 	close(fd);
@@ -1271,7 +1271,7 @@ static bool_t ktpd_session_dispatch(ktpd_session_t *ktpd, faux_msg_t *msg)
 			err = "Nobody is waiting for stdin";
 			break;
 		}
-		ktpd_session_process_stdin(ktpd, msg);
+		ktpd_session_process_std_in(ktpd, msg);
 		break;
 	case KTP_NOTIFICATION:
 		ktpd_session_process_notification(ktpd, msg);
@@ -1281,21 +1281,21 @@ static bool_t ktpd_session_dispatch(ktpd_session_t *ktpd, faux_msg_t *msg)
 //			err = "No active command is running (closing stdin)";
 			break;
 		}
-		ktpd_session_process_stdin_close(ktpd, msg);
+		ktpd_session_process_std_in_close(ktpd, msg);
 		break;
 	case KTP_STDOUT_CLOSE:
 		if (ktpd->state != KTPD_SESSION_STATE_WAIT_FOR_PROCESS) {
 //			err = "No active command is running (closing stdout)";
 			break;
 		}
-		ktpd_session_process_stdout_close(ktpd, msg);
+		ktpd_session_process_std_out_close(ktpd, msg);
 		break;
 	case KTP_STDERR_CLOSE:
 		if (ktpd->state != KTPD_SESSION_STATE_WAIT_FOR_PROCESS) {
 //			err = "No active command is running (closing stderr)";
 			break;
 		}
-		ktpd_session_process_stderr_close(ktpd, msg);
+		ktpd_session_process_std_err_close(ktpd, msg);
 		break;
 	default:
 		syslog(LOG_WARNING, "Unsupported command: 0x%04x", cmd);
@@ -1401,7 +1401,7 @@ int ktpd_session_fd(const ktpd_session_t *ktpd)
 }
 
 
-static bool_t get_stream(ktpd_session_t *ktpd, kexec_t *exec, int fd, bool_t is_stderr,
+static bool_t get_stream(ktpd_session_t *ktpd, kexec_t *exec, int fd, bool_t is_std_err,
 	bool_t process_all_data)
 {
 	ssize_t r = -1;
@@ -1415,7 +1415,7 @@ static bool_t get_stream(ktpd_session_t *ktpd, kexec_t *exec, int fd, bool_t is_
 	if (!exec)
 		return BOOL_TRUE;
 
-	if (is_stderr)
+	if (is_std_err)
 		faux_buf = kexec_buferr(exec);
 	else
 		faux_buf = kexec_bufout(exec);
@@ -1445,7 +1445,7 @@ static bool_t get_stream(ktpd_session_t *ktpd, kexec_t *exec, int fd, bool_t is_
 	faux_buf_read(faux_buf, buf, len);
 
 	// Create KTP_STDOUT/KTP_STDERR message to send to client
-	ack = ktp_msg_preform(is_stderr ? KTP_STDERR : KTP_STDOUT, KTP_STATUS_NONE);
+	ack = ktp_msg_preform(is_std_err ? KTP_STDERR : KTP_STDOUT, KTP_STATUS_NONE);
 	faux_msg_add_param(ack, KTP_PARAM_LINE, buf, len);
 	faux_msg_send_async(ack, ktpd->async);
 	faux_msg_free(ack);
@@ -1461,7 +1461,7 @@ static bool_t get_stream(ktpd_session_t *ktpd, kexec_t *exec, int fd, bool_t is_
 }
 
 
-static bool_t action_stdout_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
+static bool_t action_std_out_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	void *associated_data, void *user_data)
 {
 	faux_eloop_info_fd_t *info = (faux_eloop_info_fd_t *)associated_data;
@@ -1471,7 +1471,7 @@ static bool_t action_stdout_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	// getting stdout but for writing stdin too. Because pseudo-terminal
 	// uses the same fd for in and out.
 	if (info->revents & POLLOUT)
-		push_stdin(ktpd);
+		push_std_in(ktpd);
 
 	if (info->revents & POLLIN)
 		get_stream(ktpd, ktpd->exec, info->fd, BOOL_FALSE, BOOL_FALSE);
@@ -1487,7 +1487,7 @@ static bool_t action_stdout_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 }
 
 
-static bool_t action_stderr_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
+static bool_t action_std_err_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	void *associated_data, void *user_data)
 {
 	faux_eloop_info_fd_t *info = (faux_eloop_info_fd_t *)associated_data;
@@ -1530,9 +1530,9 @@ bool_t client_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 		if (ktpd->exec &&
 			faux_buf_len(faux_async_obuf(async)) < BUF_LIMIT) {
 			faux_eloop_include_fd_event(ktpd->eloop,
-				kexec_stdout(ktpd->exec), POLLIN);
+				kexec_std_out(ktpd->exec), POLLIN);
 			faux_eloop_include_fd_event(ktpd->eloop,
-				kexec_stderr(ktpd->exec), POLLIN);
+				kexec_std_err(ktpd->exec), POLLIN);
 		}
 	}
 

+ 8 - 8
klish/ktp_session.h

@@ -69,9 +69,9 @@ typedef enum {
 	KTP_SESSION_CB_MAX,
 } ktp_session_cb_e;
 
-typedef bool_t (*ktp_session_stdin_cb_fn)(ktp_session_t *ktp,
+typedef bool_t (*ktp_session_std_in_cb_fn)(ktp_session_t *ktp,
 	size_t len, void *udata);
-typedef bool_t (*ktp_session_stdout_cb_fn)(ktp_session_t *ktp,
+typedef bool_t (*ktp_session_std_out_cb_fn)(ktp_session_t *ktp,
 	const char *line, size_t len, void *udata);
 typedef bool_t (*ktp_session_event_cb_fn)(ktp_session_t *ktp,
 	const faux_msg_t *msg, void *udata);
@@ -98,14 +98,14 @@ bool_t ktp_session_auth(ktp_session_t *ktp, faux_error_t *error);
 bool_t ktp_session_completion(ktp_session_t *ktp, const char *line,
 	bool_t dry_run);
 bool_t ktp_session_help(ktp_session_t *ktp, const char *line);
-bool_t ktp_session_stdin(ktp_session_t *ktp, const char *line, size_t line_len);
-bool_t ktp_session_stdin_close(ktp_session_t *ktp);
-bool_t ktp_session_stdout_close(ktp_session_t *ktp);
-bool_t ktp_session_stderr_close(ktp_session_t *ktp);
+bool_t ktp_session_std_in(ktp_session_t *ktp, const char *line, size_t line_len);
+bool_t ktp_session_std_in_close(ktp_session_t *ktp);
+bool_t ktp_session_std_out_close(ktp_session_t *ktp);
+bool_t ktp_session_std_err_close(ktp_session_t *ktp);
 bool_t ktp_session_retcode(ktp_session_t *ktp, int *retcode);
 ktp_status_e ktp_session_cmd_features(const ktp_session_t *ktp);
-bool_t ktp_session_stdout_need_newline(ktp_session_t *ktp);
-bool_t ktp_session_stderr_need_newline(ktp_session_t *ktp);
+bool_t ktp_session_std_out_need_newline(ktp_session_t *ktp);
+bool_t ktp_session_std_err_need_newline(ktp_session_t *ktp);
 int ktp_session_last_stream(ktp_session_t *ktp);