Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/uart_emul.c
Show First 20 Lines • Show All 673 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
uart_stdio = true; | uart_stdio = true; | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
uart_tty_backend(struct uart_softc *sc, const char *opts) | uart_tty_backend(struct uart_softc *sc, const char *path) | ||||
{ | { | ||||
#ifndef WITHOUT_CAPSICUM | #ifndef WITHOUT_CAPSICUM | ||||
cap_rights_t rights; | cap_rights_t rights; | ||||
cap_ioctl_t cmds[] = { TIOCGETA, TIOCSETA, TIOCGWINSZ }; | cap_ioctl_t cmds[] = { TIOCGETA, TIOCSETA, TIOCGWINSZ }; | ||||
#endif | #endif | ||||
int fd; | int fd; | ||||
fd = open(opts, O_RDWR | O_NONBLOCK); | fd = open(path, O_RDWR | O_NONBLOCK); | ||||
if (fd < 0) | if (fd < 0) | ||||
return (-1); | return (-1); | ||||
if (!isatty(fd)) { | if (!isatty(fd)) { | ||||
close(fd); | close(fd); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
sc->tty.rfd = sc->tty.wfd = fd; | sc->tty.rfd = sc->tty.wfd = fd; | ||||
sc->tty.opened = true; | sc->tty.opened = true; | ||||
#ifndef WITHOUT_CAPSICUM | #ifndef WITHOUT_CAPSICUM | ||||
cap_rights_init(&rights, CAP_EVENT, CAP_IOCTL, CAP_READ, CAP_WRITE); | cap_rights_init(&rights, CAP_EVENT, CAP_IOCTL, CAP_READ, CAP_WRITE); | ||||
if (caph_rights_limit(fd, &rights) == -1) | if (caph_rights_limit(fd, &rights) == -1) | ||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | errx(EX_OSERR, "Unable to apply rights for sandbox"); | ||||
if (caph_ioctls_limit(fd, cmds, nitems(cmds)) == -1) | if (caph_ioctls_limit(fd, cmds, nitems(cmds)) == -1) | ||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | errx(EX_OSERR, "Unable to apply rights for sandbox"); | ||||
#endif | #endif | ||||
return (0); | return (0); | ||||
} | } | ||||
int | int | ||||
uart_set_backend(struct uart_softc *sc, const char *opts) | uart_set_backend(struct uart_softc *sc, const char *device) | ||||
{ | { | ||||
int retval; | int retval; | ||||
if (opts == NULL) | if (device == NULL) | ||||
return (0); | return (0); | ||||
if (strcmp("stdio", opts) == 0) | if (strcmp("stdio", device) == 0) | ||||
retval = uart_stdio_backend(sc); | retval = uart_stdio_backend(sc); | ||||
else | else | ||||
retval = uart_tty_backend(sc, opts); | retval = uart_tty_backend(sc, device); | ||||
if (retval == 0) | if (retval == 0) | ||||
uart_opentty(sc); | uart_opentty(sc); | ||||
return (retval); | return (retval); | ||||
} | } | ||||
#ifdef BHYVE_SNAPSHOT | #ifdef BHYVE_SNAPSHOT | ||||
int | int | ||||
Show All 29 Lines |