mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-18 18:56:29 +00:00
Standalone POSIX pipe utility
Pipe between files using POSIX stdio. This facilitates raw transfers between arbitrary resources exposed by the VFS library. Fix #2708
This commit is contained in:
parent
f294ec608e
commit
f27953c48d
2
repos/gems/recipes/src/pipe/content.mk
Normal file
2
repos/gems/recipes/src/pipe/content.mk
Normal file
@ -0,0 +1,2 @@
|
||||
SRC_DIR = src/app/pipe
|
||||
include $(GENODE_DIR)/repos/base/recipes/src/content.inc
|
1
repos/gems/recipes/src/pipe/hash
Normal file
1
repos/gems/recipes/src/pipe/hash
Normal file
@ -0,0 +1 @@
|
||||
-
|
3
repos/gems/recipes/src/pipe/used_apis
Normal file
3
repos/gems/recipes/src/pipe/used_apis
Normal file
@ -0,0 +1,3 @@
|
||||
base
|
||||
libc
|
||||
posix
|
40
repos/gems/run/pipe.run
Normal file
40
repos/gems/run/pipe.run
Normal file
@ -0,0 +1,40 @@
|
||||
create_boot_directory
|
||||
|
||||
install_config {
|
||||
<config>
|
||||
<parent-provides>
|
||||
<service name="CPU"/>
|
||||
<service name="IO_MEM"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="LOG"/>
|
||||
<service name="PD"/>
|
||||
<service name="RM"/>
|
||||
<service name="ROM"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</default-route>
|
||||
<start name="pipe" caps="128">
|
||||
<resource name="RAM" quantum="2M"/>
|
||||
<config>
|
||||
<vfs>
|
||||
<rom name="config"/>
|
||||
<dir name="dev"> <log/> </dir>
|
||||
</vfs>
|
||||
<libc stdin="/config" stdout="/dev/log"/>
|
||||
</config>
|
||||
</start>
|
||||
</config>
|
||||
}
|
||||
|
||||
build "core init app/pipe"
|
||||
|
||||
build_boot_image {
|
||||
core init pipe
|
||||
ld.lib.so libc.lib.so libm.lib.so posix.lib.so
|
||||
}
|
||||
|
||||
append qemu_args " -nographic "
|
||||
|
||||
run_genode_until "child .* exited with exit value 0.*\n" 10
|
15
repos/gems/src/app/pipe/README
Normal file
15
repos/gems/src/app/pipe/README
Normal file
@ -0,0 +1,15 @@
|
||||
The pipe utility is for piping between files using the
|
||||
semantics of POSIX stdio.
|
||||
|
||||
An example of piping clock jitter to a terminal session:
|
||||
|
||||
! <start name="pipe">
|
||||
! <resource name="RAM" quantum="2M"/>
|
||||
! <config>
|
||||
! <vfs>
|
||||
! <jitterentropy name="rng"/>
|
||||
! <terminal name="tty"/>
|
||||
! </vfs>
|
||||
! <libc stdin="/rng" stdout="/tty"/>
|
||||
! </config>
|
||||
! </start>
|
59
repos/gems/src/app/pipe/main.cc
Normal file
59
repos/gems/src/app/pipe/main.cc
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* \brief Standalone POSIX pipe
|
||||
* \author Emery Hemingway
|
||||
* \date 2018-03-06
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 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.
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/log.h>
|
||||
|
||||
/* Libc includes */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
enum { SIXTEEN_K = 1 << 14 };
|
||||
static char buf[SIXTEEN_K];
|
||||
|
||||
Genode::uint64_t total = 0;
|
||||
|
||||
while (true) {
|
||||
|
||||
auto const nr = fread(buf, 1, sizeof(buf), stdin);
|
||||
if (nr == 0 && feof(stdin))
|
||||
break;
|
||||
|
||||
if (nr < 1 || nr > sizeof(buf)) {
|
||||
int res = errno;
|
||||
Genode::error((char const *)strerror(res));
|
||||
return res;
|
||||
}
|
||||
|
||||
auto remain = nr;
|
||||
auto off = 0;
|
||||
while (remain > 0) {
|
||||
auto const nw = fwrite(buf+off, 1, remain, stdout);
|
||||
if (nw < 1 || nw > remain) {
|
||||
int res = errno;
|
||||
Genode::error((char const *)strerror(res));
|
||||
return res;
|
||||
}
|
||||
|
||||
remain -= nw;
|
||||
off += nw;
|
||||
total += nw;
|
||||
}
|
||||
}
|
||||
|
||||
Genode::log("piped ", total, " bytes");
|
||||
return 0;
|
||||
};
|
3
repos/gems/src/app/pipe/target.mk
Normal file
3
repos/gems/src/app/pipe/target.mk
Normal file
@ -0,0 +1,3 @@
|
||||
TARGET = pipe
|
||||
SRC_CC = main.cc
|
||||
LIBS = base libc posix
|
Loading…
Reference in New Issue
Block a user