Browse Source

kexec: Execute syms as a sync action

Serj Kalichev 2 years ago
parent
commit
ec3f40d952
4 changed files with 31 additions and 2 deletions
  1. 7 2
      klish/ksession/kexec.c
  2. 22 0
      plugins/klish/misc.c
  3. 1 0
      plugins/klish/plugin_init.c
  4. 1 0
      plugins/klish/private.h

+ 7 - 2
klish/ksession/kexec.c

@@ -181,13 +181,18 @@ static int exec_action(kcontext_t *context, const kaction_t *action, pid_t *pid)
 {
 	context = context;
 	action = action;
+	ksym_fn fn;
+	int exitcode = 0;
 
 	if (pid)
 		*pid = -1;
 
-	printf("DDD: exec_action [%s]\n", kaction_script(action));
+//	printf("DDD: exec_action [%s]\n", kaction_script(action));
 
-	return 0;
+	fn = ksym_function(kaction_sym(action));
+	exitcode = fn(context);
+
+	return exitcode;
 }
 
 

+ 22 - 0
plugins/klish/misc.c

@@ -9,6 +9,8 @@
 #include <stdlib.h>
 #include <errno.h>
 
+#include <faux/str.h>
+#include <faux/list.h>
 #include <klish/kcontext.h>
 
 
@@ -18,3 +20,23 @@ int klish_nop(kcontext_t *context)
 
 	return 0;
 }
+
+
+// Symbol for testing purposes
+int klish_tsym(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)) {
+		printf("[<empty>]\n");
+		return -1;
+	}
+
+	printf("[%s]\n", script);
+
+	return 0;
+}

+ 1 - 0
plugins/klish/plugin_init.c

@@ -26,6 +26,7 @@ int kplugin_klish_init(kcontext_t *context)
 	assert(plugin);
 
 	kplugin_add_syms(plugin, ksym_new("nop", klish_nop));
+	kplugin_add_syms(plugin, ksym_new("tsym", klish_tsym));
 
 //	fprintf(stderr, "Plugin 'klish' init\n");
 	context = context; // Happy compiler

+ 1 - 0
plugins/klish/private.h

@@ -12,6 +12,7 @@
 C_DECL_BEGIN
 
 int klish_nop(kcontext_t *context);
+int klish_tsym(kcontext_t *context);
 
 C_DECL_END