summaryrefslogtreecommitdiff
path: root/shelter.c
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2020-12-01 20:46:50 +0300
committerAleksey Veresov <aleksey@veresov.pro>2020-12-01 20:46:50 +0300
commit87189d3f65cb66c95f0be5c3fb213bdc5741e634 (patch)
tree71bee4d687d7270d0bcc80d646663534c81c9d4c /shelter.c
downloadvsvs-87189d3f65cb66c95f0be5c3fb213bdc5741e634.tar
vsvs-87189d3f65cb66c95f0be5c3fb213bdc5741e634.tar.xz
vsvs-87189d3f65cb66c95f0be5c3fb213bdc5741e634.zip
Initial
Diffstat (limited to 'shelter.c')
-rw-r--r--shelter.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/shelter.c b/shelter.c
new file mode 100644
index 0000000..e8bdf9f
--- /dev/null
+++ b/shelter.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+
+int main()
+{
+ int p[2];
+ pid_t pid;
+ pipe(p);
+ pid = fork();
+ if (pid == -1) {
+ return 1;
+ } else if (pid) {
+ int c;
+ close(p[0]);
+ write(p[1], "echo -n \"", 6);
+ while ((c = getchar()) != EOF) {
+ write(p[1], &c, 1);
+ }
+ write(p[1], "\"", 1);
+ close(p[1]);
+ wait(0);
+ } else {
+ close(p[1]);
+ dup2(p[0], 0);
+ close(p[0]);
+ execl("/bin/sh", "/bin/sh", 0);
+ }
+ return 0;
+}