From bb35b997b8ecac9b81cebd7147de35d7052d3611 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 25 Mar 2020 11:26:48 +0100 Subject: [PATCH] New stdin2out utility as replacement for tail -f This little utility allows us to remove the noux instance for the log view of Sculpt OS. Issue #3696 --- .../libports/recipes/src/stdin2out/content.mk | 10 ++++++ repos/libports/recipes/src/stdin2out/hash | 1 + .../libports/recipes/src/stdin2out/used_apis | 2 ++ repos/libports/src/app/stdin2out/main.cc | 31 +++++++++++++++++++ repos/libports/src/app/stdin2out/target.mk | 3 ++ 5 files changed, 47 insertions(+) create mode 100644 repos/libports/recipes/src/stdin2out/content.mk create mode 100644 repos/libports/recipes/src/stdin2out/hash create mode 100644 repos/libports/recipes/src/stdin2out/used_apis create mode 100644 repos/libports/src/app/stdin2out/main.cc create mode 100644 repos/libports/src/app/stdin2out/target.mk diff --git a/repos/libports/recipes/src/stdin2out/content.mk b/repos/libports/recipes/src/stdin2out/content.mk new file mode 100644 index 000000000..296c5272a --- /dev/null +++ b/repos/libports/recipes/src/stdin2out/content.mk @@ -0,0 +1,10 @@ +MIRROR_FROM_REP_DIR := src/app/stdin2out + +content: $(MIRROR_FROM_REP_DIR) LICENSE + +$(MIRROR_FROM_REP_DIR): + $(mirror_from_rep_dir) + +LICENSE: + cp $(GENODE_DIR)/LICENSE $@ + diff --git a/repos/libports/recipes/src/stdin2out/hash b/repos/libports/recipes/src/stdin2out/hash new file mode 100644 index 000000000..2875e9695 --- /dev/null +++ b/repos/libports/recipes/src/stdin2out/hash @@ -0,0 +1 @@ +2020-03-25 35a1a6bf7235f21227af3c813c3527d26d06cffe diff --git a/repos/libports/recipes/src/stdin2out/used_apis b/repos/libports/recipes/src/stdin2out/used_apis new file mode 100644 index 000000000..0c483273a --- /dev/null +++ b/repos/libports/recipes/src/stdin2out/used_apis @@ -0,0 +1,2 @@ +libc +posix diff --git a/repos/libports/src/app/stdin2out/main.cc b/repos/libports/src/app/stdin2out/main.cc new file mode 100644 index 000000000..f6f08417c --- /dev/null +++ b/repos/libports/src/app/stdin2out/main.cc @@ -0,0 +1,31 @@ +/* + * \brief Utility for forwarding data to stdout by polling stdin + * \author Norman Feske + * \date 2020-03-25 + * + * This program fulfils the purpose of 'tail -f' for the log view of Sculpt OS. + */ + +/* + * Copyright (C) 2020 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#include + +extern "C" int main(int, char **) +{ + while (true) { + + char buffer[4096] { }; + + size_t bytes = read(STDIN_FILENO, buffer, sizeof(buffer)); + + if (bytes == 0) + sleep(2); + else + write(STDOUT_FILENO, buffer, bytes); + } +} diff --git a/repos/libports/src/app/stdin2out/target.mk b/repos/libports/src/app/stdin2out/target.mk new file mode 100644 index 000000000..37cc87731 --- /dev/null +++ b/repos/libports/src/app/stdin2out/target.mk @@ -0,0 +1,3 @@ +TARGET := stdin2out +SRC_CC := main.cc +LIBS += posix