blob: 90d92476d2003ef6b14980bb48758f40a551212f [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001--- a/inittab.c
2+++ b/inittab.c
3@@ -44,6 +44,7 @@
4
5 struct init_action;
6 char *console = NULL;
7+int production_mode = 0;
8
9 struct init_handler {
10 const char *name;
11@@ -313,9 +314,24 @@ void procd_inittab(void)
12 #define LINE_LEN 128
13 FILE *fp = fopen(tab, "r");
14 struct init_action *a;
15- regex_t pat_inittab;
16- regmatch_t matches[5];
17- char *line;
18+ regex_t pat_inittab, pat_cmdline;
19+ regmatch_t matches[5], cmd_matches[2];
20+ char *line, cmdline[1024];
21+ int r, fd = open("/proc/cmdline", O_RDONLY);
22+
23+ if (fd < 0) {
24+ ERROR("Failed to open /proc/cmdline\n");
25+ return;
26+ }
27+
28+ r = read(fd, cmdline, sizeof(cmdline) - 1);
29+ cmdline[r] = '\0';
30+ close(fd);
31+ regcomp(&pat_cmdline, "PROD=([0-2])", REG_EXTENDED);
32+ if (!regexec(&pat_cmdline, cmdline, 1, cmd_matches, 0)) {
33+ cmdline[cmd_matches[0].rm_eo] = '\0';
34+ production_mode = atoi(&cmdline[cmd_matches[0].rm_eo - 1]);
35+ }
36
37 if (!fp) {
38 ERROR("Failed to open %s: %m\n", tab);
39--- a/rcS.c
40+++ b/rcS.c
41@@ -34,6 +34,7 @@
42 #include "rcS.h"
43
44 static struct runqueue q, r;
45+extern int production_mode;
46
47 struct initd {
48 struct ustream_fd fd;
49@@ -172,7 +173,17 @@ static int _rc(struct runqueue *q, char
50 }
51
52 for (j = 0; j < gl.gl_pathc; j++)
53+ {
54+ if (strstr(gl.gl_pathv[j], "prod_init")) {
55+ if (production_mode) {
56+ add_initd(q, gl.gl_pathv[j], param);
57+ break;
58+ } else {
59+ continue;
60+ }
61+ }
62 add_initd(q, gl.gl_pathv[j], param);
63+ }
64
65 globfree(&gl);
66