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 else if (strcmp(argv
[1], "iptfile") == 0) {
28 create_test_iptfile();
40 static int hotplug_main(int argc
, char *argv
[])
43 if (strcmp(argv
[1], "net") == 0) {
48 else if (strcmp(argv
[1], "usb") == 0) {
52 else if (strcmp(argv
[1], "block") == 0) {
61 static int rc_main(int argc
, char *argv
[])
63 if (argc
< 2) return 0;
64 if (strcmp(argv
[1], "start") == 0) return kill(1, SIGUSR2
);
65 if (strcmp(argv
[1], "stop") == 0) return kill(1, SIGINT
);
66 if (strcmp(argv
[1], "restart") == 0) return kill(1, SIGHUP
);
74 int (*main
)(int argc
, char *argv
[]);
77 static const applets_t applets
[] = {
78 { "init", init_main
},
80 { "ip-up", ipup_main
},
81 { "ip-down", ipdown_main
},
82 { "set-pppoepid", set_pppoepid_main
},
83 { "pppoe_down", pppoe_down_main
},
84 { "ppp_event", pppevent_main
},
85 { "hotplug", hotplug_main
},
86 { "redial", redial_main
},
87 { "listen", listen_main
},
88 { "service", service_main
},
89 { "sched", sched_main
},
90 { "mtd-write", mtd_write_main
},
91 { "mtd-erase", mtd_unlock_erase_main
},
92 { "mtd-unlock", mtd_unlock_erase_main
},
93 { "buttons", buttons_main
},
94 { "rcheck", rcheck_main
},
95 { "dhcpc-event", dhcpc_event_main
},
96 { "dhcpc-release", dhcpc_release_main
},
97 { "dhcpc-renew", dhcpc_renew_main
},
98 { "radio", radio_main
},
100 { "halt", reboothalt_main
},
101 { "reboot", reboothalt_main
},
102 { "gpio", gpio_main
},
103 { "wldist", wldist_main
},
105 { "mount-cifs", mount_cifs_main
},
108 { "ddns-update", ddns_update_main
},
111 { "rctest", rctest_main
},
116 int main(int argc
, char **argv
)
122 Make sure std* are valid since several functions attempt to close these
123 handles. If nvram_*() runs first, nvram=0, nvram gets closed. - zzz
125 if ((f
= open("/dev/null", O_RDWR
)) < 3) {
133 base
= strrchr(argv
[0], '/');
134 base
= base
? base
+ 1 : argv
[0];
137 if (strcmp(base
, "rc") == 0) {
138 if (argc
< 2) return 1;
139 if (strcmp(argv
[1], "start") == 0) return kill(1, SIGUSR2
);
140 if (strcmp(argv
[1], "stop") == 0) return kill(1, SIGINT
);
141 if (strcmp(argv
[1], "restart") == 0) return kill(1, SIGHUP
);
148 #if defined(DEBUG_NOISY)
149 if (nvram_match("debug_logrc", "1")) {
152 cprintf("[rc %d] ", getpid());
153 for (i
= 0; i
< argc
; ++i
) {
154 cprintf("%s ", argv
[i
]);
161 #if defined(DEBUG_NOISY)
162 if (nvram_match("debug_ovrc", "1")) {
166 realpath(argv
[0], tmp
);
167 if ((strncmp(tmp
, "/tmp/", 5) != 0) && (argc
< 32)) {
168 sprintf(tmp
, "%s%s", "/tmp/", base
);
170 cprintf("[rc] override: %s\n", tmp
);
171 memcpy(a
, argv
, argc
* sizeof(a
[0]));
182 for (a
= applets
; a
->name
; ++a
) {
183 if (strcmp(base
, a
->name
) == 0) {
184 openlog(base
, LOG_PID
, LOG_USER
);
185 return a
->main(argc
, argv
);
189 printf("Unknown applet: %s\n", base
);