json_script: add support for aborting script processing
authorFelix Fietkau <nbd@openwrt.org>
Fri, 6 Nov 2015 21:58:15 +0000 (22:58 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Fri, 6 Nov 2015 21:58:15 +0000 (22:58 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
json_script.c
json_script.h

index 73c25022e11c8d42e23077c8b08146b28ba30abd..22d841761e37979c265e4990d69e61b2db575e02 100644 (file)
@@ -541,6 +541,9 @@ static int json_process_cmd(struct json_call *call, struct blob_attr *block)
        }
 
        blobmsg_for_each_attr(cur, block, rem) {
+               if (ctx->abort)
+                       break;
+
                switch(blobmsg_type(cur)) {
                case BLOBMSG_TYPE_STRING:
                        if (!i)
@@ -571,6 +574,8 @@ void json_script_run_file(struct json_script_ctx *ctx, struct json_script_file *
        if (!call.seq)
                call.seq = ++_seq;
 
+       ctx->abort = false;
+
        __json_script_run(&call, file, NULL);
 }
 
index 9475baa59507f8284048386fe8fd152192d6146d..66563e9de4350a6ef6c3e03b797b43ca5b9b924d 100644 (file)
@@ -28,6 +28,7 @@ struct json_script_ctx {
        struct blob_buf buf;
 
        uint32_t run_seq;
+       bool abort;
 
        /*
         * handle_command: handle a command that was not recognized by the
@@ -99,6 +100,18 @@ void json_script_run(struct json_script_ctx *ctx, const char *filename,
 
 void json_script_run_file(struct json_script_ctx *ctx, struct json_script_file *file,
                          struct blob_attr *vars);
+
+/*
+ * json_script_abort - abort current json script run
+ *
+ * to be called from a script context callback
+ */
+static inline void
+json_script_abort(struct json_script_ctx *ctx)
+{
+       ctx->abort = true;
+}
+
 /*
  * json_script_eval_string - evaluate a string and store the result
  *