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
},
79 { "console", console_main
},
81 { "ip-up", ipup_main
},
82 { "ip-down", ipdown_main
},
84 { "ipv6-up", ip6up_main
},
85 { "ipv6-down", ip6down_main
},
87 { "ppp_event", pppevent_main
},
88 { "hotplug", hotplug_main
},
89 { "redial", redial_main
},
90 { "listen", listen_main
},
91 { "service", service_main
},
92 { "sched", sched_main
},
93 { "mtd-write", mtd_write_main
},
94 { "mtd-erase", mtd_unlock_erase_main
},
95 { "mtd-unlock", mtd_unlock_erase_main
},
96 { "buttons", buttons_main
},
97 { "rcheck", rcheck_main
},
98 { "dhcpc-event", dhcpc_event_main
},
99 { "dhcpc-release", dhcpc_release_main
},
100 { "dhcpc-renew", dhcpc_renew_main
},
102 { "dhcp6c-state", dhcp6c_state_main
},
104 { "radio", radio_main
},
106 { "halt", reboothalt_main
},
107 { "reboot", reboothalt_main
},
108 { "gpio", gpio_main
},
109 { "wldist", wldist_main
},
111 { "mount-cifs", mount_cifs_main
},
114 { "ddns-update", ddns_update_main
},
117 { "rctest", rctest_main
},
122 int main(int argc
, char **argv
)
128 Make sure std* are valid since several functions attempt to close these
129 handles. If nvram_*() runs first, nvram=0, nvram gets closed. - zzz
131 if ((f
= open("/dev/null", O_RDWR
)) < 3) {
139 base
= strrchr(argv
[0], '/');
140 base
= base
? base
+ 1 : argv
[0];
143 if (strcmp(base
, "rc") == 0) {
144 if (argc
< 2) return 1;
145 if (strcmp(argv
[1], "start") == 0) return kill(1, SIGUSR2
);
146 if (strcmp(argv
[1], "stop") == 0) return kill(1, SIGINT
);
147 if (strcmp(argv
[1], "restart") == 0) return kill(1, SIGHUP
);
154 #if defined(DEBUG_NOISY)
155 if (nvram_match("debug_logrc", "1")) {
158 cprintf("[rc %d] ", getpid());
159 for (i
= 0; i
< argc
; ++i
) {
160 cprintf("%s ", argv
[i
]);
167 #if defined(DEBUG_NOISY)
168 if (nvram_match("debug_ovrc", "1")) {
172 realpath(argv
[0], tmp
);
173 if ((strncmp(tmp
, "/tmp/", 5) != 0) && (argc
< 32)) {
174 sprintf(tmp
, "%s%s", "/tmp/", base
);
176 cprintf("[rc] override: %s\n", tmp
);
177 memcpy(a
, argv
, argc
* sizeof(a
[0]));
188 for (a
= applets
; a
->name
; ++a
) {
189 if (strcmp(base
, a
->name
) == 0) {
190 openlog(base
, LOG_PID
, LOG_USER
);
191 return a
->main(argc
, argv
);
195 printf("Unknown applet: %s\n", base
);