b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | --- a/rcS.c |
| 2 | +++ b/rcS.c |
| 3 | @@ -33,6 +33,12 @@ |
| 4 | #include "procd.h" |
| 5 | #include "rcS.h" |
| 6 | |
| 7 | +/*These are the scripts that are loaded both in normal and production mode. |
| 8 | + However, product mode only executes the scripts in BASE_SCRIPTS with |
| 9 | + lower START index than prod_init and prod_init itself. |
| 10 | + */ |
| 11 | +#define BASE_SCRIPTS "sysfixtime boot system sysctl log firewall network odhcpd fstab" |
| 12 | + |
| 13 | static struct runqueue q, r; |
| 14 | extern int production_mode; |
| 15 | |
| 16 | @@ -154,11 +160,26 @@ static void add_initd(struct runqueue *q |
| 17 | runqueue_task_add(q, &s->proc.task, false); |
| 18 | } |
| 19 | |
| 20 | +static void remove_str_from_list(char *str, char *list) |
| 21 | +{ |
| 22 | + char *pnt1, *pnt2; |
| 23 | + if (!str || !list) |
| 24 | + return; |
| 25 | + pnt1 = strstr(list, str); |
| 26 | + if (pnt1 == NULL) |
| 27 | + return; |
| 28 | + pnt2 = pnt1 + strlen(str) + 1; |
| 29 | + memmove(pnt1, pnt2, strlen(pnt2) + 1); |
| 30 | +} |
| 31 | + |
| 32 | static int _rc(struct runqueue *q, char *path, const char *file, char *pattern, char *param) |
| 33 | { |
| 34 | char *dir = alloca(2 + strlen(path) + strlen(file) + strlen(pattern)); |
| 35 | glob_t gl; |
| 36 | int j; |
| 37 | + char available_strings[] = BASE_SCRIPTS; |
| 38 | + char str[] = BASE_SCRIPTS; |
| 39 | + char *token; |
| 40 | |
| 41 | if (!dir) { |
| 42 | ERROR("Out of memory in %s.\n", file); |
| 43 | @@ -174,17 +195,31 @@ static int _rc(struct runqueue *q, char |
| 44 | |
| 45 | for (j = 0; j < gl.gl_pathc; j++) |
| 46 | { |
| 47 | - if (strstr(gl.gl_pathv[j], "prod_init")) { |
| 48 | - if (production_mode) { |
| 49 | + if (production_mode) { |
| 50 | + strcpy(str, available_strings); |
| 51 | + token = strtok(str, " "); |
| 52 | + do |
| 53 | + { |
| 54 | + if (strstr(gl.gl_pathv[j], token)) { |
| 55 | + add_initd(q, gl.gl_pathv[j], param); |
| 56 | + remove_str_from_list(token, available_strings); |
| 57 | + break; |
| 58 | + } |
| 59 | + token = strtok(NULL, " "); |
| 60 | + } while (token != NULL); |
| 61 | + if (token == NULL && strstr(gl.gl_pathv[j], "prod_init")) |
| 62 | + { |
| 63 | add_initd(q, gl.gl_pathv[j], param); |
| 64 | break; |
| 65 | } else { |
| 66 | continue; |
| 67 | } |
| 68 | + } else { |
| 69 | + if (strstr(gl.gl_pathv[j], "prod_init")) |
| 70 | + continue; |
| 71 | } |
| 72 | add_initd(q, gl.gl_pathv[j], param); |
| 73 | } |
| 74 | - |
| 75 | globfree(&gl); |
| 76 | |
| 77 | return 0; |