diff mbox series

[1/2] handlers: add a dummy handler

Message ID 1525942370-17439-1-git-send-email-sbabic@denx.de
State Accepted
Headers show
Series [1/2] handlers: add a dummy handler | expand

Commit Message

Stefano Babic May 10, 2018, 8:52 a.m. UTC
This handler skip an installation and it is thought
to provide a dry-to-run.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 handlers/Makefile        |  1 +
 handlers/dummy_handler.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
 create mode 100644 handlers/dummy_handler.c
diff mbox series

Patch

diff --git a/handlers/Makefile b/handlers/Makefile
index 0b5aa26..f9a82ed 100644
--- a/handlers/Makefile
+++ b/handlers/Makefile
@@ -7,6 +7,7 @@ 
 # not drop the handler if it is not called.
 # Handler can be called dynamically based
 # on the received image type.
+obj-y	+= dummy_handler.o
 obj-$(CONFIG_ARCHIVE) += archive_handler.o
 obj-$(CONFIG_CFI)	+= flash_handler.o
 obj-$(CONFIG_CFIHAMMING1)+= flash_hamming1_handler.o
diff --git a/handlers/dummy_handler.c b/handlers/dummy_handler.c
new file mode 100644
index 0000000..98a1962
--- /dev/null
+++ b/handlers/dummy_handler.c
@@ -0,0 +1,52 @@ 
+/*
+ * (C) Copyright 2013
+ * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
+ * 	on behalf of ifm electronic GmbH
+ *
+ * SPDX-License-Identifier:     GPL-2.0-or-later
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include "swupdate.h"
+#include "handler.h"
+#include "util.h"
+
+void dummy_handler(void);
+
+static int install_nothing(struct img_type *img,
+	void __attribute__ ((__unused__)) *data)
+{
+	int ret;
+	int fdout;
+
+	if (img->is_partitioner | img->is_script)
+		return 0;
+
+	fdout = open("/dev/null", O_WRONLY);
+	if (fdout < 0) {
+		TRACE("Device %s cannot be opened: %s",
+				"/dev/null", strerror(errno));
+		return -1;
+	}
+
+	ret = copyimage(&fdout, img, NULL);
+
+	close(fdout);
+	return ret;
+}
+
+__attribute__((constructor))
+void dummy_handler(void)
+{
+	register_handler("dummy", install_nothing,
+				IMAGE_HANDLER |
+				FILE_HANDLER |
+				SCRIPT_HANDLER |
+				PARTITION_HANDLER,
+				NULL);
+}