Browse Source

ACTION: exec_on and update_retcode attributes.

Serj Kalichev 3 years ago
parent
commit
0b8071ad30
3 changed files with 33 additions and 1 deletions
  1. 6 1
      bin/klishd/klishd.c
  2. 20 0
      klish.xsd
  3. 7 0
      klish/kaction.h

+ 6 - 1
bin/klishd/klishd.c

@@ -33,7 +33,7 @@
 #include <klish/ktp.h>
 #include <klish/ktp_session.h>
 
-#include <klish/kparam.h>
+#include <klish/kscheme.h>
 
 #include "private.h"
 
@@ -68,6 +68,7 @@ int main(int argc, char **argv)
 	faux_eloop_t *eloop = NULL;
 	int listen_unix_sock = -1;
 	ktpd_clients_t *clients = NULL;
+	kscheme_t *scheme = NULL;
 
 	struct timespec delayed = { .tv_sec = 10, .tv_nsec = 0 };
 	struct timespec period = { .tv_sec = 3, .tv_nsec = 0 };
@@ -130,6 +131,7 @@ int main(int argc, char **argv)
 	}
 
 	// Load scheme
+	scheme = kscheme_new();
 	{
 	kparam_t *param = NULL;
 	param = kparam_new_static((kparam_info_t){.name="PARAM", .help="This is param", .ptype = "STRING" });
@@ -191,6 +193,9 @@ err:
 		}
 	}
 
+	// Free scheme
+	kscheme_free(scheme);
+
 	// Free command line options
 	opts_free(opts);
 	syslog(LOG_INFO, "Stop daemon.\n");

+ 20 - 0
klish.xsd

@@ -403,8 +403,26 @@
 * [interactive="true/false"] - specify is action interactive. The
 *	interactive ACTIONs can't be used with piped ("|") output.
 *
+* [exec_on="fail/success/always"] - ACTION's execution depends on
+*	return code of previous elements of ACTION chain. If the
+*	condition is not met then ACTION will not be executed. The "always"
+*	value means that ACTION will be always executed and chain return
+*	code will be ignored. Default is "success".
+*
+* [upadate_retcode="true/false"] - The chain return value can be updated
+*	by current ACTION's return code or ACTION's return code can be ignored.
+*	Default is "true".
+*
 ********************************************************
 -->
+	<xs:simpleType name="action_cond_t">
+		<xs:restriction base="xs:string">
+			<xs:enumeration value="fail"/>
+			<xs:enumeration value="success"/>
+			<xs:enumeration value="always"/>
+		</xs:restriction>
+	</xs:simpleType>
+
 	<xs:complexType name="action_t">
 		<xs:simpleContent>
 			<xs:extension base="xs:string">
@@ -413,6 +431,8 @@
 				<xs:attribute name="lock" type="xs:boolean" use="optional" default="true"/>
 				<xs:attribute name="interrupt" type="xs:boolean" use="optional" default="false"/>
 				<xs:attribute name="interactive" type="xs:boolean" use="optional" default="false"/>
+				<xs:attribute name="exec_on" type="action_cond_t" use="optional" default="success"/>
+				<xs:attribute name="update_retcode" type="xs:boolean" use="optional" default="true"/>
 			</xs:extension>
 		</xs:simpleContent>
 	</xs:complexType>

+ 7 - 0
klish/kaction.h

@@ -15,6 +15,13 @@ typedef struct kaction_info_s {
 } kaction_info_t;
 
 
+typedef enum {
+	KACTION_COND_FAIL,
+	KACTION_COND_SUCCESS,
+	KACTION_COND_ALWAYS
+} kaction_chain_e;
+
+
 C_DECL_BEGIN
 
 kaction_t *kaction_new(kaction_info_t info);