/[baselayout]/trunk/src/rc.c
Gentoo

Diff of /trunk/src/rc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2794 Revision 2799
28#include <signal.h> 28#include <signal.h>
29#include <string.h> 29#include <string.h>
30#include <termios.h> 30#include <termios.h>
31#include <unistd.h> 31#include <unistd.h>
32 32
33#include "builtins.h"
33#include "einfo.h" 34#include "einfo.h"
34#include "rc.h" 35#include "rc.h"
35#include "rc-misc.h" 36#include "rc-misc.h"
36#include "rc-plugin.h" 37#include "rc-plugin.h"
37#include "strlist.h" 38#include "strlist.h"
80} pidlist_t; 81} pidlist_t;
81static pidlist_t *service_pids = NULL; 82static pidlist_t *service_pids = NULL;
82 83
83static void cleanup (void) 84static void cleanup (void)
84{ 85{
86 if (applet && strcmp (applet, "rc") == 0) {
85 pidlist_t *pl = service_pids; 87 pidlist_t *pl = service_pids;
86 88
87 rc_plugin_unload (); 89 rc_plugin_unload ();
88 90
89 if (! rc_in_plugin && termios_orig) { 91 if (! rc_in_plugin && termios_orig) {
90 tcsetattr (fileno (stdin), TCSANOW, termios_orig); 92 tcsetattr (fileno (stdin), TCSANOW, termios_orig);
91 free (termios_orig); 93 free (termios_orig);
92 } 94 }
93 95
94 while (pl) { 96 while (pl) {
95 pidlist_t *p = pl->next; 97 pidlist_t *p = pl->next;
96 free (pl); 98 free (pl);
97 pl = p; 99 pl = p;
98 } 100 }
99 101
100 rc_strlist_free (env); 102 rc_strlist_free (env);
101 rc_strlist_free (newenv); 103 rc_strlist_free (newenv);
102 rc_strlist_free (coldplugged_services); 104 rc_strlist_free (coldplugged_services);
103 rc_strlist_free (stop_services); 105 rc_strlist_free (stop_services);
104 rc_strlist_free (start_services); 106 rc_strlist_free (start_services);
105 rc_free_deptree (deptree); 107 rc_free_deptree (deptree);
106 rc_strlist_free (types); 108 rc_strlist_free (types);
107 109
108 /* Clean runlevel start, stop markers */ 110 /* Clean runlevel start, stop markers */
109 if (! rc_in_plugin) { 111 if (! rc_in_plugin) {
110 if (rc_is_dir (RC_SVCDIR "softscripts.new")) 112 if (rc_is_dir (RC_SVCDIR "softscripts.new"))
111 rc_rm_dir (RC_SVCDIR "softscripts.new", true); 113 rc_rm_dir (RC_SVCDIR "softscripts.new", true);
112 if (rc_is_dir (RC_SVCDIR "softscripts.old")) 114 if (rc_is_dir (RC_SVCDIR "softscripts.old"))
113 rc_rm_dir (RC_SVCDIR "softscripts.old", true); 115 rc_rm_dir (RC_SVCDIR "softscripts.old", true);
116 }
114 } 117 }
115 118
116 free (applet); 119 free (applet);
117} 120}
118 121
693 int depoptions = RC_DEP_STRICT | RC_DEP_TRACE; 696 int depoptions = RC_DEP_STRICT | RC_DEP_TRACE;
694 char ksoftbuffer [PATH_MAX]; 697 char ksoftbuffer [PATH_MAX];
695 char pidstr[6]; 698 char pidstr[6];
696 int opt; 699 int opt;
697 700
701 atexit (cleanup);
698 if (argv[0]) 702 if (argv[0])
699 applet = rc_xstrdup (basename (argv[0])); 703 applet = rc_xstrdup (basename (argv[0]));
700 704
701 if (! applet) 705 if (! applet)
702 eerrorx ("arguments required"); 706 eerrorx ("arguments required");
707
708 /* These used to be programs in their own right, so we shouldn't
709 * touch argc or argv for them */
710 if (strcmp (applet, "env-update") == 0)
711 exit (env_update (argc, argv));
712 else if (strcmp (applet, "fstabinfo") == 0)
713 exit (fstabinfo (argc, argv));
714 else if (strcmp (applet, "mountinfo") == 0)
715 exit (mountinfo (argc, argv));
716 else if (strcmp (applet, "rc-depend") == 0)
717 exit (rc_depend (argc, argv));
718 else if (strcmp (applet, "rc-status") == 0)
719 exit (rc_status (argc, argv));
720 else if (strcmp (applet, "runscript") == 0)
721 exit (runscript (argc, argv));
722 else if (strcmp (applet, "start-stop-daemon") == 0)
723 exit (start_stop_daemon (argc, argv));
703 724
704 argc--; 725 argc--;
705 argv++; 726 argv++;
706 727
707 /* Handle multicall stuff */ 728 /* Handle multicall stuff */
736 exit (EXIT_FAILURE); 757 exit (EXIT_FAILURE);
737 } 758 }
738 759
739 if (strcmp (applet, "rc" ) != 0) 760 if (strcmp (applet, "rc" ) != 0)
740 eerrorx ("%s: unknown applet", applet); 761 eerrorx ("%s: unknown applet", applet);
741
742 atexit (cleanup);
743 762
744 /* Change dir to / to ensure all scripts don't use stuff in pwd */ 763 /* Change dir to / to ensure all scripts don't use stuff in pwd */
745 chdir ("/"); 764 chdir ("/");
746 765
747 /* RUNLEVEL is set by sysvinit as is a magic number 766 /* RUNLEVEL is set by sysvinit as is a magic number

Legend:
Removed from v.2794  
changed lines
  Added in v.2799

  ViewVC Help
Powered by ViewVC 1.1.20