[rtems-libbsd commit] vprintf: Add handler that mutes all output.

Christian Mauderer christianm at rtems.org
Fri Mar 23 08:37:53 UTC 2018


Module:    rtems-libbsd
Branch:    master
Commit:    7ec935e03f13baa899ab62f5c8348eec5ca35e5c
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=7ec935e03f13baa899ab62f5c8348eec5ca35e5c

Author:    Christian Mauderer <christian.mauderer at embedded-brains.de>
Date:      Fri Mar 23 07:58:18 2018 +0100

vprintf: Add handler that mutes all output.

This adds a vprintf handler that can be used to suppress all outputs of
the libbsd.

---

 libbsd.txt                            | 24 ++++++++++++++++++++++++
 rtemsbsd/include/rtems/bsd/bsd.h      |  9 +++++++++
 rtemsbsd/rtems/rtems-kernel-vprintf.c | 10 ++++++++++
 3 files changed, 43 insertions(+)

diff --git a/libbsd.txt b/libbsd.txt
index f66a41b..e7a9f78 100644
--- a/libbsd.txt
+++ b/libbsd.txt
@@ -265,6 +265,30 @@ their own implementation of the `rtems_bsd_get_allocator_domain_size()`
 function (for example in the module which calls `rtems_bsd_initialize()`) if
 different values are desired.  The default size is 8MiB for all domains.
 
+=== Redirecting or Disabling the Output ===
+
+A lot of system messages are printed to the stdout by default. If you want to
+redirect them you can overwrite the default print handler. That can even be done
+before the libbsd initialization to catch all messages. An example would look
+like follows:
+
+-------------------------------------------------------------------------------
+int my_vprintf_handler(int level, const char *fmt, va_list ap) {
+	/* Do something with the messages. */
+
+	return number_of_printed_chars;
+}
+
+...
+	/* In your initialization: */
+	rtems_bsd_vprintf_handler old;
+	old = rtems_bsd_set_vprintf_handler(my_vprintf_handler);
+...
+-------------------------------------------------------------------------------
+
+As a special case, you can set the `rtems_bsd_vprintf_handler_mute(...)`
+provided by libbsd to suppress all output.
+
 == Network Stack Features
 
 http://roy.marples.name/projects/dhcpcd/index[DHCPCD(8)]:: DHCP client
diff --git a/rtemsbsd/include/rtems/bsd/bsd.h b/rtemsbsd/include/rtems/bsd/bsd.h
index 19428a5..cec14ac 100755
--- a/rtemsbsd/include/rtems/bsd/bsd.h
+++ b/rtemsbsd/include/rtems/bsd/bsd.h
@@ -294,6 +294,15 @@ int rtems_bsd_vprintf(int level, const char *fmt, va_list ap);
  */
 int rtems_bsd_setlogpriority(const char* priority);
 
+/**
+ * @brief Set this vprintf handler to suppress all output.
+ *
+ * @retval Allways 0.
+ *
+ * @see rtems_bsd_vprintf() for the parameters.
+ */
+int rtems_bsd_vprintf_handler_mute(int level, const char *fmt, va_list ap);
+
 /** @} */
 
 #ifdef __cplusplus
diff --git a/rtemsbsd/rtems/rtems-kernel-vprintf.c b/rtemsbsd/rtems/rtems-kernel-vprintf.c
index 7364ec6..29dc1ff 100644
--- a/rtemsbsd/rtems/rtems-kernel-vprintf.c
+++ b/rtemsbsd/rtems/rtems-kernel-vprintf.c
@@ -103,6 +103,16 @@ default_vprintf_handler(int level, const char *fmt, va_list ap)
 static int (*vprintf_handler)(int, const char *, va_list) =
     default_vprintf_handler;
 
+int
+rtems_bsd_vprintf_handler_mute(int level, const char *fmt, va_list ap)
+{
+	(void) level;
+	(void) fmt;
+	(void) ap;
+
+	return 0;
+}
+
 rtems_bsd_vprintf_handler
 rtems_bsd_set_vprintf_handler(rtems_bsd_vprintf_handler new_handler)
 {




More information about the vc mailing list