summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorRodrigo G. López <r.gonzalez@telfy.com>2021-10-14 14:04:54 +0200
committerRodrigo G. López <r.gonzalez@telfy.com>2021-10-14 14:04:54 +0200
commit0388142877654e7b0a420f8e63b4a3153644aee4 (patch)
tree58ec31680f5c42033ce1ea99990cde3090792f96 /main.c
downloadparamedic-0388142877654e7b0a420f8e63b4a3153644aee4.tar.gz
paramedic-0388142877654e7b0a420f8e63b4a3153644aee4.tar.bz2
paramedic-0388142877654e7b0a420f8e63b4a3153644aee4.zip
Initial commit.
Diffstat (limited to 'main.c')
-rw-r--r--main.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..6b6e15a
--- /dev/null
+++ b/main.c
@@ -0,0 +1,35 @@
+#define _GNU_SOURCE
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int
+main(int argc, char *argv[])
+{
+ char buf[1024];
+ int mfd, n, cs;
+
+ mfd = memfd_create("", MFD_CLOEXEC);
+ if(mfd < 0)
+ exit(1);
+
+ while((n = read(0, buf, sizeof buf)) > 0)
+ if(write(mfd, buf, n) != n)
+ exit(2);
+
+ switch(fork()){
+ case -1:
+ exit(3);
+ case 0:
+ snprintf(buf, sizeof buf, "/proc/self/fd/%d", mfd);
+ execl(buf, "", NULL);
+ exit(66);
+ default:
+ wait(&cs);
+ }
+ exit(cs);
+}