diff options
Diffstat (limited to 'init.c')
-rw-r--r-- | init.c | 44 |
1 files changed, 21 insertions, 23 deletions
@@ -331,7 +331,7 @@ static void console_init() | |||
331 | static pid_t run(char* command, | 331 | static pid_t run(char* command, |
332 | char *terminal, int get_enter) | 332 | char *terminal, int get_enter) |
333 | { | 333 | { |
334 | int i; | 334 | int i, fd; |
335 | pid_t pid; | 335 | pid_t pid; |
336 | char* tmpCmd; | 336 | char* tmpCmd; |
337 | char* cmd[255]; | 337 | char* cmd[255]; |
@@ -357,21 +357,20 @@ static pid_t run(char* command, | |||
357 | close(2); | 357 | close(2); |
358 | setsid(); | 358 | setsid(); |
359 | 359 | ||
360 | if (device_open(terminal, O_RDWR) < 0) { | ||
361 | message(LOG|CONSOLE, "Bummer, can't open %s\r\n", terminal); | ||
362 | exit(1); | ||
363 | } | ||
364 | dup(0); | ||
365 | dup(0); | ||
366 | tcsetpgrp (0, getpgrp()); | ||
367 | set_term(0); | ||
368 | |||
369 | /* Reset signal handlers set for parent process */ | 360 | /* Reset signal handlers set for parent process */ |
370 | signal(SIGUSR1, SIG_DFL); | 361 | signal(SIGUSR1, SIG_DFL); |
371 | signal(SIGUSR2, SIG_DFL); | 362 | signal(SIGUSR2, SIG_DFL); |
372 | signal(SIGINT, SIG_DFL); | 363 | signal(SIGINT, SIG_DFL); |
373 | signal(SIGTERM, SIG_DFL); | 364 | signal(SIGTERM, SIG_DFL); |
374 | 365 | ||
366 | if ((fd = device_open(terminal, O_RDWR)) < 0) { | ||
367 | message(LOG|CONSOLE, "Bummer, can't open %s\r\n", terminal); | ||
368 | exit(1); | ||
369 | } | ||
370 | dup(fd); | ||
371 | dup(fd); | ||
372 | tcsetpgrp (0, getpgrp()); | ||
373 | set_term(0); | ||
375 | 374 | ||
376 | if (get_enter==TRUE) { | 375 | if (get_enter==TRUE) { |
377 | /* | 376 | /* |
@@ -389,19 +388,21 @@ static pid_t run(char* command, | |||
389 | read(fileno(stdin), &c, 1); | 388 | read(fileno(stdin), &c, 1); |
390 | } | 389 | } |
391 | 390 | ||
391 | /* Log the process name and args */ | ||
392 | message(LOG|CONSOLE, "Starting pid %d, console %s: '", | ||
393 | shell_pgid, terminal, command); | ||
394 | |||
392 | /* Convert command (char*) into cmd (char**, one word per string) */ | 395 | /* Convert command (char*) into cmd (char**, one word per string) */ |
393 | for (tmpCmd=command, i=0; (tmpCmd=strsep(&command, " \t")) != NULL;) { | 396 | for (tmpCmd=command, i=0; (tmpCmd=strsep(&command, " \t")) != NULL;) { |
394 | if (*tmpCmd != '\0') { | 397 | if (*tmpCmd != '\0') { |
395 | cmd[i] = tmpCmd; | 398 | cmd[i] = tmpCmd; |
399 | message(LOG|CONSOLE, "%s ", tmpCmd); | ||
396 | tmpCmd++; | 400 | tmpCmd++; |
397 | i++; | 401 | i++; |
398 | } | 402 | } |
399 | } | 403 | } |
400 | cmd[i] = NULL; | 404 | cmd[i] = NULL; |
401 | 405 | message(LOG|CONSOLE, "'\r\n"); | |
402 | /* Log the process name and args */ | ||
403 | message(LOG, "Starting pid %d, console %s: '%s'\r\n", | ||
404 | shell_pgid, terminal, cmd[0]); | ||
405 | 406 | ||
406 | /* Now run it. The new program will take over this PID, | 407 | /* Now run it. The new program will take over this PID, |
407 | * so nothing further in init.c should be run. */ | 408 | * so nothing further in init.c should be run. */ |
@@ -540,8 +541,8 @@ void new_initAction (initActionEnum action, | |||
540 | } else | 541 | } else |
541 | strncpy(newAction->console, console, 255); | 542 | strncpy(newAction->console, console, 255); |
542 | newAction->pid = 0; | 543 | newAction->pid = 0; |
543 | // message(LOG|CONSOLE, "process='%s' action='%d' console='%s'\n", | 544 | message(LOG|CONSOLE, "process='%s' action='%d' console='%s'\n", |
544 | // newAction->process, newAction->action, newAction->console); | 545 | newAction->process, newAction->action, newAction->console); |
545 | } | 546 | } |
546 | 547 | ||
547 | void delete_initAction (initAction *action) | 548 | void delete_initAction (initAction *action) |
@@ -672,11 +673,8 @@ extern int init_main(int argc, char **argv) | |||
672 | usage( "init\n\nInit is the parent of all processes.\n\n" | 673 | usage( "init\n\nInit is the parent of all processes.\n\n" |
673 | "This version of init is designed to be run only by the kernel\n"); | 674 | "This version of init is designed to be run only by the kernel\n"); |
674 | } | 675 | } |
675 | 676 | /* Set up sig handlers -- be sure to | |
676 | /* from the controlling terminal */ | 677 | * clear all of these in run() */ |
677 | setsid(); | ||
678 | |||
679 | /* Set up sig handlers -- be sure to clear all of these in run() */ | ||
680 | signal(SIGUSR1, halt_signal); | 678 | signal(SIGUSR1, halt_signal); |
681 | signal(SIGUSR2, reboot_signal); | 679 | signal(SIGUSR2, reboot_signal); |
682 | signal(SIGINT, reboot_signal); | 680 | signal(SIGINT, reboot_signal); |
@@ -686,7 +684,7 @@ extern int init_main(int argc, char **argv) | |||
686 | * SIGINT on CAD so we can shut things down gracefully... */ | 684 | * SIGINT on CAD so we can shut things down gracefully... */ |
687 | reboot(RB_DISABLE_CAD); | 685 | reboot(RB_DISABLE_CAD); |
688 | #endif | 686 | #endif |
689 | 687 | ||
690 | /* Figure out where the default console should be */ | 688 | /* Figure out where the default console should be */ |
691 | console_init(); | 689 | console_init(); |
692 | 690 | ||
@@ -695,11 +693,11 @@ extern int init_main(int argc, char **argv) | |||
695 | close(1); | 693 | close(1); |
696 | close(2); | 694 | close(2); |
697 | set_term(0); | 695 | set_term(0); |
696 | setsid(); | ||
698 | 697 | ||
699 | /* Make sure PATH is set to something sane */ | 698 | /* Make sure PATH is set to something sane */ |
700 | putenv(_PATH_STDPATH); | 699 | putenv(_PATH_STDPATH); |
701 | 700 | ||
702 | |||
703 | /* Hello world */ | 701 | /* Hello world */ |
704 | #ifndef DEBUG_INIT | 702 | #ifndef DEBUG_INIT |
705 | message(LOG|CONSOLE, | 703 | message(LOG|CONSOLE, |