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

Diff of /trunk/src/rc.c

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

Revision 2936 Revision 2950
143 char *fmt = NULL; 143 char *fmt = NULL;
144 int level = 0; 144 int level = 0;
145 145
146 if (strcmp (applet, "eval_ecolors") == 0) { 146 if (strcmp (applet, "eval_ecolors") == 0) {
147 printf ("GOOD='%s'\nWARN='%s'\nBAD='%s'\nHILITE='%s'\nBRACKET='%s'\nNORMAL='%s'\n", 147 printf ("GOOD='%s'\nWARN='%s'\nBAD='%s'\nHILITE='%s'\nBRACKET='%s'\nNORMAL='%s'\n",
148 ecolor (ecolor_good), 148 ecolor (ECOLOR_GOOD),
149 ecolor (ecolor_warn), 149 ecolor (ECOLOR_WARN),
150 ecolor (ecolor_bad), 150 ecolor (ECOLOR_BAD),
151 ecolor (ecolor_hilite), 151 ecolor (ECOLOR_HILITE),
152 ecolor (ecolor_bracket), 152 ecolor (ECOLOR_BRACKET),
153 ecolor (ecolor_normal)); 153 ecolor (ECOLOR_NORMAL));
154 exit (EXIT_SUCCESS); 154 exit (EXIT_SUCCESS);
155 } 155 }
156 156
157 if (argc > 0) { 157 if (argc > 0) {
158 158
267 267
268 if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0) 268 if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0)
269 eerrorx ("%s: no service specified", applet); 269 eerrorx ("%s: no service specified", applet);
270 270
271 if (strcmp (applet, "service_started") == 0) 271 if (strcmp (applet, "service_started") == 0)
272 ok = rc_service_state (argv[0], rc_service_started); 272 ok = rc_service_state (argv[0], RC_SERVICE_STARTED);
273 else if (strcmp (applet, "service_stopped") == 0) 273 else if (strcmp (applet, "service_stopped") == 0)
274 ok = rc_service_state (argv[0], rc_service_stopped); 274 ok = rc_service_state (argv[0], RC_SERVICE_STOPPED);
275 else if (strcmp (applet, "service_inactive") == 0) 275 else if (strcmp (applet, "service_inactive") == 0)
276 ok = rc_service_state (argv[0], rc_service_inactive); 276 ok = rc_service_state (argv[0], RC_SERVICE_INACTIVE);
277 else if (strcmp (applet, "service_starting") == 0) 277 else if (strcmp (applet, "service_starting") == 0)
278 ok = rc_service_state (argv[0], rc_service_starting); 278 ok = rc_service_state (argv[0], RC_SERVICE_STOPPING);
279 else if (strcmp (applet, "service_stopping") == 0) 279 else if (strcmp (applet, "service_stopping") == 0)
280 ok = rc_service_state (argv[0], rc_service_stopping); 280 ok = rc_service_state (argv[0], RC_SERVICE_STOPPING);
281 else if (strcmp (applet, "service_coldplugged") == 0) 281 else if (strcmp (applet, "service_coldplugged") == 0)
282 ok = rc_service_state (argv[0], rc_service_coldplugged); 282 ok = rc_service_state (argv[0], RC_SERVICE_COLDPLUGGED);
283 else if (strcmp (applet, "service_wasinactive") == 0) 283 else if (strcmp (applet, "service_wasinactive") == 0)
284 ok = rc_service_state (argv[0], rc_service_wasinactive); 284 ok = rc_service_state (argv[0], RC_SERVICE_WASINACTIVE);
285 else if (strcmp (applet, "service_started_daemon") == 0) { 285 else if (strcmp (applet, "service_started_daemon") == 0) {
286 int idx = 0; 286 int idx = 0;
287 if (argc > 2) 287 if (argc > 2)
288 sscanf (argv[2], "%d", &idx); 288 sscanf (argv[2], "%d", &idx);
289 exit (rc_service_started_daemon (argv[0], argv[1], idx) 289 exit (rc_service_started_daemon (argv[0], argv[1], idx)
301 301
302 if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0) 302 if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0)
303 eerrorx ("%s: no service specified", applet); 303 eerrorx ("%s: no service specified", applet);
304 304
305 if (strcmp (applet, "mark_service_started") == 0) 305 if (strcmp (applet, "mark_service_started") == 0)
306 ok = rc_mark_service (argv[0], rc_service_started); 306 ok = rc_mark_service (argv[0], RC_SERVICE_STARTED);
307 else if (strcmp (applet, "mark_service_stopped") == 0) 307 else if (strcmp (applet, "mark_service_stopped") == 0)
308 ok = rc_mark_service (argv[0], rc_service_stopped); 308 ok = rc_mark_service (argv[0], RC_SERVICE_STOPPED);
309 else if (strcmp (applet, "mark_service_inactive") == 0) 309 else if (strcmp (applet, "mark_service_inactive") == 0)
310 ok = rc_mark_service (argv[0], rc_service_inactive); 310 ok = rc_mark_service (argv[0], RC_SERVICE_INACTIVE);
311 else if (strcmp (applet, "mark_service_starting") == 0) 311 else if (strcmp (applet, "mark_service_starting") == 0)
312 ok = rc_mark_service (argv[0], rc_service_starting); 312 ok = rc_mark_service (argv[0], RC_SERVICE_STOPPING);
313 else if (strcmp (applet, "mark_service_stopping") == 0) 313 else if (strcmp (applet, "mark_service_stopping") == 0)
314 ok = rc_mark_service (argv[0], rc_service_stopping); 314 ok = rc_mark_service (argv[0], RC_SERVICE_STOPPING);
315 else if (strcmp (applet, "mark_service_coldplugged") == 0) 315 else if (strcmp (applet, "mark_service_coldplugged") == 0)
316 ok = rc_mark_service (argv[0], rc_service_coldplugged); 316 ok = rc_mark_service (argv[0], RC_SERVICE_COLDPLUGGED);
317 else 317 else
318 eerrorx ("%s: unknown applet", applet); 318 eerrorx ("%s: unknown applet", applet);
319 319
320 /* If we're marking ourselves then we need to inform our parent runscript 320 /* If we're marking ourselves then we need to inform our parent runscript
321 process so they do not mark us based on our exit code */ 321 process so they do not mark us based on our exit code */
662 signal (SIGCHLD, SIG_IGN); 662 signal (SIGCHLD, SIG_IGN);
663 for (pl = service_pids; pl; pl = pl->next) 663 for (pl = service_pids; pl; pl = pl->next)
664 kill (pl->pid, SIGTERM); 664 kill (pl->pid, SIGTERM);
665 665
666 /* Notify plugins we are aborting */ 666 /* Notify plugins we are aborting */
667 rc_plugin_run (rc_hook_abort, NULL); 667 rc_plugin_run (RC_HOOK_ABORT, NULL);
668 668
669 /* Only drop into single user mode if we're booting */ 669 /* Only drop into single user mode if we're booting */
670 if ((PREVLEVEL && 670 if ((PREVLEVEL &&
671 (strcmp (PREVLEVEL, "S") == 0 || 671 (strcmp (PREVLEVEL, "S") == 0 ||
672 strcmp (PREVLEVEL, "1") == 0)) || 672 strcmp (PREVLEVEL, "1") == 0)) ||
914 914
915 printf ("\n"); 915 printf ("\n");
916 printf (" %sGentoo/%s; %shttp://www.gentoo.org/%s" 916 printf (" %sGentoo/%s; %shttp://www.gentoo.org/%s"
917 "\n Copyright 1999-2007 Gentoo Foundation; " 917 "\n Copyright 1999-2007 Gentoo Foundation; "
918 "Distributed under the GPLv2\n\n", 918 "Distributed under the GPLv2\n\n",
919 ecolor (ecolor_good), uts.sysname, ecolor (ecolor_bracket), 919 ecolor (ECOLOR_GOOD), uts.sysname, ecolor (ECOLOR_BRACKET),
920 ecolor (ecolor_normal)); 920 ecolor (ECOLOR_NORMAL));
921 921
922 if (rc_env_bool ("RC_INTERACTIVE")) 922 if (rc_env_bool ("RC_INTERACTIVE"))
923 printf ("Press %sI%s to enter interactive boot mode\n\n", 923 printf ("Press %sI%s to enter interactive boot mode\n\n",
924 ecolor (ecolor_good), ecolor (ecolor_normal)); 924 ecolor (ECOLOR_GOOD), ecolor (ECOLOR_NORMAL));
925 925
926 setenv ("RC_SOFTLEVEL", newlevel, 1); 926 setenv ("RC_SOFTLEVEL", newlevel, 1);
927 rc_plugin_run (rc_hook_runlevel_start_in, newlevel); 927 rc_plugin_run (RC_HOOK_RUNLEVEL_START_IN, newlevel);
928 run_script (INITSH); 928 run_script (INITSH);
929 929
930#ifdef __linux__ 930#ifdef __linux__
931 /* If we requested a softlevel, save it now */ 931 /* If we requested a softlevel, save it now */
932 set_ksoftlevel (NULL); 932 set_ksoftlevel (NULL);
934 set_ksoftlevel (cmd); 934 set_ksoftlevel (cmd);
935 free (cmd); 935 free (cmd);
936 } 936 }
937 937
938#endif 938#endif
939 rc_plugin_run (rc_hook_runlevel_start_out, newlevel); 939 rc_plugin_run (RC_HOOK_RUNLEVEL_START_OUT, newlevel);
940 940
941 if (want_interactive ()) 941 if (want_interactive ())
942 mark_interactive (); 942 mark_interactive ();
943 943
944 exit (EXIT_SUCCESS); 944 exit (EXIT_SUCCESS);
1005 strcmp (newlevel, RC_LEVEL_SINGLE) == 0)) 1005 strcmp (newlevel, RC_LEVEL_SINGLE) == 0))
1006 { 1006 {
1007 going_down = true; 1007 going_down = true;
1008 rc_set_runlevel (newlevel); 1008 rc_set_runlevel (newlevel);
1009 setenv ("RC_SOFTLEVEL", newlevel, 1); 1009 setenv ("RC_SOFTLEVEL", newlevel, 1);
1010 rc_plugin_run (rc_hook_runlevel_stop_in, newlevel); 1010 rc_plugin_run (RC_HOOK_RUNLEVEL_STOP_IN, newlevel);
1011 } else { 1011 } else {
1012 rc_plugin_run (rc_hook_runlevel_stop_in, runlevel); 1012 rc_plugin_run (RC_HOOK_RUNLEVEL_STOP_IN, runlevel);
1013 } 1013 }
1014 1014
1015 /* Check if runlevel is valid if we're changing */ 1015 /* Check if runlevel is valid if we're changing */
1016 if (newlevel && strcmp (runlevel, newlevel) != 0 && ! going_down) { 1016 if (newlevel && strcmp (runlevel, newlevel) != 0 && ! going_down) {
1017 tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel, (char *) NULL); 1017 tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel, (char *) NULL);
1039 start_services = rc_ls_dir (DEVBOOT, RC_LS_INITD); 1039 start_services = rc_ls_dir (DEVBOOT, RC_LS_INITD);
1040 rc_rm_dir (DEVBOOT, true); 1040 rc_rm_dir (DEVBOOT, true);
1041 1041
1042 STRLIST_FOREACH (start_services, service, i) 1042 STRLIST_FOREACH (start_services, service, i)
1043 if (rc_allow_plug (service)) 1043 if (rc_allow_plug (service))
1044 rc_mark_service (service, rc_service_coldplugged); 1044 rc_mark_service (service, RC_SERVICE_COLDPLUGGED);
1045 /* We need to dump this list now. 1045 /* We need to dump this list now.
1046 This may seem redunant, but only Linux needs this and saves on 1046 This may seem redunant, but only Linux needs this and saves on
1047 code bloat. */ 1047 code bloat. */
1048 rc_strlist_free (start_services); 1048 rc_strlist_free (start_services);
1049 start_services = NULL; 1049 start_services = NULL;
1064 STRLIST_FOREACH (start_services, service, i) { 1064 STRLIST_FOREACH (start_services, service, i) {
1065 j = (strlen ("net.") + strlen (service) + 1); 1065 j = (strlen ("net.") + strlen (service) + 1);
1066 tmp = rc_xmalloc (sizeof (char *) * j); 1066 tmp = rc_xmalloc (sizeof (char *) * j);
1067 snprintf (tmp, j, "net.%s", service); 1067 snprintf (tmp, j, "net.%s", service);
1068 if (rc_service_exists (tmp) && rc_allow_plug (tmp)) 1068 if (rc_service_exists (tmp) && rc_allow_plug (tmp))
1069 rc_mark_service (tmp, rc_service_coldplugged); 1069 rc_mark_service (tmp, RC_SERVICE_COLDPLUGGED);
1070 CHAR_FREE (tmp); 1070 CHAR_FREE (tmp);
1071 } 1071 }
1072 rc_strlist_free (start_services); 1072 rc_strlist_free (start_services);
1073#endif 1073#endif
1074 1074
1083 if (p && isdigit (*p)) { 1083 if (p && isdigit (*p)) {
1084 j = (strlen ("moused.") + strlen (service) + 1); 1084 j = (strlen ("moused.") + strlen (service) + 1);
1085 tmp = rc_xmalloc (sizeof (char *) * j); 1085 tmp = rc_xmalloc (sizeof (char *) * j);
1086 snprintf (tmp, j, "moused.%s", service); 1086 snprintf (tmp, j, "moused.%s", service);
1087 if (rc_service_exists (tmp) && rc_allow_plug (tmp)) 1087 if (rc_service_exists (tmp) && rc_allow_plug (tmp))
1088 rc_mark_service (tmp, rc_service_coldplugged); 1088 rc_mark_service (tmp, RC_SERVICE_COLDPLUGGED);
1089 CHAR_FREE (tmp); 1089 CHAR_FREE (tmp);
1090 } 1090 }
1091 } 1091 }
1092 } 1092 }
1093 rc_strlist_free (start_services); 1093 rc_strlist_free (start_services);
1178 char **stopdeps = NULL; 1178 char **stopdeps = NULL;
1179 char *svc1 = NULL; 1179 char *svc1 = NULL;
1180 char *svc2 = NULL; 1180 char *svc2 = NULL;
1181 int k; 1181 int k;
1182 1182
1183 if (rc_service_state (service, rc_service_stopped)) 1183 if (rc_service_state (service, RC_SERVICE_STOPPED))
1184 continue; 1184 continue;
1185 1185
1186 /* We always stop the service when in these runlevels */ 1186 /* We always stop the service when in these runlevels */
1187 if (going_down) { 1187 if (going_down) {
1188 pid_t pid = rc_stop_service (service); 1188 pid_t pid = rc_stop_service (service);
1222 if (!found) 1222 if (!found)
1223 continue; 1223 continue;
1224 } 1224 }
1225 } else { 1225 } else {
1226 /* Allow coldplugged services not to be in the runlevels list */ 1226 /* Allow coldplugged services not to be in the runlevels list */
1227 if (rc_service_state (service, rc_service_coldplugged)) 1227 if (rc_service_state (service, RC_SERVICE_COLDPLUGGED))
1228 continue; 1228 continue;
1229 } 1229 }
1230 1230
1231 /* We got this far! Or last check is to see if any any service that 1231 /* We got this far! Or last check is to see if any any service that
1232 going to be started depends on us */ 1232 going to be started depends on us */
1260 1260
1261 /* Wait for our services to finish */ 1261 /* Wait for our services to finish */
1262 wait_for_services (); 1262 wait_for_services ();
1263 1263
1264 /* Notify the plugins we have finished */ 1264 /* Notify the plugins we have finished */
1265 rc_plugin_run (rc_hook_runlevel_stop_out, runlevel); 1265 rc_plugin_run (RC_HOOK_RUNLEVEL_STOP_OUT, runlevel);
1266 1266
1267 rmdir (RC_STOPPING); 1267 rmdir (RC_STOPPING);
1268 1268
1269 /* Store the new runlevel */ 1269 /* Store the new runlevel */
1270 if (newlevel) { 1270 if (newlevel) {
1288 unlink (INTERACTIVE); 1288 unlink (INTERACTIVE);
1289 sulogin (false); 1289 sulogin (false);
1290 } 1290 }
1291 1291
1292 mkdir (RC_STARTING, 0755); 1292 mkdir (RC_STARTING, 0755);
1293 rc_plugin_run (rc_hook_runlevel_start_in, runlevel); 1293 rc_plugin_run (RC_HOOK_RUNLEVEL_START_IN, runlevel);
1294 1294
1295 /* Re-add our coldplugged services if they stopped */ 1295 /* Re-add our coldplugged services if they stopped */
1296 STRLIST_FOREACH (coldplugged_services, service, i) 1296 STRLIST_FOREACH (coldplugged_services, service, i)
1297 rc_mark_service (service, rc_service_coldplugged); 1297 rc_mark_service (service, RC_SERVICE_COLDPLUGGED);
1298 1298
1299 /* Order the services to start */ 1299 /* Order the services to start */
1300 rc_strlist_add (&types, "ineed"); 1300 rc_strlist_add (&types, "ineed");
1301 rc_strlist_add (&types, "iuse"); 1301 rc_strlist_add (&types, "iuse");
1302 rc_strlist_add (&types, "iafter"); 1302 rc_strlist_add (&types, "iafter");
1314 if ((service = proc_getent ("noinitd"))) { 1314 if ((service = proc_getent ("noinitd"))) {
1315 char *p = service; 1315 char *p = service;
1316 char *token; 1316 char *token;
1317 1317
1318 while ((token = strsep (&p, ","))) 1318 while ((token = strsep (&p, ",")))
1319 rc_mark_service (token, rc_service_started); 1319 rc_mark_service (token, RC_SERVICE_STARTED);
1320 free (service); 1320 free (service);
1321 } 1321 }
1322 } 1322 }
1323#endif 1323#endif
1324 1324
1325 1325
1326 STRLIST_FOREACH (start_services, service, i) { 1326 STRLIST_FOREACH (start_services, service, i) {
1327 if (rc_service_state (service, rc_service_stopped)) { 1327 if (rc_service_state (service, RC_SERVICE_STOPPED)) {
1328 pid_t pid; 1328 pid_t pid;
1329 1329
1330 if (! interactive) 1330 if (! interactive)
1331 interactive = want_interactive (); 1331 interactive = want_interactive ();
1332 1332
1360 } 1360 }
1361 1361
1362 /* Wait for our services to finish */ 1362 /* Wait for our services to finish */
1363 wait_for_services (); 1363 wait_for_services ();
1364 1364
1365 rc_plugin_run (rc_hook_runlevel_start_out, runlevel); 1365 rc_plugin_run (RC_HOOK_RUNLEVEL_START_OUT, runlevel);
1366 1366
1367#ifdef __linux__ 1367#ifdef __linux__
1368 /* mark any services skipped as stopped */ 1368 /* mark any services skipped as stopped */
1369 if (PREVLEVEL && strcmp (PREVLEVEL, "N") == 0) { 1369 if (PREVLEVEL && strcmp (PREVLEVEL, "N") == 0) {
1370 if ((service = proc_getent ("noinitd"))) { 1370 if ((service = proc_getent ("noinitd"))) {
1371 char *p = service; 1371 char *p = service;
1372 char *token; 1372 char *token;
1373 1373
1374 while ((token = strsep (&p, ","))) 1374 while ((token = strsep (&p, ",")))
1375 rc_mark_service (token, rc_service_stopped); 1375 rc_mark_service (token, RC_SERVICE_STOPPED);
1376 free (service); 1376 free (service);
1377 } 1377 }
1378 } 1378 }
1379#endif 1379#endif
1380 1380

Legend:
Removed from v.2936  
changed lines
  Added in v.2950

  ViewVC Help
Powered by ViewVC 1.1.20