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

Diff of /trunk/src/runscript.c

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

Revision 3039 Revision 3040
49static char *service = NULL; 49static char *service = NULL;
50static char *exclusive = NULL; 50static char *exclusive = NULL;
51static char *mtime_test = NULL; 51static char *mtime_test = NULL;
52static rc_depinfo_t *deptree = NULL; 52static rc_depinfo_t *deptree = NULL;
53static char **services = NULL; 53static char **services = NULL;
54static char **svclist = NULL;
55static char **tmplist = NULL; 54static char **tmplist = NULL;
56static char **providelist = NULL; 55static char **providelist = NULL;
57static char **types = NULL;
58static char **restart_services = NULL; 56static char **restart_services = NULL;
59static char **need_services = NULL; 57static char **need_services = NULL;
60static char **use_services = NULL; 58static char **use_services = NULL;
61static char **env = NULL; 59static char **env = NULL;
62static char *tmp = NULL; 60static char *tmp = NULL;
70static bool prefix_locked = false; 68static bool prefix_locked = false;
71static int signal_pipe[2] = { -1, -1 }; 69static int signal_pipe[2] = { -1, -1 };
72static int master_tty = -1; 70static int master_tty = -1;
73 71
74extern char **environ; 72extern char **environ;
73
74static const char *types_b[] = { "broken", NULL };
75static const char *types_n[] = { "ineed", NULL };
76static const char *types_nu[] = { "ineed", "iuse", NULL };
77static const char *types_nua[] = { "ineed", "iuse", "iafter", NULL };
78static const char *types_p[] = { "iprovide", NULL };
79
80static const char *types_m[] = { "needsme", NULL };
81static const char *types_mua[] = { "needsme", "usesme", "beforeme", NULL };
75 82
76#ifdef __linux__ 83#ifdef __linux__
77static void (*selinux_run_init_old) (void); 84static void (*selinux_run_init_old) (void);
78static void (*selinux_run_init_new) (int argc, char **argv); 85static void (*selinux_run_init_new) (int argc, char **argv);
79 86
297 } 304 }
298 305
299 rc_plugin_unload (); 306 rc_plugin_unload ();
300 rc_deptree_free (deptree); 307 rc_deptree_free (deptree);
301 rc_strlist_free (services); 308 rc_strlist_free (services);
302 rc_strlist_free (types);
303 rc_strlist_free (svclist);
304 rc_strlist_free (providelist); 309 rc_strlist_free (providelist);
305 rc_strlist_free (need_services); 310 rc_strlist_free (need_services);
306 rc_strlist_free (use_services); 311 rc_strlist_free (use_services);
307 rc_strlist_free (restart_services); 312 rc_strlist_free (restart_services);
308 rc_strlist_free (tmplist); 313 rc_strlist_free (tmplist);
578 char *svc; 583 char *svc;
579 char *svc2; 584 char *svc2;
580 int i; 585 int i;
581 int j; 586 int j;
582 int depoptions = RC_DEP_TRACE; 587 int depoptions = RC_DEP_TRACE;
588 const char *svcl[] = { applet, NULL };
583 rc_service_state_t state; 589 rc_service_state_t state;
584 590
585 hook_out = RC_HOOK_SERVICE_START_OUT; 591 hook_out = RC_HOOK_SERVICE_START_OUT;
586 rc_plugin_run (RC_HOOK_SERVICE_START_IN, applet); 592 rc_plugin_run (RC_HOOK_SERVICE_START_IN, applet);
587 state = rc_service_state (service); 593 state = rc_service_state (service);
615 621
616 if (deps) { 622 if (deps) {
617 if (! deptree && ((deptree = _rc_deptree_load ()) == NULL)) 623 if (! deptree && ((deptree = _rc_deptree_load ()) == NULL))
618 eerrorx ("failed to load deptree"); 624 eerrorx ("failed to load deptree");
619 625
620 rc_strlist_free (types);
621 types = NULL;
622 rc_strlist_add (&types, "broken");
623 rc_strlist_free (svclist);
624 svclist = NULL;
625 rc_strlist_add (&svclist, applet);
626 rc_strlist_free (services); 626 rc_strlist_free (services);
627 services = rc_deptree_depends (deptree, types, svclist, softlevel, 0); 627 services = rc_deptree_depends (deptree, types_b, svcl, softlevel, 0);
628 if (services) { 628 if (services) {
629 eerrorn ("ERROR: `%s' needs ", applet); 629 eerrorn ("ERROR: `%s' needs ", applet);
630 STRLIST_FOREACH (services, svc, i) { 630 STRLIST_FOREACH (services, svc, i) {
631 if (i > 0) 631 if (i > 0)
632 fprintf (stderr, ", "); 632 fprintf (stderr, ", ");
635 exit (EXIT_FAILURE); 635 exit (EXIT_FAILURE);
636 } 636 }
637 rc_strlist_free (services); 637 rc_strlist_free (services);
638 services = NULL; 638 services = NULL;
639 639
640 rc_strlist_free (types);
641 types = NULL;
642 rc_strlist_add (&types, "ineed");
643 rc_strlist_free (need_services); 640 rc_strlist_free (need_services);
644 need_services = rc_deptree_depends (deptree, types, svclist, 641 need_services = rc_deptree_depends (deptree, types_n, svcl,
645 softlevel, depoptions); 642 softlevel, depoptions);
646 643
647 rc_strlist_add (&types, "iuse");
648 rc_strlist_free (use_services); 644 rc_strlist_free (use_services);
649 use_services = rc_deptree_depends (deptree, types, svclist, 645 use_services = rc_deptree_depends (deptree, types_nu, svcl,
650 softlevel, depoptions); 646 softlevel, depoptions);
651 647
652 if (! rc_runlevel_starting ()) { 648 if (! rc_runlevel_starting ()) {
653 STRLIST_FOREACH (use_services, svc, i) 649 STRLIST_FOREACH (use_services, svc, i)
654 if (rc_service_state (svc) & RC_SERVICE_STOPPED) { 650 if (rc_service_state (svc) & RC_SERVICE_STOPPED) {
657 wait_pid (pid); 653 wait_pid (pid);
658 } 654 }
659 } 655 }
660 656
661 /* Now wait for them to start */ 657 /* Now wait for them to start */
662 rc_strlist_add (&types, "iafter");
663 services = rc_deptree_depends (deptree, types, svclist, 658 services = rc_deptree_depends (deptree, types_nua, svcl,
664 softlevel, depoptions); 659 softlevel, depoptions);
665 660
666 /* We use tmplist to hold our scheduled by list */ 661 /* We use tmplist to hold our scheduled by list */
667 rc_strlist_free (tmplist); 662 rc_strlist_free (tmplist);
668 tmplist = NULL; 663 tmplist = NULL;
669 664
710 /* Set the state now, then unlink our exclusive so that 705 /* Set the state now, then unlink our exclusive so that
711 our scheduled list is preserved */ 706 our scheduled list is preserved */
712 rc_service_mark (service, RC_SERVICE_STOPPED); 707 rc_service_mark (service, RC_SERVICE_STOPPED);
713 unlink_mtime_test (); 708 unlink_mtime_test ();
714 709
715 rc_strlist_free (types);
716 types = NULL;
717 rc_strlist_add (&types, "iprovide");
718 STRLIST_FOREACH (tmplist, svc, i) { 710 STRLIST_FOREACH (tmplist, svc, i) {
711 const char *sl[] = { svc, NULL };
719 rc_service_schedule_start (svc, service); 712 rc_service_schedule_start (svc, service);
720 713
721 rc_strlist_free (svclist);
722 svclist = NULL;
723 rc_strlist_add (&svclist, svc);
724 rc_strlist_free (providelist); 714 rc_strlist_free (providelist);
725 providelist = rc_deptree_depends (deptree, types, svclist, 715 providelist = rc_deptree_depends (deptree, types_p, sl,
726 softlevel, depoptions); 716 softlevel, depoptions);
727 STRLIST_FOREACH (providelist, svc2, j) 717 STRLIST_FOREACH (providelist, svc2, j)
728 rc_service_schedule_start (svc2, service); 718 rc_service_schedule_start (svc2, service);
729 719
730 len += strlen (svc) + 2; 720 len += strlen (svc) + 2;
731 n++; 721 n++;
747 applet, tmp); 737 applet, tmp);
748 } 738 }
749 739
750 rc_strlist_free (services); 740 rc_strlist_free (services);
751 services = NULL; 741 services = NULL;
752 rc_strlist_free (types);
753 types = NULL;
754 rc_strlist_free (svclist);
755 svclist = NULL;
756 } 742 }
757 743
758 if (ibsave) 744 if (ibsave)
759 setenv ("IN_BACKGROUND", ibsave, 1); 745 setenv ("IN_BACKGROUND", ibsave, 1);
760 hook_out = RC_HOOK_SERVICE_START_DONE; 746 hook_out = RC_HOOK_SERVICE_START_DONE;
789 rc_service_start (svc); 775 rc_service_start (svc);
790 rc_strlist_free (services); 776 rc_strlist_free (services);
791 services = NULL; 777 services = NULL;
792 778
793 /* Do the same for any services we provide */ 779 /* Do the same for any services we provide */
794 rc_strlist_free (types);
795 types = NULL;
796 rc_strlist_add (&types, "iprovide");
797 rc_strlist_free (svclist);
798 svclist = NULL;
799 rc_strlist_add (&svclist, applet);
800 rc_strlist_free (tmplist); 780 rc_strlist_free (tmplist);
801 tmplist = rc_deptree_depends (deptree, types, svclist, softlevel, depoptions); 781 tmplist = rc_deptree_depends (deptree, types_p, svcl, softlevel, depoptions);
802 782
803 STRLIST_FOREACH (tmplist, svc2, j) { 783 STRLIST_FOREACH (tmplist, svc2, j) {
804 rc_strlist_free (services); 784 rc_strlist_free (services);
805 services = rc_services_scheduled (svc2); 785 services = rc_services_scheduled (svc2);
806 STRLIST_FOREACH (services, svc, i) 786 STRLIST_FOREACH (services, svc, i)
813} 793}
814 794
815static void svc_stop (bool deps) 795static void svc_stop (bool deps)
816{ 796{
817 bool stopped; 797 bool stopped;
798 const char *svcl[] = { applet, NULL };
799
818 rc_service_state_t state = rc_service_state (service); 800 rc_service_state_t state = rc_service_state (service);
819 801
820 hook_out = RC_HOOK_SERVICE_STOP_OUT; 802 hook_out = RC_HOOK_SERVICE_STOP_OUT;
821 rc_plugin_run (RC_HOOK_SERVICE_STOP_IN, applet); 803 rc_plugin_run (RC_HOOK_SERVICE_STOP_IN, applet);
822 804
855 depoptions |= RC_DEP_STOP; 837 depoptions |= RC_DEP_STOP;
856 838
857 if (! deptree && ((deptree = _rc_deptree_load ()) == NULL)) 839 if (! deptree && ((deptree = _rc_deptree_load ()) == NULL))
858 eerrorx ("failed to load deptree"); 840 eerrorx ("failed to load deptree");
859 841
860 rc_strlist_free (types);
861 types = NULL;
862 rc_strlist_add (&types, "needsme");
863 rc_strlist_free (svclist);
864 svclist = NULL;
865 rc_strlist_add (&svclist, applet);
866 rc_strlist_free (tmplist); 842 rc_strlist_free (tmplist);
867 tmplist = NULL; 843 tmplist = NULL;
868 rc_strlist_free (services); 844 rc_strlist_free (services);
869 services = rc_deptree_depends (deptree, types, svclist, 845 services = rc_deptree_depends (deptree, types_m, svcl,
870 softlevel, depoptions); 846 softlevel, depoptions);
871 rc_strlist_reverse (services); 847 rc_strlist_reverse (services);
872 STRLIST_FOREACH (services, svc, i) { 848 STRLIST_FOREACH (services, svc, i) {
873 rc_service_state_t svcs = rc_service_state (svc); 849 rc_service_state_t svcs = rc_service_state (svc);
874 if (svcs & RC_SERVICE_STARTED || 850 if (svcs & RC_SERVICE_STARTED ||
875 svcs & RC_SERVICE_INACTIVE) 851 svcs & RC_SERVICE_INACTIVE)
913 rc_strlist_free (tmplist); 889 rc_strlist_free (tmplist);
914 tmplist = NULL; 890 tmplist = NULL;
915 891
916 /* We now wait for other services that may use us and are stopping 892 /* We now wait for other services that may use us and are stopping
917 This is important when a runlevel stops */ 893 This is important when a runlevel stops */
918 rc_strlist_add (&types, "usesme");
919 rc_strlist_add (&types, "ibefore");
920 services = rc_deptree_depends (deptree, types, svclist, 894 services = rc_deptree_depends (deptree, types_mua, svcl,
921 softlevel, depoptions); 895 softlevel, depoptions);
922 STRLIST_FOREACH (services, svc, i) { 896 STRLIST_FOREACH (services, svc, i) {
923 if (rc_service_state (svc) & RC_SERVICE_STOPPED) 897 if (rc_service_state (svc) & RC_SERVICE_STOPPED)
924 continue; 898 continue;
925 rc_service_wait (svc); 899 rc_service_wait (svc);
926 } 900 }
927 901
928 rc_strlist_free (services); 902 rc_strlist_free (services);
929 services = NULL; 903 services = NULL;
930 rc_strlist_free (types);
931 types = NULL;
932 } 904 }
933 905
934 if (ibsave) 906 if (ibsave)
935 setenv ("IN_BACKGROUND", ibsave, 1); 907 setenv ("IN_BACKGROUND", ibsave, 1);
936 hook_out = RC_HOOK_SERVICE_STOP_DONE; 908 hook_out = RC_HOOK_SERVICE_STOP_DONE;
955 rc_plugin_run (RC_HOOK_SERVICE_STOP_DONE, applet); 927 rc_plugin_run (RC_HOOK_SERVICE_STOP_DONE, applet);
956 if (exclusive) 928 if (exclusive)
957 unlink (exclusive); 929 unlink (exclusive);
958 hook_out = 0; 930 hook_out = 0;
959 rc_plugin_run (RC_HOOK_SERVICE_STOP_OUT, applet); 931 rc_plugin_run (RC_HOOK_SERVICE_STOP_OUT, applet);
960
961} 932}
962 933
963static void svc_restart (bool deps) 934static void svc_restart (bool deps)
964{ 935{
965 /* This is hairly and a better way needs to be found I think! 936 /* This is hairly and a better way needs to be found I think!
1211 strcmp (optarg, "usesme") == 0 || 1182 strcmp (optarg, "usesme") == 0 ||
1212 strcmp (optarg, "iafter") == 0 || 1183 strcmp (optarg, "iafter") == 0 ||
1213 strcmp (optarg, "ibefore") == 0 || 1184 strcmp (optarg, "ibefore") == 0 ||
1214 strcmp (optarg, "iprovide") == 0) { 1185 strcmp (optarg, "iprovide") == 0) {
1215 int depoptions = RC_DEP_TRACE; 1186 int depoptions = RC_DEP_TRACE;
1187 const char *t[] = { optarg, NULL };
1188 const char *s[] = { applet, NULL };
1216 1189
1217 if (rc_env_bool ("RC_DEPEND_STRICT")) 1190 if (rc_env_bool ("RC_DEPEND_STRICT"))
1218 depoptions |= RC_DEP_STRICT; 1191 depoptions |= RC_DEP_STRICT;
1219 1192
1220 if (! deptree && ((deptree = _rc_deptree_load ()) == NULL)) 1193 if (! deptree && ((deptree = _rc_deptree_load ()) == NULL))
1221 eerrorx ("failed to load deptree"); 1194 eerrorx ("failed to load deptree");
1222 1195
1223 rc_strlist_free (types);
1224 types = NULL;
1225 rc_strlist_add (&types, optarg);
1226 rc_strlist_free (svclist);
1227 svclist = NULL;
1228 rc_strlist_add (&svclist, applet);
1229 rc_strlist_free (services); 1196 rc_strlist_free (services);
1230 services = rc_deptree_depends (deptree, types, svclist, 1197 services = rc_deptree_depends (deptree, t, s, softlevel, depoptions);
1231 softlevel, depoptions);
1232 STRLIST_FOREACH (services, svc, i) 1198 STRLIST_FOREACH (services, svc, i)
1233 printf ("%s%s", i == 1 ? "" : " ", svc); 1199 printf ("%s%s", i == 1 ? "" : " ", svc);
1234 if (services) 1200 if (services)
1235 printf ("\n"); 1201 printf ("\n");
1236 } else if (strcmp (optarg, "status") == 0) { 1202 } else if (strcmp (optarg, "status") == 0) {

Legend:
Removed from v.3039  
changed lines
  Added in v.3040

  ViewVC Help
Powered by ViewVC 1.1.20