diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2020-12-01 20:46:50 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2020-12-01 20:46:50 +0300 |
commit | 87189d3f65cb66c95f0be5c3fb213bdc5741e634 (patch) | |
tree | 71bee4d687d7270d0bcc80d646663534c81c9d4c /shelter.c | |
download | vsvs-87189d3f65cb66c95f0be5c3fb213bdc5741e634.tar vsvs-87189d3f65cb66c95f0be5c3fb213bdc5741e634.tar.xz vsvs-87189d3f65cb66c95f0be5c3fb213bdc5741e634.zip |
Initial
Diffstat (limited to 'shelter.c')
-rw-r--r-- | shelter.c | 31 |
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; +} |