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  +FROM scratch
            2  +
            3  +COPY init appfsd /bin/
            4  +
            5  +ENTRYPOINT ["/bin/init"]

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

            1  +#include <sys/types.h>
            2  +#include <sys/stat.h>
            3  +#include <sys/wait.h>
            4  +#include <unistd.h>
            5  +#include <stdlib.h>
            6  +#include <stdarg.h>
            7  +#include <stdio.h>
            8  +
            9  +int run(const char *path, ...) {
           10  +	va_list ap;
           11  +	char **argv;
           12  +	int argvMax, argvIdx;
           13  +	pid_t pid;
           14  +	int pidstat;
           15  +
           16  +	pid = fork();
           17  +	if (pid == ((pid_t) -1)) {
           18  +		return(-1);
           19  +	}
           20  +	
           21  +	if (pid != 0) {
           22  +		waitpid(pid, &pidstat, 0);
           23  +
           24  +		return(pidstat);
           25  +	}
           26  +
           27  +	argvMax = 32;
           28  +	argv = malloc(sizeof(*argv) * argvMax);
           29  +
           30  +	va_start(ap, path);
           31  +
           32  +	for (argvIdx = 0; argvIdx < argvMax; argvIdx++) {
           33  +		argv[argvIdx] = va_arg(ap, char *);
           34  +		if (argv[argvIdx] == NULL) {
           35  +			break;
           36  +		}
           37  +	}
           38  +	
           39  +	va_end(ap);
           40  +
           41  +	execv(path, argv);
           42  +
           43  +	exit(EXIT_FAILURE);
           44  +}
           45  +
           46  +int main(int argc, char **argv) {
           47  +	if (access("/dev/fuse", F_OK) != 0) {
           48  +		fprintf(stderr, "This container needs to be run as:  docker run --cap-add SYS_ADMIN --device /dev/fuse ...\n");
           49  +
           50  +		return(1);
           51  +	}
           52  +
           53  +	mkdir("/bin", 0755);
           54  +	mkdir("/opt", 0755);
           55  +	mkdir("/opt/appfs", 0755);
           56  +	mkdir("/var", 0755);
           57  +	mkdir("/var/cache", 0755);
           58  +	mkdir("/var/cache/appfs", 0755);
           59  +	run("/bin/appfsd", "appfsd", "/var/cache/appfs", "/opt/appfs", NULL);
           60  +
           61  +	symlink(".", "/usr");
           62  +	symlink("/opt/appfs/core.appfs.rkeene.org/bash/platform/latest/bin/bash", "/bin/bash");
           63  +	symlink("/opt/appfs/core.appfs.rkeene.org/coreutils/platform/latest/bin/env", "/bin/env");
           64  +
           65  +	symlink("/bin/bash", "/bin/sh");
           66  +
           67  +	setenv("PATH", "/bin:/opt/appfs/core.appfs.rkeene.org/coreutils/platform/latest/bin", 1);
           68  +	run("/bin/appfs-install-pkg", "appfs-install-pkg", "core.appfs.rkeene.org", "coreutils", NULL);
           69  +	setenv("PATH", "/bin", 1);
           70  +
           71  +	if (argc == 1) {
           72  +		run("/bin/sh", "sh", NULL);
           73  +	} else {
           74  +		argv++;
           75  +		execvp(argv[0], argv);
           76  +	}
           77  +
           78  +	return(0);
           79  +}