Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/bhyve/rfb.c
Show All 23 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/socket.h> | #include <sys/socket.h> | ||||
#include <sys/select.h> | #include <sys/select.h> | ||||
#include <sys/time.h> | #include <sys/time.h> | ||||
#include <arpa/inet.h> | #include <arpa/inet.h> | ||||
#include <machine/cpufunc.h> | #include <machine/cpufunc.h> | ||||
#include <machine/specialreg.h> | #include <machine/specialreg.h> | ||||
#include <netinet/in.h> | #include <netinet/in.h> | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <err.h> | |||||
#include <errno.h> | |||||
#include <pthread.h> | #include <pthread.h> | ||||
#include <pthread_np.h> | #include <pthread_np.h> | ||||
#include <signal.h> | #include <signal.h> | ||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <sysexits.h> | |||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <zlib.h> | #include <zlib.h> | ||||
#include "bhyvegc.h" | #include "bhyvegc.h" | ||||
#include "console.h" | #include "console.h" | ||||
#include "rfb.h" | #include "rfb.h" | ||||
#include "sockstream.h" | #include "sockstream.h" | ||||
▲ Show 20 Lines • Show All 807 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
int | int | ||||
rfb_init(char *hostname, int port, int wait) | rfb_init(char *hostname, int port, int wait) | ||||
{ | { | ||||
struct rfb_softc *rc; | struct rfb_softc *rc; | ||||
struct sockaddr_in sin; | struct sockaddr_in sin; | ||||
int on = 1; | int on = 1; | ||||
#ifndef WITHOUT_CAPSICUM | |||||
cap_rights_t rights; | |||||
#endif | |||||
rc = calloc(1, sizeof(struct rfb_softc)); | rc = calloc(1, sizeof(struct rfb_softc)); | ||||
rc->crc = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32), | rc->crc = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32), | ||||
sizeof(uint32_t)); | sizeof(uint32_t)); | ||||
rc->crc_tmp = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32), | rc->crc_tmp = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32), | ||||
sizeof(uint32_t)); | sizeof(uint32_t)); | ||||
rc->crc_width = RFB_MAX_WIDTH; | rc->crc_width = RFB_MAX_WIDTH; | ||||
Show All 19 Lines | if (bind(rc->sfd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { | ||||
perror("bind"); | perror("bind"); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
if (listen(rc->sfd, 1) < 0) { | if (listen(rc->sfd, 1) < 0) { | ||||
perror("listen"); | perror("listen"); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
#ifndef WITHOUT_CAPSICUM | |||||
cap_rights_init(&rights, CAP_ACCEPT, CAP_EVENT, CAP_READ, CAP_WRITE); | |||||
if (cap_rights_limit(rc->sfd, &rights) == -1 && errno != ENOSYS) | |||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | |||||
#endif | |||||
rc->hw_crc = sse42_supported(); | rc->hw_crc = sse42_supported(); | ||||
rc->conn_wait = wait; | rc->conn_wait = wait; | ||||
if (wait) { | if (wait) { | ||||
pthread_mutex_init(&rc->mtx, NULL); | pthread_mutex_init(&rc->mtx, NULL); | ||||
pthread_cond_init(&rc->cond, NULL); | pthread_cond_init(&rc->cond, NULL); | ||||
} | } | ||||
Show All 13 Lines |