Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/pci_virtio_console.c
Show All 28 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> | ||||
#ifndef WITHOUT_CAPSICUM | |||||
#include <capsicum_helpers.h> | #include <capsicum_helpers.h> | ||||
#endif | |||||
#include <err.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> | ||||
▲ Show 20 Lines • Show All 217 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; | 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, 0); | ||||
Show All 31 Lines | if (fcntl(s, F_SETFL, O_NONBLOCK) < 0) { | ||||
goto out; | 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); | cap_rights_init(&rights, CAP_ACCEPT, CAP_EVENT, CAP_READ, CAP_WRITE); | ||||
if (caph_rights_limit(s, &rights) == -1) | if (caph_rights_limit(s, &rights) == -1) | ||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | 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 337 Lines • Show Last 20 Lines |