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

Diff of /trunk/src/rc.c

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

Revision 3007 Revision 3008
190 190
191 if (argc > 0) { 191 if (argc > 0) {
192 for (i = 0; i < argc; i++) 192 for (i = 0; i < argc; i++)
193 l += strlen (argv[i]) + 1; 193 l += strlen (argv[i]) + 1;
194 194
195 message = rc_xmalloc (l); 195 message = xmalloc (l);
196 p = message; 196 p = message;
197 197
198 for (i = 0; i < argc; i++) { 198 for (i = 0; i < argc; i++) {
199 if (i > 0) 199 if (i > 0)
200 *p++ = ' '; 200 *p++ = ' ';
203 } 203 }
204 *p = 0; 204 *p = 0;
205 } 205 }
206 206
207 if (message) 207 if (message)
208 fmt = rc_xstrdup ("%s"); 208 fmt = strdup ("%s");
209 209
210 if (strcmp (applet, "einfo") == 0) 210 if (strcmp (applet, "einfo") == 0)
211 einfo (fmt, message); 211 einfo (fmt, message);
212 else if (strcmp (applet, "einfon") == 0) 212 else if (strcmp (applet, "einfon") == 0)
213 einfon (fmt, message); 213 einfon (fmt, message);
336 in control as well */ 336 in control as well */
337 l = strlen (RC_SVCDIR "exclusive") + 337 l = strlen (RC_SVCDIR "exclusive") +
338 strlen (svcname) + 338 strlen (svcname) +
339 strlen (runscript_pid) + 339 strlen (runscript_pid) +
340 4; 340 4;
341 mtime = rc_xmalloc (l); 341 mtime = xmalloc (l);
342 snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s", 342 snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s",
343 svcname, runscript_pid); 343 svcname, runscript_pid);
344 if (rc_exists (mtime) && unlink (mtime) != 0) 344 if (exists (mtime) && unlink (mtime) != 0)
345 eerror ("%s: unlink: %s", applet, strerror (errno)); 345 eerror ("%s: unlink: %s", applet, strerror (errno));
346 free (mtime); 346 free (mtime);
347 } 347 }
348 348
349 return (ok ? EXIT_SUCCESS : EXIT_FAILURE); 349 return (ok ? EXIT_SUCCESS : EXIT_FAILURE);
382 char buffer[RC_LINEBUFFER]; 382 char buffer[RC_LINEBUFFER];
383 char *p; 383 char *p;
384 char *value = NULL; 384 char *value = NULL;
385 int i; 385 int i;
386 386
387 if (! rc_exists ("/proc/cmdline")) 387 if (! exists ("/proc/cmdline"))
388 return (NULL); 388 return (NULL);
389 389
390 if (! (fp = fopen ("/proc/cmdline", "r"))) { 390 if (! (fp = fopen ("/proc/cmdline", "r"))) {
391 eerror ("failed to open `/proc/cmdline': %s", strerror (errno)); 391 eerror ("failed to open `/proc/cmdline': %s", strerror (errno));
392 return (NULL); 392 return (NULL);
426 return (false); 426 return (false);
427 427
428 /* Now save our terminal settings. We need to restore them at exit as we 428 /* Now save our terminal settings. We need to restore them at exit as we
429 will be changing it for non-blocking reads for Interactive */ 429 will be changing it for non-blocking reads for Interactive */
430 if (! termios_orig) { 430 if (! termios_orig) {
431 termios_orig = rc_xmalloc (sizeof (struct termios)); 431 termios_orig = xmalloc (sizeof (struct termios));
432 tcgetattr (fd, termios_orig); 432 tcgetattr (fd, termios_orig);
433 } 433 }
434 434
435 tcgetattr (fd, &termios); 435 tcgetattr (fd, &termios);
436 termios.c_lflag &= ~(ICANON | ECHO); 436 termios.c_lflag &= ~(ICANON | ECHO);
545 if (! level || 545 if (! level ||
546 strcmp (level, getenv ("RC_BOOTLEVEL")) == 0 || 546 strcmp (level, getenv ("RC_BOOTLEVEL")) == 0 ||
547 strcmp (level, RC_LEVEL_SINGLE) == 0 || 547 strcmp (level, RC_LEVEL_SINGLE) == 0 ||
548 strcmp (level, RC_LEVEL_SYSINIT) == 0) 548 strcmp (level, RC_LEVEL_SYSINIT) == 0)
549 { 549 {
550 if (rc_exists (RC_KSOFTLEVEL) && 550 if (exists (RC_KSOFTLEVEL) &&
551 unlink (RC_KSOFTLEVEL) != 0) 551 unlink (RC_KSOFTLEVEL) != 0)
552 eerror ("unlink `%s': %s", RC_KSOFTLEVEL, strerror (errno)); 552 eerror ("unlink `%s': %s", RC_KSOFTLEVEL, strerror (errno));
553 return; 553 return;
554 } 554 }
555 555
565static int get_ksoftlevel (char *buffer, int buffer_len) 565static int get_ksoftlevel (char *buffer, int buffer_len)
566{ 566{
567 FILE *fp; 567 FILE *fp;
568 int i = 0; 568 int i = 0;
569 569
570 if (! rc_exists (RC_KSOFTLEVEL)) 570 if (! exists (RC_KSOFTLEVEL))
571 return (0); 571 return (0);
572 572
573 if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) { 573 if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) {
574 eerror ("fopen `%s': %s", RC_KSOFTLEVEL, strerror (errno)); 574 eerror ("fopen `%s': %s", RC_KSOFTLEVEL, strerror (errno));
575 return (-1); 575 return (-1);
595{ 595{
596 pidlist_t *sp = service_pids; 596 pidlist_t *sp = service_pids;
597 if (sp) { 597 if (sp) {
598 while (sp->next) 598 while (sp->next)
599 sp = sp->next; 599 sp = sp->next;
600 sp->next = rc_xmalloc (sizeof (pidlist_t)); 600 sp->next = xmalloc (sizeof (pidlist_t));
601 sp = sp->next; 601 sp = sp->next;
602 } else 602 } else
603 sp = service_pids = rc_xmalloc (sizeof (pidlist_t)); 603 sp = service_pids = xmalloc (sizeof (pidlist_t));
604 memset (sp, 0, sizeof (pidlist_t)); 604 memset (sp, 0, sizeof (pidlist_t));
605 sp->pid = pid; 605 sp->pid = pid;
606} 606}
607 607
608static void remove_pid (pid_t pid) 608static void remove_pid (pid_t pid)
755 DIR *dp; 755 DIR *dp;
756 struct dirent *d; 756 struct dirent *d;
757 757
758 atexit (cleanup); 758 atexit (cleanup);
759 if (argv[0]) 759 if (argv[0])
760 applet = rc_xstrdup (basename (argv[0])); 760 applet = strdup (basename (argv[0]));
761 761
762 if (! applet) 762 if (! applet)
763 eerrorx ("arguments required"); 763 eerrorx ("arguments required");
764 764
765 /* These used to be programs in their own right, so we shouldn't 765 /* These used to be programs in their own right, so we shouldn't
856 /* No clearenv present here then. 856 /* No clearenv present here then.
857 We could manipulate environ directly ourselves, but it seems that 857 We could manipulate environ directly ourselves, but it seems that
858 some kernels bitch about this according to the environ man pages 858 some kernels bitch about this according to the environ man pages
859 so we walk though environ and call unsetenv for each value. */ 859 so we walk though environ and call unsetenv for each value. */
860 while (environ[0]) { 860 while (environ[0]) {
861 tmp = rc_xstrdup (environ[0]); 861 tmp = strdup (environ[0]);
862 p = tmp; 862 p = tmp;
863 var = strsep (&p, "="); 863 var = strsep (&p, "=");
864 unsetenv (var); 864 unsetenv (var);
865 free (tmp); 865 free (tmp);
866 } 866 }
896 896
897 /* Export our PID */ 897 /* Export our PID */
898 snprintf (pidstr, sizeof (pidstr), "%d", getpid ()); 898 snprintf (pidstr, sizeof (pidstr), "%d", getpid ());
899 setenv ("RC_PID", pidstr, 1); 899 setenv ("RC_PID", pidstr, 1);
900 900
901 interactive = rc_exists (INTERACTIVE); 901 interactive = exists (INTERACTIVE);
902 rc_plugin_load (); 902 rc_plugin_load ();
903 903
904 /* Load current softlevel */ 904 /* Load current softlevel */
905 bootlevel = getenv ("RC_BOOTLEVEL"); 905 bootlevel = getenv ("RC_BOOTLEVEL");
906 runlevel = rc_runlevel_get (); 906 runlevel = rc_runlevel_get ();
923#endif 923#endif
924 924
925 /* exec init-early.sh if it exists 925 /* exec init-early.sh if it exists
926 * This should just setup the console to use the correct 926 * This should just setup the console to use the correct
927 * font. Maybe it should setup the keyboard too? */ 927 * font. Maybe it should setup the keyboard too? */
928 if (rc_exists (INITEARLYSH)) 928 if (exists (INITEARLYSH))
929 run_script (INITEARLYSH); 929 run_script (INITEARLYSH);
930 930
931 uname (&uts); 931 uname (&uts);
932 932
933 printf ("\n"); 933 printf ("\n");
1102#if defined(__DragonFly__) || defined(__FreeBSD__) 1102#if defined(__DragonFly__) || defined(__FreeBSD__)
1103 /* The net interfaces are easy - they're all in net /dev/net :) */ 1103 /* The net interfaces are easy - they're all in net /dev/net :) */
1104 if ((dp = opendir ("/dev/net"))) { 1104 if ((dp = opendir ("/dev/net"))) {
1105 while ((d = readdir (dp))) { 1105 while ((d = readdir (dp))) {
1106 i = (strlen ("net.") + strlen (d->d_name) + 1); 1106 i = (strlen ("net.") + strlen (d->d_name) + 1);
1107 tmp = rc_xmalloc (sizeof (char *) * i); 1107 tmp = xmalloc (sizeof (char *) * i);
1108 snprintf (tmp, i, "net.%s", d->d_name); 1108 snprintf (tmp, i, "net.%s", d->d_name);
1109 if (rc_service_exists (tmp) && 1109 if (rc_service_exists (tmp) &&
1110 rc_service_plugable (tmp)) 1110 rc_service_plugable (tmp))
1111 rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED); 1111 rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED);
1112 CHAR_FREE (tmp); 1112 CHAR_FREE (tmp);
1123 strncmp (d->d_name, "ums", 3) == 0) 1123 strncmp (d->d_name, "ums", 3) == 0)
1124 { 1124 {
1125 char *p = d->d_name + 3; 1125 char *p = d->d_name + 3;
1126 if (p && isdigit (*p)) { 1126 if (p && isdigit (*p)) {
1127 i = (strlen ("moused.") + strlen (d->d_name) + 1); 1127 i = (strlen ("moused.") + strlen (d->d_name) + 1);
1128 tmp = rc_xmalloc (sizeof (char *) * i); 1128 tmp = xmalloc (sizeof (char *) * i);
1129 snprintf (tmp, i, "moused.%s", d->d_name); 1129 snprintf (tmp, i, "moused.%s", d->d_name);
1130 if (rc_service_exists (tmp) && rc_service_plugable (tmp)) 1130 if (rc_service_exists (tmp) && rc_service_plugable (tmp))
1131 rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED); 1131 rc_service_mark (tmp, RC_SERVICE_COLDPLUGGED);
1132 CHAR_FREE (tmp); 1132 CHAR_FREE (tmp);
1133 } 1133 }
1243 int len; 1243 int len;
1244 if (! newlevel) 1244 if (! newlevel)
1245 continue; 1245 continue;
1246 1246
1247 len = strlen (service) + strlen (runlevel) + 2; 1247 len = strlen (service) + strlen (runlevel) + 2;
1248 tmp = rc_xmalloc (sizeof (char *) * len); 1248 tmp = xmalloc (sizeof (char *) * len);
1249 snprintf (tmp, len, "%s.%s", service, runlevel); 1249 snprintf (tmp, len, "%s.%s", service, runlevel);
1250 conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); 1250 conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
1251 found = rc_exists (conf); 1251 found = exists (conf);
1252 CHAR_FREE (conf); 1252 CHAR_FREE (conf);
1253 CHAR_FREE (tmp); 1253 CHAR_FREE (tmp);
1254 if (! found) { 1254 if (! found) {
1255 len = strlen (service) + strlen (newlevel) + 2; 1255 len = strlen (service) + strlen (newlevel) + 2;
1256 tmp = rc_xmalloc (sizeof (char *) * len); 1256 tmp = xmalloc (sizeof (char *) * len);
1257 snprintf (tmp, len, "%s.%s", service, newlevel); 1257 snprintf (tmp, len, "%s.%s", service, newlevel);
1258 conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL); 1258 conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
1259 found = rc_exists (conf); 1259 found = exists (conf);
1260 CHAR_FREE (conf); 1260 CHAR_FREE (conf);
1261 CHAR_FREE (tmp); 1261 CHAR_FREE (tmp);
1262 if (!found) 1262 if (!found)
1263 continue; 1263 continue;
1264 } 1264 }
1308 1308
1309 /* Store the new runlevel */ 1309 /* Store the new runlevel */
1310 if (newlevel) { 1310 if (newlevel) {
1311 rc_runlevel_set (newlevel); 1311 rc_runlevel_set (newlevel);
1312 free (runlevel); 1312 free (runlevel);
1313 runlevel = rc_xstrdup (newlevel); 1313 runlevel = strdup (newlevel);
1314 setenv ("RC_SOFTLEVEL", runlevel, 1); 1314 setenv ("RC_SOFTLEVEL", runlevel, 1);
1315 } 1315 }
1316 1316
1317 /* Run the halt script if needed */ 1317 /* Run the halt script if needed */
1318 if (strcmp (runlevel, RC_LEVEL_SHUTDOWN) == 0 || 1318 if (strcmp (runlevel, RC_LEVEL_SHUTDOWN) == 0 ||
1323 applet, HALTSH, strerror (errno)); 1323 applet, HALTSH, strerror (errno));
1324 } 1324 }
1325 1325
1326 /* Single user is done now */ 1326 /* Single user is done now */
1327 if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0) { 1327 if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0) {
1328 if (rc_exists (INTERACTIVE)) 1328 if (exists (INTERACTIVE))
1329 unlink (INTERACTIVE); 1329 unlink (INTERACTIVE);
1330 sulogin (false); 1330 sulogin (false);
1331 } 1331 }
1332 1332
1333 mkdir (RC_STARTING, 0755); 1333 mkdir (RC_STARTING, 0755);
1421 1421
1422 /* Store our interactive status for boot */ 1422 /* Store our interactive status for boot */
1423 if (interactive && strcmp (runlevel, bootlevel) == 0) 1423 if (interactive && strcmp (runlevel, bootlevel) == 0)
1424 mark_interactive (); 1424 mark_interactive ();
1425 else { 1425 else {
1426 if (rc_exists (INTERACTIVE)) 1426 if (exists (INTERACTIVE))
1427 unlink (INTERACTIVE); 1427 unlink (INTERACTIVE);
1428 } 1428 }
1429 1429
1430 return (EXIT_SUCCESS); 1430 return (EXIT_SUCCESS);
1431} 1431}

Legend:
Removed from v.3007  
changed lines
  Added in v.3008

  ViewVC Help
Powered by ViewVC 1.1.20