├── .gitignore ├── Creating Containerd.pdf ├── LICENSE ├── Makefile ├── cloexec.c └── parent.c /.gitignore: -------------------------------------------------------------------------------- 1 | exec-fifo 2 | cloexec 3 | parent 4 | -------------------------------------------------------------------------------- /Creating Containerd.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crosbymichael/dockercon-2016/912e3f1884ecfa39901001551a3ce415bba9539c/Creating Containerd.pdf -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Michael Crosby. crosbymichael@gmail.com 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, copy, 7 | modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, 16 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, 20 | DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, 23 | ARISING FROM, OUT OF OR IN CONNECTION WITH 24 | THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | gcc -o cloexec cloexec.c 4 | gcc -o parent parent.c 5 | 6 | clean: 7 | rm -f cloexec 8 | rm -f parent 9 | rm -f exit-fifo 10 | -------------------------------------------------------------------------------- /cloexec.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main() 11 | { 12 | if (mkfifo("exit-fifo", 0666) != 0) { 13 | printf("%s\n", strerror(errno)); 14 | exit(EXIT_FAILURE); 15 | } 16 | int fd = open("exit-fifo", O_WRONLY | O_CLOEXEC, 0); 17 | if (fd < 0) { 18 | printf("%s\n", strerror(errno)); 19 | exit(EXIT_FAILURE); 20 | } 21 | pause(); 22 | } 23 | -------------------------------------------------------------------------------- /parent.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main(int argc, char **argv) 11 | { 12 | if (argc > 1 && strcmp(argv[1], "--subreaper") == 0) { 13 | prctl(PR_SET_CHILD_SUBREAPER, 1); 14 | } 15 | printf("main() parent %d\n", getpid()); 16 | 17 | pid_t pid = fork(); 18 | if (pid == 0) { 19 | pid_t child = fork(); 20 | if (child == 0) { 21 | printf("child process %d with parent %d\n", getpid(), 22 | getppid()); 23 | sleep(3); 24 | printf("child process %d with new parent %d\n", 25 | getpid(), getppid()); 26 | sleep(2); 27 | exit(EXIT_SUCCESS); 28 | } 29 | sleep(2); 30 | printf("parent %d exiting\n", getpid()); 31 | exit(EXIT_SUCCESS); 32 | } 33 | 34 | int status; 35 | waitpid(pid, &status, 0); 36 | sleep(1); 37 | 38 | printf("trying to wait on child\n"); 39 | if (waitpid(-1, &status, 0) < 1) { 40 | printf("%s\n", strerror(errno)); 41 | exit(EXIT_FAILURE); 42 | } 43 | printf("success waiting on the child of my child\n"); 44 | } 45 | --------------------------------------------------------------------------------