Przeglądaj źródła

kexec: Retcode of kexec is a retcode of its first context

Serj Kalichev 2 lat temu
rodzic
commit
29e11398e8
3 zmienionych plików z 45 dodań i 0 usunięć
  1. 2 0
      klish/kexec.h
  2. 19 0
      klish/ksession/kexec.c
  3. 24 0
      klish/ksession/ksession.c

+ 2 - 0
klish/kexec.h

@@ -31,6 +31,8 @@ bool_t kexec_set_stdout(kexec_t *exec, int stdout);
 // STDERR
 int kexec_stderr(const kexec_t *exec);
 bool_t kexec_set_stderr(kexec_t *exec, int stderr);
+// Return code
+bool_t kexec_retcode(const kexec_t *exec, int *status);
 // CONTEXTs
 bool_t kexec_add_contexts(kexec_t *exec, kcontext_t *context);
 ssize_t kexec_contexts_len(const kexec_t *exec);

+ 19 - 0
klish/ksession/kexec.c

@@ -99,6 +99,25 @@ size_t kexec_is_empty(const kexec_t *exec)
 }
 
 
+// Retcode of kexec is a retcode of its first context execution because
+// next contexts just a filters.
+bool_t kexec_retcode(const kexec_t *exec, int *status)
+{
+	assert(exec);
+	if (!exec)
+		return BOOL_FALSE;
+
+	if (kexec_is_empty(exec))
+		return BOOL_FALSE;
+
+	if (status)
+		*status = kcontext_retcode(
+			(kcontext_t *)faux_list_data(faux_list_head(exec->contexts)));
+
+	return BOOL_TRUE;
+}
+
+
 bool_t kexec_add(kexec_t *exec, kcontext_t *context)
 {
 	assert(exec);

+ 24 - 0
klish/ksession/ksession.c

@@ -12,6 +12,7 @@
 #include <klish/kpath.h>
 #include <klish/kpargv.h>
 #include <klish/ksession.h>
+#include <klish/kexec.h>
 
 
 struct ksession_s {
@@ -79,3 +80,26 @@ void ksession_free(ksession_t *session)
 
 	free(session);
 }
+
+
+bool_t ksession_exec_locally(ksession_t *session, const char *line,
+	int status, faux_error_t *error)
+{
+	kexec_t *exec = NULL;
+
+	assert(session);
+	if (!session)
+		return BOOL_FALSE;
+
+	// Parsing
+	exec = ksession_parse_for_exec(session, line, error);
+	if (!exec)
+		return BOOL_FALSE;
+
+	kexec_exec(exec);
+
+
+	status = status;
+
+	return BOOL_TRUE;
+}