Browse Source

konfd: Fix unclosed stderr descriptor

Serj Kalichev 2 months ago
parent
commit
6e6b0bf010
5 changed files with 48 additions and 0 deletions
  1. 14 0
      klish/ktp/ktp.c
  2. 13 0
      klish/ktp/ktpd_session.c
  3. 19 0
      plugins/klish/misc.c
  4. 1 0
      plugins/klish/plugin_init.c
  5. 1 0
      plugins/klish/private.h

+ 14 - 0
klish/ktp/ktp.c

@@ -155,6 +155,20 @@ bool_t ktp_peer_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 		return BOOL_FALSE; // Stop event loop
 	}
 
+	// POLLERR
+	if (info->revents & POLLERR) {
+		faux_eloop_del_fd(eloop, info->fd);
+		syslog(LOG_DEBUG, "POLLERR received %d", info->fd);
+		return BOOL_FALSE; // Stop event loop
+	}
+
+	// POLLNVAL
+	if (info->revents & POLLNVAL) {
+		faux_eloop_del_fd(eloop, info->fd);
+		syslog(LOG_DEBUG, "POLLNVAL received %d", info->fd);
+		return BOOL_FALSE; // Stop event loop
+	}
+
 	type = type; // Happy compiler
 
 	return BOOL_TRUE;

+ 13 - 0
klish/ktp/ktpd_session.c

@@ -391,6 +391,7 @@ static bool_t wait_for_actions_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 		return BOOL_TRUE; // Continue
 
 	faux_eloop_del_fd(eloop, kexec_stdout(ktpd->exec));
+	faux_eloop_del_fd(eloop, kexec_stderr(ktpd->exec));
 
 	kexec_free(ktpd->exec);
 	ktpd->exec = NULL;
@@ -421,6 +422,12 @@ static bool_t action_stdout_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	ssize_t len = 0;
 	faux_msg_t *ack = NULL;
 
+	// Some errors or fd is closed so remove it from polling
+	if (!(info->revents & POLLIN)) {
+		faux_eloop_del_fd(eloop, info->fd);
+		return BOOL_TRUE;
+	}
+
 	if (!ktpd)
 		return BOOL_TRUE;
 	if (!ktpd->exec)
@@ -476,6 +483,12 @@ static bool_t action_stderr_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 	ssize_t len = 0;
 	faux_msg_t *ack = NULL;
 
+	// Some errors or fd is closed so remove it from polling
+	if (!(info->revents & POLLIN)) {
+		faux_eloop_del_fd(eloop, info->fd);
+		return BOOL_TRUE;
+	}
+
 	if (!ktpd)
 		return BOOL_TRUE;
 	if (!ktpd->exec)

+ 19 - 0
plugins/klish/misc.c

@@ -44,6 +44,25 @@ int klish_tsym(kcontext_t *context)
 	return 0;
 }
 
+
+// Print content of ACTION script
+int klish_print(kcontext_t *context)
+{
+	const kaction_t *action = NULL;
+	const char *script = NULL;
+
+	action = (kaction_t *)faux_list_data(kcontext_action_iter(context));
+
+	script = kaction_script(action);
+	if (faux_str_is_empty(script))
+		script = "";
+
+	printf("%s\n", script);
+
+	return 0;
+}
+
+
 // Symbol to show current path
 int klish_pwd(kcontext_t *context)
 {

+ 1 - 0
plugins/klish/plugin_init.c

@@ -30,6 +30,7 @@ int kplugin_klish_init(kcontext_t *context)
 	kplugin_add_syms(plugin, ksym_new_ext("nop", klish_nop,
 		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
 	kplugin_add_syms(plugin, ksym_new("tsym", klish_tsym));
+	kplugin_add_syms(plugin, ksym_new("print", klish_print));
 	kplugin_add_syms(plugin, ksym_new_ext("pwd", klish_pwd,
 		KSYM_PERMANENT, KSYM_SYNC));
 

+ 1 - 0
plugins/klish/private.h

@@ -14,6 +14,7 @@ C_DECL_BEGIN
 // Misc
 int klish_nop(kcontext_t *context);
 int klish_tsym(kcontext_t *context);
+int klish_print(kcontext_t *context);
 int klish_pwd(kcontext_t *context);
 
 // Navigation