Check-in [2d83a6231c]
Overview
Comment:Added start of docker init code
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2d83a6231c088594c0ba9af7592e2a028955ab50
User & Date: rkeene on 2017-10-30 18:03:28
Other Links: manifest | tags
Context
2017-10-30
18:03
Added an "install" command for setting up symlinks to binaries check-in: 8998f05e2e user: rkeene tags: trunk
18:03
Added start of docker init code check-in: 2d83a6231c user: rkeene tags: trunk
2017-02-23
22:31
Added script to build static AppFS packages check-in: 232fd3b1ce user: rkeene tags: trunk
Changes

Added build/docker/Dockerfile version [42acc0ed9e].











>
>
>
>
>
1
2
3
4
5
FROM scratch

COPY init appfsd /bin/

ENTRYPOINT ["/bin/init"]

Added build/docker/init.c version [ecb8eda1cf].































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>

int run(const char *path, ...) {
	va_list ap;
	char **argv;
	int argvMax, argvIdx;
	pid_t pid;
	int pidstat;

	pid = fork();
	if (pid == ((pid_t) -1)) {
		return(-1);
	}
	
	if (pid != 0) {
		waitpid(pid, &pidstat, 0);

		return(pidstat);
	}

	argvMax = 32;
	argv = malloc(sizeof(*argv) * argvMax);

	va_start(ap, path);

	for (argvIdx = 0; argvIdx < argvMax; argvIdx++) {
		argv[argvIdx] = va_arg(ap, char *);
		if (argv[argvIdx] == NULL) {
			break;
		}
	}
	
	va_end(ap);

	execv(path, argv);

	exit(EXIT_FAILURE);
}

int main(int argc, char **argv) {
	if (access("/dev/fuse", F_OK) != 0) {
		fprintf(stderr, "This container needs to be run as:  docker run --cap-add SYS_ADMIN --device /dev/fuse ...\n");

		return(1);
	}

	mkdir("/bin", 0755);
	mkdir("/opt", 0755);
	mkdir("/opt/appfs", 0755);
	mkdir("/var", 0755);
	mkdir("/var/cache", 0755);
	mkdir("/var/cache/appfs", 0755);
	run("/bin/appfsd", "appfsd", "/var/cache/appfs", "/opt/appfs", NULL);

	symlink(".", "/usr");
	symlink("/opt/appfs/core.appfs.rkeene.org/bash/platform/latest/bin/bash", "/bin/bash");
	symlink("/opt/appfs/core.appfs.rkeene.org/coreutils/platform/latest/bin/env", "/bin/env");

	symlink("/bin/bash", "/bin/sh");

	setenv("PATH", "/bin:/opt/appfs/core.appfs.rkeene.org/coreutils/platform/latest/bin", 1);
	run("/bin/appfs-install-pkg", "appfs-install-pkg", "core.appfs.rkeene.org", "coreutils", NULL);
	setenv("PATH", "/bin", 1);

	if (argc == 1) {
		run("/bin/sh", "sh", NULL);
	} else {
		argv++;
		execvp(argv[0], argv);
	}

	return(0);
}