4 Copyright (C) 2006-2009 Jonathan Zarate
12 // used for various testing
13 static int rctest_main(int argc
, char *argv
[])
16 printf("test what?\n");
19 printf("%s\n", argv
[1]);
21 if (strcmp(argv
[1], "foo") == 0) {
23 else if (strcmp(argv
[1], "qos") == 0) {
27 if (strcmp(argv
[1], "6rd") == 0) {
33 else if (strcmp(argv
[1], "iptfile") == 0) {
34 create_test_iptfile();
46 static int hotplug_main(int argc
, char *argv
[])
49 if (strcmp(argv
[1], "net") == 0) {
54 else if (strcmp(argv
[1], "usb") == 0) {
58 else if (strcmp(argv
[1], "block") == 0) {
67 static int rc_main(int argc
, char *argv
[])
69 if (argc
< 2) return 0;
70 if (strcmp(argv
[1], "start") == 0) return kill(1, SIGUSR2
);
71 if (strcmp(argv
[1], "stop") == 0) return kill(1, SIGINT
);
72 if (strcmp(argv
[1], "restart") == 0) return kill(1, SIGHUP
);
80 int (*main
)(int argc
, char *argv
[]);
83 static const applets_t applets
[] = {
84 { "preinit", init_main
},
85 { "init", init_main
},
86 { "console", console_main
},
88 { "ip-up", ipup_main
},
89 { "ip-down", ipdown_main
},
90 /* KDB - these functions do nothing why are they here?
92 { "ipv6-up", ip6up_main },
93 { "ipv6-down", ip6down_main },
96 { "ppp_event", pppevent_main
},
97 { "hotplug", hotplug_main
},
98 { "redial", redial_main
},
99 { "listen", listen_main
},
100 { "service", service_main
},
101 { "sched", sched_main
},
102 #ifdef TCONFIG_BCMARM
103 { "mtd-write", mtd_write_main_old
},
104 { "mtd-erase", mtd_unlock_erase_main_old
},
105 { "mtd-unlock", mtd_unlock_erase_main_old
},
107 { "mtd-write", mtd_write_main
},
108 { "mtd-erase", mtd_unlock_erase_main
},
109 { "mtd-unlock", mtd_unlock_erase_main
},
111 { "buttons", buttons_main
},
113 { "blink_5g", blink_5g_main
},
115 { "rcheck", rcheck_main
},
116 { "dhcpc-event", dhcpc_event_main
},
117 { "dhcpc-release", dhcpc_release_main
},
118 { "dhcpc-renew", dhcpc_renew_main
},
120 { "dhcp6c-state", dhcp6c_state_main
},
122 { "radio", radio_main
},
124 { "halt", reboothalt_main
},
125 { "reboot", reboothalt_main
},
126 { "gpio", gpio_main
},
127 { "wldist", wldist_main
},
129 { "mount-cifs", mount_cifs_main
},
132 { "ddns-update", ddns_update_main
},
135 { "rctest", rctest_main
},
140 #ifdef TCONFIG_BCMARM
141 void erase_nvram(void)
143 eval("mtd-erase2", "nvram");
147 int main(int argc
, char **argv
)
153 Make sure std* are valid since several functions attempt to close these
154 handles. If nvram_*() runs first, nvram=0, nvram gets closed. - zzz
156 if ((f
= open("/dev/null", O_RDWR
)) < 3) {
164 base
= strrchr(argv
[0], '/');
165 base
= base
? base
+ 1 : argv
[0];
168 if (strcmp(base
, "rc") == 0) {
169 if (argc
< 2) return 1;
170 if (strcmp(argv
[1], "start") == 0) return kill(1, SIGUSR2
);
171 if (strcmp(argv
[1], "stop") == 0) return kill(1, SIGINT
);
172 if (strcmp(argv
[1], "restart") == 0) return kill(1, SIGHUP
);
181 #if defined(DEBUG_NOISY)
182 if (nvram_match("debug_logrc", "1")) {
185 cprintf("[rc %d] ", getpid());
186 for (i
= 0; i
< argc
; ++i
) {
187 cprintf("%s ", argv
[i
]);
194 #if defined(DEBUG_NOISY)
195 if (nvram_match("debug_ovrc", "1")) {
199 realpath(argv
[0], tmp
);
200 if ((strncmp(tmp
, "/tmp/", 5) != 0) && (argc
< 32)) {
201 sprintf(tmp
, "%s%s", "/tmp/", base
);
203 cprintf("[rc] override: %s\n", tmp
);
204 memcpy(a
, argv
, argc
* sizeof(a
[0]));
215 for (a
= applets
; a
->name
; ++a
) {
216 if (strcmp(base
, a
->name
) == 0) {
217 openlog(base
, LOG_PID
, LOG_USER
);
218 return a
->main(argc
, argv
);
222 #ifdef TCONFIG_BCMARM
223 if (!strcmp(base
, "nvram_erase")){
227 /* mtd-erase2 [device] */
228 else if (!strcmp(base
, "mtd-erase2")) {
229 if (argv
[1] && ((!strcmp(argv
[1], "boot")) ||
230 (!strcmp(argv
[1], "linux")) ||
231 (!strcmp(argv
[1], "linux2")) ||
232 (!strcmp(argv
[1], "rootfs")) ||
233 (!strcmp(argv
[1], "rootfs2")) ||
234 (!strcmp(argv
[1], "nvram")))) {
236 return mtd_erase(argv
[1]);
238 fprintf(stderr
, "usage: mtd-erase2 [device]\n");
242 /* mtd-write2 [path] [device] */
243 else if (!strcmp(base
, "mtd-write2")) {
245 return mtd_write(argv
[1], argv
[2]);
247 fprintf(stderr
, "usage: mtd-write2 [path] [device]\n");
253 printf("Unknown applet: %s\n", base
);