--- sysvinit-2.88dsf/src/init.c.wiget 2011-12-03 23:39:16.988206898 +0100 +++ sysvinit-2.88dsf/src/init.c 2011-12-03 23:47:53.761427001 +0100 @@ -880,7 +880,7 @@ char **init_buildenv(int child) n += NR_EXTRA_ENV; if (child) n += 8; - e = calloc(n, sizeof(char *)); + e = imalloc(n * sizeof(char *)); for (n = 0; environ[n]; n++) e[n] = istrdup(environ[n]); @@ -911,6 +911,9 @@ void init_freeenv(char **e) { int n; + if (!e) + return; + for (n = 0; e[n]; n++) free(e[n]); free(e); @@ -1976,7 +1979,7 @@ void re_exec(void) CHILD *ch; sigset_t mask, oldset; pid_t pid; - char **env; + char **env = 0; int fd; if (strchr("S0123456",runlevel) == NULL) @@ -2027,8 +2030,13 @@ void re_exec(void) /* * The existing init process execs a new init binary. */ - env = init_buildenv(0); - execle(myname, myname, "--init", NULL, env); + if (pid > 0) { + /* + * The existing init process execs a new init binary. + */ + env = init_buildenv(0); + execle(myname, myname, "--init", NULL, env); + } /* * We shouldn't be here, something failed. @@ -2729,7 +2737,7 @@ int telinit(char *progname, int argc, ch if (!strchr("0123456789SsQqAaBbCcUu", argv[optind][0])) usage(progname); request.cmd = INIT_CMD_RUNLVL; - request.runlevel = env ? 0 : argv[optind][0]; + request.runlevel = argv[optind][0]; request.sleeptime = sltime; }