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) {
50 static int rc_main(int argc
, char *argv
[])
52 if (argc
< 2) return 0;
53 if (strcmp(argv
[1], "start") == 0) return kill(1, SIGUSR2
);
54 if (strcmp(argv
[1], "stop") == 0) return kill(1, SIGINT
);
55 if (strcmp(argv
[1], "restart") == 0) return kill(1, SIGHUP
);
63 int (*main
)(int argc
, char *argv
[]);
66 static const applets_t applets
[] = {
67 { "init", init_main
},
69 { "ip-up", ipup_main
},
70 { "ip-down", ipdown_main
},
71 { "set-pppoepid", set_pppoepid_main
},
72 { "pppoe_down", pppoe_down_main
},
73 { "ppp_event", pppevent_main
},
74 { "hotplug", hotplug_main
},
75 { "redial", redial_main
},
76 { "listen", listen_main
},
77 { "service", service_main
},
78 { "sched", sched_main
},
79 { "mtd-write", mtd_write_main
},
80 { "mtd-erase", mtd_unlock_erase_main
},
81 { "mtd-unlock", mtd_unlock_erase_main
},
82 { "buttons", buttons_main
},
83 { "rcheck", rcheck_main
},
84 { "dhcpc-event", dhcpc_event_main
},
85 { "dhcpc-release", dhcpc_release_main
},
86 { "dhcpc-renew", dhcpc_renew_main
},
87 { "radio", radio_main
},
89 { "halt", reboothalt_main
},
90 { "reboot", reboothalt_main
},
91 { "gpio", gpio_main
},
92 { "wldist", wldist_main
},
94 { "mount-cifs", mount_cifs_main
},
97 { "ddns-update", ddns_update_main
},
100 { "rctest", rctest_main
},
105 int main(int argc
, char **argv
)
111 Make sure std* are valid since several functions attempt to close these
112 handles. If nvram_*() runs first, nvram=0, nvram gets closed. - zzz
114 if ((f
= open("/dev/null", O_RDWR
)) < 3) {
122 base
= strrchr(argv
[0], '/');
123 base
= base
? base
+ 1 : argv
[0];
126 if (strcmp(base
, "rc") == 0) {
127 if (argc
< 2) return 1;
128 if (strcmp(argv
[1], "start") == 0) return kill(1, SIGUSR2
);
129 if (strcmp(argv
[1], "stop") == 0) return kill(1, SIGINT
);
130 if (strcmp(argv
[1], "restart") == 0) return kill(1, SIGHUP
);
137 #if defined(DEBUG_NOISY)
138 if (nvram_match("debug_logrc", "1")) {
141 cprintf("[rc %d] ", getpid());
142 for (i
= 0; i
< argc
; ++i
) {
143 cprintf("%s ", argv
[i
]);
150 #if defined(DEBUG_NOISY)
151 if (nvram_match("debug_ovrc", "1")) {
155 realpath(argv
[0], tmp
);
156 if ((strncmp(tmp
, "/tmp/", 5) != 0) && (argc
< 32)) {
157 sprintf(tmp
, "%s%s", "/tmp/", base
);
159 cprintf("[rc] override: %s\n", tmp
);
160 memcpy(a
, argv
, argc
* sizeof(a
[0]));
171 for (a
= applets
; a
->name
; ++a
) {
172 if (strcmp(base
, a
->name
) == 0) {
173 openlog(base
, LOG_PID
, LOG_USER
);
174 return a
->main(argc
, argv
);
178 printf("Unknown applet: %s\n", base
);