| --- a/inittab.c |
| +++ b/inittab.c |
| @@ -44,6 +44,7 @@ |
| |
| struct init_action; |
| char *console = NULL; |
| +int production_mode = 0; |
| |
| struct init_handler { |
| const char *name; |
| @@ -313,9 +314,24 @@ void procd_inittab(void) |
| #define LINE_LEN 128 |
| FILE *fp = fopen(tab, "r"); |
| struct init_action *a; |
| - regex_t pat_inittab; |
| - regmatch_t matches[5]; |
| - char *line; |
| + regex_t pat_inittab, pat_cmdline; |
| + regmatch_t matches[5], cmd_matches[2]; |
| + char *line, cmdline[1024]; |
| + int r, fd = open("/proc/cmdline", O_RDONLY); |
| + |
| + if (fd < 0) { |
| + ERROR("Failed to open /proc/cmdline\n"); |
| + return; |
| + } |
| + |
| + r = read(fd, cmdline, sizeof(cmdline) - 1); |
| + cmdline[r] = '\0'; |
| + close(fd); |
| + regcomp(&pat_cmdline, "PROD=([0-2])", REG_EXTENDED); |
| + if (!regexec(&pat_cmdline, cmdline, 1, cmd_matches, 0)) { |
| + cmdline[cmd_matches[0].rm_eo] = '\0'; |
| + production_mode = atoi(&cmdline[cmd_matches[0].rm_eo - 1]); |
| + } |
| |
| if (!fp) { |
| ERROR("Failed to open %s: %m\n", tab); |
| --- a/rcS.c |
| +++ b/rcS.c |
| @@ -34,6 +34,7 @@ |
| #include "rcS.h" |
| |
| static struct runqueue q, r; |
| +extern int production_mode; |
| |
| struct initd { |
| struct ustream_fd fd; |
| @@ -172,7 +173,17 @@ static int _rc(struct runqueue *q, char |
| } |
| |
| for (j = 0; j < gl.gl_pathc; j++) |
| + { |
| + if (strstr(gl.gl_pathv[j], "prod_init")) { |
| + if (production_mode) { |
| + add_initd(q, gl.gl_pathv[j], param); |
| + break; |
| + } else { |
| + continue; |
| + } |
| + } |
| add_initd(q, gl.gl_pathv[j], param); |
| + } |
| |
| globfree(&gl); |
| |