diff mbox series

[3/3] handlers: pipe_handlers: add fail-cmd

Message ID 20210305053935.1786812-4-dominique.martinet@atmark-techno.com
State Changes Requested
Headers show
Series add pipe handler | expand

Commit Message

Dominique Martinet March 5, 2021, 5:39 a.m. UTC
Add a mechanism to run yet another command if the copy
failed.
This allows cleanup on error or if the checksum was invalid

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
 doc/source/handlers.rst | 4 ++++
 handlers/pipe_handler.c | 9 +++++++++
 2 files changed, 13 insertions(+)
diff mbox series

Patch

diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst
index 764e0d0d09a2..3f5e6e229217 100644
--- a/doc/source/handlers.rst
+++ b/doc/source/handlers.rst
@@ -868,6 +868,10 @@  is piped to the command which runs until the end, so if the checksum fails
 the harm has still been done and it is not recommended to modify data in place
 that way.
 
+If the "fail-cmd" property has been set, that command will be run if any error
+has been encountered (checksum error, error downloading or writing the file,
+or command returning a non-zero status code)
+
 
 ::
 
diff --git a/handlers/pipe_handler.c b/handlers/pipe_handler.c
index 5c6365614b5c..6a945c94f943 100644
--- a/handlers/pipe_handler.c
+++ b/handlers/pipe_handler.c
@@ -12,6 +12,7 @@ 
 #include "swupdate.h"
 #include "handler.h"
 #include "util.h"
+#include "pctl.h"
 
 struct pipe_priv {
 	pid_t pid;
@@ -215,6 +216,14 @@  static int pipe_image(struct img_type *img,
 	if (priv.stderr_index)
 		ERROR("%s", priv.stderr_buf);
 
+	/* run fail command if errored and set */
+	if (ret) {
+		cmd = dict_get_value(&img->properties, "fail-cmd");
+		if (cmd) {
+			run_system_cmd(cmd);
+		}
+	}
+
 	TRACE("finished piping image");
 	return ret;
 }