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

Diff of /trunk/src/rc.c

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

Revision 2927 Revision 2928
107 rc_free_deptree (deptree); 107 rc_free_deptree (deptree);
108 rc_strlist_free (types); 108 rc_strlist_free (types);
109 109
110 /* Clean runlevel start, stop markers */ 110 /* Clean runlevel start, stop markers */
111 if (! rc_in_plugin) { 111 if (! rc_in_plugin) {
112 if (rc_is_dir (RC_STARTING) == 0) 112 if (rc_is_dir (RC_STARTING))
113 rc_rm_dir (RC_STARTING, true); 113 rc_rm_dir (RC_STARTING, true);
114 if (rc_is_dir (RC_STOPPING) == 0) 114 if (rc_is_dir (RC_STOPPING))
115 rc_rm_dir (RC_STOPPING, true); 115 rc_rm_dir (RC_STOPPING, true);
116 } 116 }
117 } 117 }
118 118
119 free (applet); 119 free (applet);
261 return (retval); 261 return (retval);
262} 262}
263 263
264static int do_service (int argc, char **argv) 264static int do_service (int argc, char **argv)
265{ 265{
266 int ok = -1; 266 bool ok = false;
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)
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 ok = rc_service_started_daemon (argv[0], argv[1], idx); 289 exit (rc_service_started_daemon (argv[0], argv[1], idx)
290 ? 0 : 1);
290 } else 291 } else
291 eerrorx ("%s: unknown applet", applet); 292 eerrorx ("%s: unknown applet", applet);
292 293
293 return (ok); 294 return (ok ? EXIT_SUCCESS : EXIT_FAILURE);
294} 295}
295 296
296static int do_mark_service (int argc, char **argv) 297static int do_mark_service (int argc, char **argv)
297{ 298{
298 int ok = -1; 299 bool ok = false;
299 char *svcname = getenv ("SVCNAME"); 300 char *svcname = getenv ("SVCNAME");
300 301
301 if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0) 302 if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0)
302 eerrorx ("%s: no service specified", applet); 303 eerrorx ("%s: no service specified", applet);
303 304
316 else 317 else
317 eerrorx ("%s: unknown applet", applet); 318 eerrorx ("%s: unknown applet", applet);
318 319
319 /* 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
320 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 */
321 if (ok == 0 && svcname && strcmp (svcname, argv[0]) == 0) { 322 if (ok && svcname && strcmp (svcname, argv[0]) == 0) {
322 char *runscript_pid = getenv ("RC_RUNSCRIPT_PID"); 323 char *runscript_pid = getenv ("RC_RUNSCRIPT_PID");
323 char *mtime; 324 char *mtime;
324 pid_t pid = 0; 325 pid_t pid = 0;
325 int l; 326 int l;
326 327
336 strlen (runscript_pid) + 337 strlen (runscript_pid) +
337 4; 338 4;
338 mtime = rc_xmalloc (l); 339 mtime = rc_xmalloc (l);
339 snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s", 340 snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s",
340 svcname, runscript_pid); 341 svcname, runscript_pid);
341 if (rc_exists (mtime) == 0 && unlink (mtime) != 0) 342 if (rc_exists (mtime) && unlink (mtime) != 0)
342 eerror ("%s: unlink: %s", applet, strerror (errno)); 343 eerror ("%s: unlink: %s", applet, strerror (errno));
343 free (mtime); 344 free (mtime);
344 } 345 }
345 346
346 return (ok); 347 return (ok ? EXIT_SUCCESS : EXIT_FAILURE);
347} 348}
348 349
349static int do_options (int argc, char **argv) 350static int do_options (int argc, char **argv)
350{ 351{
351 int ok = -1; 352 bool ok = false;
352 char *service = getenv ("SVCNAME"); 353 char *service = getenv ("SVCNAME");
353 354
354 if (! service) 355 if (! service)
355 eerrorx ("%s: no service specified", applet); 356 eerrorx ("%s: no service specified", applet);
356 357
360 if (strcmp (applet, "get_options") == 0) { 361 if (strcmp (applet, "get_options") == 0) {
361 char *option = rc_get_service_option (service, argv[0]); 362 char *option = rc_get_service_option (service, argv[0]);
362 if (option) { 363 if (option) {
363 printf ("%s", option); 364 printf ("%s", option);
364 free (option); 365 free (option);
365 ok = 0; 366 ok = true;
366 } 367 }
367 } else if (strcmp (applet, "save_options") == 0) 368 } else if (strcmp (applet, "save_options") == 0)
368 ok = rc_set_service_option (service, argv[0], argv[1]); 369 ok = rc_set_service_option (service, argv[0], argv[1]);
369 else 370 else
370 eerrorx ("%s: unknown applet", applet); 371 eerrorx ("%s: unknown applet", applet);
371 372
372 return (ok); 373 return (ok ? EXIT_SUCCESS : EXIT_FAILURE);
373} 374}
374 375
375#ifdef __linux__ 376#ifdef __linux__
376static char *proc_getent (const char *ent) 377static char *proc_getent (const char *ent)
377{ 378{
379 char buffer[RC_LINEBUFFER]; 380 char buffer[RC_LINEBUFFER];
380 char *p; 381 char *p;
381 char *value = NULL; 382 char *value = NULL;
382 int i; 383 int i;
383 384
384 if (rc_exists ("/proc/cmdline") != 0) 385 if (! rc_exists ("/proc/cmdline"))
385 return (NULL); 386 return (NULL);
386 387
387 if (! (fp = fopen ("/proc/cmdline", "r"))) { 388 if (! (fp = fopen ("/proc/cmdline", "r"))) {
388 eerror ("failed to open `/proc/cmdline': %s", strerror (errno)); 389 eerror ("failed to open `/proc/cmdline': %s", strerror (errno));
389 return (NULL); 390 return (NULL);
542 if (! runlevel || 543 if (! runlevel ||
543 strcmp (runlevel, getenv ("RC_BOOTLEVEL")) == 0 || 544 strcmp (runlevel, getenv ("RC_BOOTLEVEL")) == 0 ||
544 strcmp (runlevel, RC_LEVEL_SINGLE) == 0 || 545 strcmp (runlevel, RC_LEVEL_SINGLE) == 0 ||
545 strcmp (runlevel, RC_LEVEL_SYSINIT) == 0) 546 strcmp (runlevel, RC_LEVEL_SYSINIT) == 0)
546 { 547 {
547 if (rc_exists (RC_KSOFTLEVEL) == 0 && 548 if (rc_exists (RC_KSOFTLEVEL) &&
548 unlink (RC_KSOFTLEVEL) != 0) 549 unlink (RC_KSOFTLEVEL) != 0)
549 eerror ("unlink `%s': %s", RC_KSOFTLEVEL, strerror (errno)); 550 eerror ("unlink `%s': %s", RC_KSOFTLEVEL, strerror (errno));
550 return; 551 return;
551 } 552 }
552 553
562static int get_ksoftlevel (char *buffer, int buffer_len) 563static int get_ksoftlevel (char *buffer, int buffer_len)
563{ 564{
564 FILE *fp; 565 FILE *fp;
565 int i = 0; 566 int i = 0;
566 567
567 if (rc_exists (RC_KSOFTLEVEL) != 0) 568 if (! rc_exists (RC_KSOFTLEVEL))
568 return (0); 569 return (0);
569 570
570 if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) { 571 if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) {
571 eerror ("fopen `%s': %s", RC_KSOFTLEVEL, strerror (errno)); 572 eerror ("fopen `%s': %s", RC_KSOFTLEVEL, strerror (errno));
572 return (-1); 573 return (-1);
781 782
782 if (strncmp (applet, "mark_service_", strlen ("mark_service_")) == 0) 783 if (strncmp (applet, "mark_service_", strlen ("mark_service_")) == 0)
783 exit (do_mark_service (argc, argv)); 784 exit (do_mark_service (argc, argv));
784 785
785 if (strcmp (applet, "is_runlevel_start") == 0) 786 if (strcmp (applet, "is_runlevel_start") == 0)
786 exit (rc_runlevel_starting ()); 787 exit (rc_runlevel_starting () ? 0 : 1);
787 else if (strcmp (applet, "is_runlevel_stop") == 0) 788 else if (strcmp (applet, "is_runlevel_stop") == 0)
788 exit (rc_runlevel_stopping ()); 789 exit (rc_runlevel_stopping () ? 0 : 1);
789 790
790 if (strcmp (applet, "rc-abort") == 0) { 791 if (strcmp (applet, "rc-abort") == 0) {
791 char *p = getenv ("RC_PID"); 792 char *p = getenv ("RC_PID");
792 pid_t pid = 0; 793 pid_t pid = 0;
793 794
877 878
878 /* Export our PID */ 879 /* Export our PID */
879 snprintf (pidstr, sizeof (pidstr), "%d", getpid ()); 880 snprintf (pidstr, sizeof (pidstr), "%d", getpid ());
880 setenv ("RC_PID", pidstr, 1); 881 setenv ("RC_PID", pidstr, 1);
881 882
882 interactive = (rc_exists (INTERACTIVE) == 0); 883 interactive = rc_exists (INTERACTIVE);
883 rc_plugin_load (); 884 rc_plugin_load ();
884 885
885 /* Load current softlevel */ 886 /* Load current softlevel */
886 bootlevel = getenv ("RC_BOOTLEVEL"); 887 bootlevel = getenv ("RC_BOOTLEVEL");
887 runlevel = rc_get_runlevel (); 888 runlevel = rc_get_runlevel ();
904#endif 905#endif
905 906
906 /* exec init-early.sh if it exists 907 /* exec init-early.sh if it exists
907 * This should just setup the console to use the correct 908 * This should just setup the console to use the correct
908 * font. Maybe it should setup the keyboard too? */ 909 * font. Maybe it should setup the keyboard too? */
909 if (rc_exists (INITEARLYSH) == 0) 910 if (rc_exists (INITEARLYSH))
910 run_script (INITEARLYSH); 911 run_script (INITEARLYSH);
911 912
912 uname (&uts); 913 uname (&uts);
913 914
914 printf ("\n"); 915 printf ("\n");
1012 } 1013 }
1013 1014
1014 /* Check if runlevel is valid if we're changing */ 1015 /* Check if runlevel is valid if we're changing */
1015 if (newlevel && strcmp (runlevel, newlevel) != 0 && ! going_down) { 1016 if (newlevel && strcmp (runlevel, newlevel) != 0 && ! going_down) {
1016 tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel, (char *) NULL); 1017 tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel, (char *) NULL);
1017 if (rc_is_dir (tmp) != 0) 1018 if (! rc_is_dir (tmp))
1018 eerrorx ("%s: is not a valid runlevel", newlevel); 1019 eerrorx ("%s: is not a valid runlevel", newlevel);
1019 CHAR_FREE (tmp); 1020 CHAR_FREE (tmp);
1020 } 1021 }
1021 1022
1022 /* Load our deptree now */ 1023 /* Load our deptree now */
1023 if ((deptree = rc_load_deptree ()) == NULL) 1024 if ((deptree = rc_load_deptree ()) == NULL)
1024 eerrorx ("failed to load deptree"); 1025 eerrorx ("failed to load deptree");
1025 1026
1026 /* Clean the failed services state dir now */ 1027 /* Clean the failed services state dir now */
1027 if (rc_is_dir (RC_SVCDIR "/failed") == 0) 1028 if (rc_is_dir (RC_SVCDIR "/failed"))
1028 rc_rm_dir (RC_SVCDIR "/failed", false); 1029 rc_rm_dir (RC_SVCDIR "/failed", false);
1029 1030
1030 mkdir (RC_STOPPING, 0755); 1031 mkdir (RC_STOPPING, 0755);
1031 1032
1032#ifdef __linux__ 1033#ifdef __linux__
1033 /* udev likes to start services before we're ready when it does 1034 /* udev likes to start services before we're ready when it does
1034 its coldplugging thing. runscript knows when we're not ready so it 1035 its coldplugging thing. runscript knows when we're not ready so it
1035 stores a list of coldplugged services in DEVBOOT for us to pick up 1036 stores a list of coldplugged services in DEVBOOT for us to pick up
1036 here when we are ready for them */ 1037 here when we are ready for them */
1037 if (rc_is_dir (DEVBOOT) == 0) { 1038 if (rc_is_dir (DEVBOOT)) {
1038 start_services = rc_ls_dir (DEVBOOT, RC_LS_INITD); 1039 start_services = rc_ls_dir (DEVBOOT, RC_LS_INITD);
1039 rc_rm_dir (DEVBOOT, true); 1040 rc_rm_dir (DEVBOOT, true);
1040 1041
1041 STRLIST_FOREACH (start_services, service, i) 1042 STRLIST_FOREACH (start_services, service, i)
1042 if (rc_allow_plug (service) == 0) 1043 if (rc_allow_plug (service))
1043 rc_mark_service (service, rc_service_coldplugged); 1044 rc_mark_service (service, rc_service_coldplugged);
1044 /* We need to dump this list now. 1045 /* We need to dump this list now.
1045 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
1046 code bloat. */ 1047 code bloat. */
1047 rc_strlist_free (start_services); 1048 rc_strlist_free (start_services);
1062 start_services = rc_ls_dir ("/dev/net", 0); 1063 start_services = rc_ls_dir ("/dev/net", 0);
1063 STRLIST_FOREACH (start_services, service, i) { 1064 STRLIST_FOREACH (start_services, service, i) {
1064 j = (strlen ("net.") + strlen (service) + 1); 1065 j = (strlen ("net.") + strlen (service) + 1);
1065 tmp = rc_xmalloc (sizeof (char *) * j); 1066 tmp = rc_xmalloc (sizeof (char *) * j);
1066 snprintf (tmp, j, "net.%s", service); 1067 snprintf (tmp, j, "net.%s", service);
1067 if (rc_service_exists (tmp) == 0 && rc_allow_plug (tmp) == 0) 1068 if (rc_service_exists (tmp) && rc_allow_plug (tmp))
1068 rc_mark_service (tmp, rc_service_coldplugged); 1069 rc_mark_service (tmp, rc_service_coldplugged);
1069 CHAR_FREE (tmp); 1070 CHAR_FREE (tmp);
1070 } 1071 }
1071 rc_strlist_free (start_services); 1072 rc_strlist_free (start_services);
1072#endif 1073#endif
1081 char *p = service + 3; 1082 char *p = service + 3;
1082 if (p && isdigit (*p)) { 1083 if (p && isdigit (*p)) {
1083 j = (strlen ("moused.") + strlen (service) + 1); 1084 j = (strlen ("moused.") + strlen (service) + 1);
1084 tmp = rc_xmalloc (sizeof (char *) * j); 1085 tmp = rc_xmalloc (sizeof (char *) * j);
1085 snprintf (tmp, j, "moused.%s", service); 1086 snprintf (tmp, j, "moused.%s", service);
1086 if (rc_service_exists (tmp) == 0 && rc_allow_plug (tmp) == 0) 1087 if (rc_service_exists (tmp) && rc_allow_plug (tmp))
1087 rc_mark_service (tmp, rc_service_coldplugged); 1088 rc_mark_service (tmp, rc_service_coldplugged);
1088 CHAR_FREE (tmp); 1089 CHAR_FREE (tmp);
1089 } 1090 }
1090 } 1091 }
1091 } 1092 }
1177 char **stopdeps = NULL; 1178 char **stopdeps = NULL;
1178 char *svc1 = NULL; 1179 char *svc1 = NULL;
1179 char *svc2 = NULL; 1180 char *svc2 = NULL;
1180 int k; 1181 int k;
1181 1182
1182 if (rc_service_state (service, rc_service_stopped) == 0) 1183 if (rc_service_state (service, rc_service_stopped))
1183 continue; 1184 continue;
1184 1185
1185 /* We always stop the service when in these runlevels */ 1186 /* We always stop the service when in these runlevels */
1186 if (going_down) { 1187 if (going_down) {
1187 pid_t pid = rc_stop_service (service); 1188 pid_t pid = rc_stop_service (service);
1205 1206
1206 len = strlen (service) + strlen (runlevel) + 2; 1207 len = strlen (service) + strlen (runlevel) + 2;
1207 tmp = rc_xmalloc (sizeof (char *) * len); 1208 tmp = rc_xmalloc (sizeof (char *) * len);
1208 snprintf (tmp, len, "%s.%s", service, runlevel); 1209 snprintf (tmp, len, "%s.%s", service, runlevel);
1209 conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); 1210 conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
1210 found = (rc_exists (conf) == 0); 1211 found = rc_exists (conf);
1211 CHAR_FREE (conf); 1212 CHAR_FREE (conf);
1212 CHAR_FREE (tmp); 1213 CHAR_FREE (tmp);
1213 if (! found) { 1214 if (! found) {
1214 len = strlen (service) + strlen (newlevel) + 2; 1215 len = strlen (service) + strlen (newlevel) + 2;
1215 tmp = rc_xmalloc (sizeof (char *) * len); 1216 tmp = rc_xmalloc (sizeof (char *) * len);
1216 snprintf (tmp, len, "%s.%s", service, newlevel); 1217 snprintf (tmp, len, "%s.%s", service, newlevel);
1217 conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); 1218 conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
1218 found = (rc_exists (conf) == 0); 1219 found = rc_exists (conf);
1219 CHAR_FREE (conf); 1220 CHAR_FREE (conf);
1220 CHAR_FREE (tmp); 1221 CHAR_FREE (tmp);
1221 if (!found) 1222 if (!found)
1222 continue; 1223 continue;
1223 } 1224 }
1224 } else { 1225 } else {
1225 /* Allow coldplugged services not to be in the runlevels list */ 1226 /* Allow coldplugged services not to be in the runlevels list */
1226 if (rc_service_state (service, rc_service_coldplugged) == 0) 1227 if (rc_service_state (service, rc_service_coldplugged))
1227 continue; 1228 continue;
1228 } 1229 }
1229 1230
1230 /* 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
1231 going to be started depends on us */ 1232 going to be started depends on us */
1281 applet, HALTSH, strerror (errno)); 1282 applet, HALTSH, strerror (errno));
1282 } 1283 }
1283 1284
1284 /* Single user is done now */ 1285 /* Single user is done now */
1285 if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0) { 1286 if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0) {
1286 if (rc_exists (INTERACTIVE) == 0) 1287 if (rc_exists (INTERACTIVE))
1287 unlink (INTERACTIVE); 1288 unlink (INTERACTIVE);
1288 sulogin (false); 1289 sulogin (false);
1289 } 1290 }
1290 1291
1291 mkdir (RC_STARTING, 0755); 1292 mkdir (RC_STARTING, 0755);
1321 } 1322 }
1322#endif 1323#endif
1323 1324
1324 1325
1325 STRLIST_FOREACH (start_services, service, i) { 1326 STRLIST_FOREACH (start_services, service, i) {
1326 if (rc_service_state (service, rc_service_stopped) == 0) { 1327 if (rc_service_state (service, rc_service_stopped)) {
1327 pid_t pid; 1328 pid_t pid;
1328 1329
1329 if (! interactive) 1330 if (! interactive)
1330 interactive = want_interactive (); 1331 interactive = want_interactive ();
1331 1332
1379 1380
1380 /* Store our interactive status for boot */ 1381 /* Store our interactive status for boot */
1381 if (interactive && strcmp (runlevel, bootlevel) == 0) 1382 if (interactive && strcmp (runlevel, bootlevel) == 0)
1382 mark_interactive (); 1383 mark_interactive ();
1383 else { 1384 else {
1384 if (rc_exists (INTERACTIVE) == 0) 1385 if (rc_exists (INTERACTIVE))
1385 unlink (INTERACTIVE); 1386 unlink (INTERACTIVE);
1386 } 1387 }
1387 1388
1388 return (EXIT_SUCCESS); 1389 return (EXIT_SUCCESS);
1389} 1390}

Legend:
Removed from v.2927  
changed lines
  Added in v.2928

  ViewVC Help
Powered by ViewVC 1.1.20