summaryrefslogtreecommitdiff
path: root/main.c
blob: 6b6e15ab4ef13121880ae39fe0c15797a024150a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
}