aboutsummaryrefslogtreecommitdiff
path: root/src/rc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rc.c')
-rw-r--r--src/rc.c73
1 files changed, 46 insertions, 27 deletions
diff --git a/src/rc.c b/src/rc.c
index 9c9423cc..c226f805 100644
--- a/src/rc.c
+++ b/src/rc.c
@@ -30,6 +30,7 @@
#include <termios.h>
#include <unistd.h>
+#include "builtins.h"
#include "einfo.h"
#include "rc.h"
#include "rc-misc.h"
@@ -82,35 +83,37 @@ static pidlist_t *service_pids = NULL;
static void cleanup (void)
{
- pidlist_t *pl = service_pids;
+ if (applet && strcmp (applet, "rc") == 0) {
+ pidlist_t *pl = service_pids;
- rc_plugin_unload ();
+ rc_plugin_unload ();
- if (! rc_in_plugin && termios_orig) {
- tcsetattr (fileno (stdin), TCSANOW, termios_orig);
- free (termios_orig);
- }
-
- while (pl) {
- pidlist_t *p = pl->next;
- free (pl);
- pl = p;
- }
+ if (! rc_in_plugin && termios_orig) {
+ tcsetattr (fileno (stdin), TCSANOW, termios_orig);
+ free (termios_orig);
+ }
- rc_strlist_free (env);
- rc_strlist_free (newenv);
- rc_strlist_free (coldplugged_services);
- rc_strlist_free (stop_services);
- rc_strlist_free (start_services);
- rc_free_deptree (deptree);
- rc_strlist_free (types);
+ while (pl) {
+ pidlist_t *p = pl->next;
+ free (pl);
+ pl = p;
+ }
- /* Clean runlevel start, stop markers */
- if (! rc_in_plugin) {
- if (rc_is_dir (RC_SVCDIR "softscripts.new"))
- rc_rm_dir (RC_SVCDIR "softscripts.new", true);
- if (rc_is_dir (RC_SVCDIR "softscripts.old"))
- rc_rm_dir (RC_SVCDIR "softscripts.old", true);
+ rc_strlist_free (env);
+ rc_strlist_free (newenv);
+ rc_strlist_free (coldplugged_services);
+ rc_strlist_free (stop_services);
+ rc_strlist_free (start_services);
+ rc_free_deptree (deptree);
+ rc_strlist_free (types);
+
+ /* Clean runlevel start, stop markers */
+ if (! rc_in_plugin) {
+ if (rc_is_dir (RC_SVCDIR "softscripts.new"))
+ rc_rm_dir (RC_SVCDIR "softscripts.new", true);
+ if (rc_is_dir (RC_SVCDIR "softscripts.old"))
+ rc_rm_dir (RC_SVCDIR "softscripts.old", true);
+ }
}
free (applet);
@@ -695,12 +698,30 @@ int main (int argc, char **argv)
char pidstr[6];
int opt;
+ atexit (cleanup);
if (argv[0])
applet = rc_xstrdup (basename (argv[0]));
if (! applet)
eerrorx ("arguments required");
+ /* These used to be programs in their own right, so we shouldn't
+ * touch argc or argv for them */
+ if (strcmp (applet, "env-update") == 0)
+ exit (env_update (argc, argv));
+ else if (strcmp (applet, "fstabinfo") == 0)
+ exit (fstabinfo (argc, argv));
+ else if (strcmp (applet, "mountinfo") == 0)
+ exit (mountinfo (argc, argv));
+ else if (strcmp (applet, "rc-depend") == 0)
+ exit (rc_depend (argc, argv));
+ else if (strcmp (applet, "rc-status") == 0)
+ exit (rc_status (argc, argv));
+ else if (strcmp (applet, "runscript") == 0)
+ exit (runscript (argc, argv));
+ else if (strcmp (applet, "start-stop-daemon") == 0)
+ exit (start_stop_daemon (argc, argv));
+
argc--;
argv++;
@@ -739,8 +760,6 @@ int main (int argc, char **argv)
if (strcmp (applet, "rc" ) != 0)
eerrorx ("%s: unknown applet", applet);
- atexit (cleanup);
-
/* Change dir to / to ensure all scripts don't use stuff in pwd */
chdir ("/");