Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/pci_virtio_console.c
Show All 26 Lines | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#ifndef WITHOUT_CAPSICUM | |||||
#include <sys/capsicum.h> | |||||
#endif | |||||
#include <sys/linker_set.h> | #include <sys/linker_set.h> | ||||
#include <sys/uio.h> | #include <sys/uio.h> | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
#include <sys/un.h> | #include <sys/un.h> | ||||
#include <err.h> | |||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <pthread.h> | #include <pthread.h> | ||||
#include <libgen.h> | #include <libgen.h> | ||||
#include <sysexits.h> | |||||
#include "bhyverun.h" | #include "bhyverun.h" | ||||
#include "pci_emul.h" | #include "pci_emul.h" | ||||
#include "virtio.h" | #include "virtio.h" | ||||
#include "mevent.h" | #include "mevent.h" | ||||
#define VTCON_RINGSZ 64 | #define VTCON_RINGSZ 64 | ||||
#define VTCON_MAXPORTS 16 | #define VTCON_MAXPORTS 16 | ||||
▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | |||||
static int | static int | ||||
pci_vtcon_sock_add(struct pci_vtcon_softc *sc, const char *name, | pci_vtcon_sock_add(struct pci_vtcon_softc *sc, const char *name, | ||||
const char *path) | const char *path) | ||||
{ | { | ||||
struct pci_vtcon_sock *sock; | struct pci_vtcon_sock *sock; | ||||
struct sockaddr_un sun; | struct sockaddr_un sun; | ||||
char *pathcopy; | char *pathcopy; | ||||
int s = -1, fd = -1, error = 0; | int s = -1, fd = -1, error = 0; | ||||
#ifndef WITHOUT_CAPSICUM | |||||
cap_rights_t rights; | |||||
#endif | |||||
sock = calloc(1, sizeof(struct pci_vtcon_sock)); | sock = calloc(1, sizeof(struct pci_vtcon_sock)); | ||||
if (sock == NULL) { | if (sock == NULL) { | ||||
error = -1; | error = -1; | ||||
goto out; | goto out; | ||||
} | } | ||||
s = socket(AF_UNIX, SOCK_STREAM, 0); | s = socket(AF_UNIX, SOCK_STREAM|SOCK_NONBLOCK, 0); | ||||
emaste: I'd like to see us commit these sorts of changes individually in advance of the Capsicum change. | |||||
kaktusAuthorUnsubmitted Not Done Inline ActionsThat was leftover from previous version. kaktus: That was leftover from previous version. | |||||
if (s < 0) { | if (s < 0) { | ||||
error = -1; | error = -1; | ||||
goto out; | goto out; | ||||
} | } | ||||
pathcopy = strdup(path); | pathcopy = strdup(path); | ||||
if (pathcopy == NULL) { | if (pathcopy == NULL) { | ||||
error = -1; | error = -1; | ||||
Show All 13 Lines | #endif | ||||
strncpy(sun.sun_path, basename(pathcopy), sizeof(sun.sun_path)); | strncpy(sun.sun_path, basename(pathcopy), sizeof(sun.sun_path)); | ||||
free(pathcopy); | free(pathcopy); | ||||
if (bindat(fd, s, (struct sockaddr *)&sun, sun.sun_len) < 0) { | if (bindat(fd, s, (struct sockaddr *)&sun, sun.sun_len) < 0) { | ||||
error = -1; | error = -1; | ||||
goto out; | goto out; | ||||
} | } | ||||
if (fcntl(s, F_SETFL, O_NONBLOCK) < 0) { | |||||
error = -1; | |||||
goto out; | |||||
} | |||||
if (listen(s, 1) < 0) { | if (listen(s, 1) < 0) { | ||||
error = -1; | error = -1; | ||||
goto out; | goto out; | ||||
} | } | ||||
#ifndef WITHOUT_CAPSICUM | |||||
cap_rights_init(&rights, CAP_ACCEPT, CAP_EVENT, CAP_READ, CAP_WRITE); | |||||
if (cap_rights_limit(s, &rights) == -1 && errno != ENOSYS) | |||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | |||||
#endif | |||||
sock->vss_port = pci_vtcon_port_add(sc, name, pci_vtcon_sock_tx, sock); | sock->vss_port = pci_vtcon_port_add(sc, name, pci_vtcon_sock_tx, sock); | ||||
if (sock->vss_port == NULL) { | if (sock->vss_port == NULL) { | ||||
error = -1; | error = -1; | ||||
goto out; | goto out; | ||||
} | } | ||||
sock->vss_open = false; | sock->vss_open = false; | ||||
▲ Show 20 Lines • Show All 318 Lines • Show Last 20 Lines |
I'd like to see us commit these sorts of changes individually in advance of the Capsicum change.