Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/init_main.c
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
#include "opt_ddb.h" | #include "opt_ddb.h" | ||||
#include "opt_init_path.h" | #include "opt_init_path.h" | ||||
#include "opt_verbose_sysinit.h" | #include "opt_verbose_sysinit.h" | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/exec.h> | #include <sys/exec.h> | ||||
#include <sys/fcntl.h> | |||||
#include <sys/file.h> | #include <sys/file.h> | ||||
#include <sys/filedesc.h> | #include <sys/filedesc.h> | ||||
#include <sys/jail.h> | #include <sys/jail.h> | ||||
#include <sys/ktr.h> | #include <sys/ktr.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/loginclass.h> | #include <sys/loginclass.h> | ||||
#include <sys/mount.h> | #include <sys/mount.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
▲ Show 20 Lines • Show All 602 Lines • ▼ Show 20 Lines | |||||
#ifndef INIT_SHUTDOWN_TIMEOUT | #ifndef INIT_SHUTDOWN_TIMEOUT | ||||
#define INIT_SHUTDOWN_TIMEOUT 120 | #define INIT_SHUTDOWN_TIMEOUT 120 | ||||
#endif | #endif | ||||
static int init_shutdown_timeout = INIT_SHUTDOWN_TIMEOUT; | static int init_shutdown_timeout = INIT_SHUTDOWN_TIMEOUT; | ||||
SYSCTL_INT(_kern, OID_AUTO, init_shutdown_timeout, | SYSCTL_INT(_kern, OID_AUTO, init_shutdown_timeout, | ||||
CTLFLAG_RW, &init_shutdown_timeout, 0, "Shutdown timeout of init(8). " | CTLFLAG_RW, &init_shutdown_timeout, 0, "Shutdown timeout of init(8). " | ||||
"Unused within kernel, but used to control init(8)"); | "Unused within kernel, but used to control init(8)"); | ||||
static void | |||||
open_initial_fds(void) | |||||
{ | |||||
struct thread *td; | |||||
int devconsole, error; | |||||
td = curthread; | |||||
error = kern_openat(td, AT_FDCWD, "/dev/console", | |||||
kib: Depending on the type of the console, this could have quite spectacular effects. E.g. the boot… | |||||
Not Done Inline ActionsI've added O_NONBLOCK there, does this fix the issue? trasz: I've added O_NONBLOCK there, does this fix the issue?
| |||||
Not Done Inline ActionsNo, it only prevents blocking, it does not make non-CLOCAL tty operational. kib: No, it only prevents blocking, it does not make non-CLOCAL tty operational. | |||||
Not Done Inline ActionsAre you absolutely sure? Looking at the sys/kern/tty.c:ttydev_open(), it seems you'll never have non-CLOCAL /dev/console. trasz: Are you absolutely sure? Looking at the sys/kern/tty.c:ttydev_open(), it seems you'll never… | |||||
Not Done Inline ActionsCan you explain ? kib: Can you explain ? | |||||
Not Done Inline ActionsFWIW, O_NONBLOCK should be in effect after the open(2) as well, which obviously must cause funny behaviour of read(2) done by the shell on stdin. In other words, I suspect that this code was not tested. kib: FWIW, O_NONBLOCK should be in effect after the open(2) as well, which obviously must cause… | |||||
UIO_SYSSPACE, O_RDWR | O_NONBLOCK, 0); | |||||
if (error != 0) { | |||||
if (bootverbose || error != EWOULDBLOCK) | |||||
printf("%s: cannot open /dev/console, error = %d\n", | |||||
__func__, error); | |||||
return; | |||||
} | |||||
devconsole = td->td_retval[0]; | |||||
KASSERT(devconsole == 0, ("we didn't get our fd")); | |||||
error = kern_dup(td, FDDUP_FIXED, 0, devconsole, 1); | |||||
if (error != 0) { | |||||
printf("%s: kern_dup() failed for stdout with error %d\n", | |||||
__func__, error); | |||||
return; | |||||
} | |||||
error = kern_dup(td, FDDUP_FIXED, 0, devconsole, 2); | |||||
if (error != 0) { | |||||
printf("%s: kern_dup() failed for stderr with error %d\n", | |||||
__func__, error); | |||||
return; | |||||
} | |||||
} | |||||
/* | /* | ||||
* Start the initial user process; try exec'ing each pathname in init_path. | * Start the initial user process; try exec'ing each pathname in init_path. | ||||
* The program is invoked with one argument containing the boot flags. | * The program is invoked with one argument containing the boot flags. | ||||
*/ | */ | ||||
static void | static void | ||||
start_init(void *dummy) | start_init(void *dummy) | ||||
{ | { | ||||
vm_offset_t addr; | vm_offset_t addr; | ||||
Show All 25 Lines | if (vm_map_find(&p->p_vmspace->vm_map, NULL, 0, &addr, PAGE_SIZE, 0, | ||||
panic("init: couldn't allocate argument space"); | panic("init: couldn't allocate argument space"); | ||||
p->p_vmspace->vm_maxsaddr = (caddr_t)addr; | p->p_vmspace->vm_maxsaddr = (caddr_t)addr; | ||||
p->p_vmspace->vm_ssize = 1; | p->p_vmspace->vm_ssize = 1; | ||||
if ((var = kern_getenv("init_path")) != NULL) { | if ((var = kern_getenv("init_path")) != NULL) { | ||||
strlcpy(init_path, var, sizeof(init_path)); | strlcpy(init_path, var, sizeof(init_path)); | ||||
freeenv(var); | freeenv(var); | ||||
} | } | ||||
open_initial_fds(); | |||||
for (path = init_path; *path != '\0'; path = next) { | for (path = init_path; *path != '\0'; path = next) { | ||||
while (*path == ':') | while (*path == ':') | ||||
path++; | path++; | ||||
if (*path == '\0') | if (*path == '\0') | ||||
break; | break; | ||||
for (next = path; *next != '\0' && *next != ':'; next++) | for (next = path; *next != '\0' && *next != ':'; next++) | ||||
/* nothing */ ; | /* nothing */ ; | ||||
if (bootverbose) | if (bootverbose) | ||||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |
Depending on the type of the console, this could have quite spectacular effects. E.g. the boot could hang at this point if console is a serial port and CLOCAL is not set (and it is typically not set on ports). The thread would wait for the modem control indicating link.
There is a reason why init exists and handles ttys specially.