···11/*
22This file is part of Darling.
3344-Copyright (C) 2016 Lubos Dolezel
44+Copyright (C) 2016-2017 Lubos Dolezel
5566Darling is free software: you can redistribute it and/or modify
77it under the terms of the GNU General Public License as published by
···141141 return 0;
142142 }
143143144144+start_init:
144145 // If prefix's init is not running, start it up
145146 if (pidInit == 0)
146147 {
···201202 pidChild = spawnChild(pidInit, MLDR_PATH,
202203 (const char *[3]) {MLDR_PATH, "/bin/bash", NULL});
203204 }
205205+ if (pidChild == -ENOMEM)
206206+ {
207207+ pidInit = 0;
208208+ goto start_init;
209209+ }
204210205211 // Drop the privileges so that we can be killed, etc by the user
206212 seteuid(g_originalUid);
···248254 pidChild = fork();
249255 if (pidChild < 0)
250256 {
257257+ if (errno == ENOMEM)
258258+ {
259259+ // This condition happens specifically when the init process is a zombie.
260260+ // We should simply start a new init process.
261261+ return -ENOMEM;
262262+ }
251263 fprintf(stderr, "Cannot spawn a child process: %s\n", strerror(errno));
252264 exit(1);
253265 }