Browse Source

Execute log callback

Serj Kalichev 5 months ago
parent
commit
466c20446b
2 changed files with 22 additions and 4 deletions
  1. 4 1
      klish/ksession/ksession_parse.c
  2. 18 3
      klish/ktp/ktpd_session.c

+ 4 - 1
klish/ksession/ksession_parse.c

@@ -611,6 +611,7 @@ kexec_t *ksession_parse_for_exec(ksession_t *session, const char *raw_line,
 		faux_argv_t *argv = (faux_argv_t *)faux_list_data(iter);
 		kcontext_t *context = NULL;
 		bool_t is_first = (iter == faux_list_head(split));
+		char *context_line = NULL;
 
 		pargv = ksession_parse_line(session, argv, KPURPOSE_EXEC, !is_first);
 		// All components must be ready for execution
@@ -628,7 +629,9 @@ kexec_t *ksession_parse_for_exec(ksession_t *session, const char *raw_line,
 		kcontext_set_pargv(context, pargv);
 		// Context for ACTION execution contains session
 		kcontext_set_session(context, session);
-		kcontext_set_line(context, faux_argv_line(argv));
+		context_line = faux_argv_line(argv);
+		kcontext_set_line(context, context_line);
+		faux_str_free(context_line);
 		kcontext_set_pipeline_stage(context, index);
 		kexec_add_contexts(exec, context);
 

+ 18 - 3
klish/ktp/ktpd_session.c

@@ -565,10 +565,25 @@ static bool_t wait_for_actions_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
 
 static bool_t ktpd_session_log(ktpd_session_t *ktpd, const kexec_t *exec)
 {
-	fprintf(stderr, "LOG\n");
+	kexec_contexts_node_t *iter = NULL;
+	kcontext_t *context = NULL;
+
+	iter = kexec_contexts_iter(exec);
+	while ((context = kexec_contexts_each(&iter))) {
+		const kentry_t *entry = kcontext_command(context);
+		const kentry_t *log_entry = NULL;
+		int rc = -1;
 
-	ktpd = ktpd;
-	exec = exec;
+		if (!entry)
+			continue;
+		log_entry = kentry_nested_by_purpose(entry, KENTRY_PURPOSE_LOG);
+		if (!log_entry)
+			continue;
+		if (kentry_actions_len(log_entry) == 0)
+			continue;
+		ksession_exec_locally(ktpd->session, log_entry,
+			kcontext_pargv(context), context, exec, &rc, NULL);
+	}
 
 	return BOOL_TRUE;
 }