static CursorPipeItem *cursor_pipe_item_ref(CursorPipeItem *item) { spice_return_val_if_fail(item, NULL); spice_return_val_if_fail(item->refs > 0, NULL); item->refs++; return item; }
static CursorItem *cursor_item_ref(CursorItem *item) { spice_return_val_if_fail(item != NULL, NULL); spice_return_val_if_fail(item->refs > 0, NULL); item->refs++; return item; }
int reds_stream_get_family(const RedsStream *s) { spice_return_val_if_fail(s != NULL, -1); if (s->socket == -1) return -1; return s->priv->info->laddr_ext.ss_family; }
int main(int argc, char *argv[]) { RedsStream *st[2]; int sv[2]; int ret, fd = -1; char c; spice_return_val_if_fail(server_init() == 0, -1); if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv) == -1) { spice_error("socketpair failed %s", strerror(errno)); return -1; } st[0] = reds_stream_new(server, sv[0]); spice_assert(reds_stream_is_plain_unix(st[0])); st[1] = reds_stream_new(server, sv[1]); spice_assert(reds_stream_is_plain_unix(st[1])); /* send stdin, for the fun of it */ ret = reds_stream_send_msgfd(st[0], 0); spice_assert(ret == 1); ret = sock_fd_read(sv[1], &c, 1, &fd); spice_assert(c == '@'); spice_assert(ret == 1); spice_assert(fd != -1); close(fd); /* send invalid fd behaviour */ ret = reds_stream_send_msgfd(st[0], -1); spice_assert(ret == 1); ret = sock_fd_read(sv[1], &c, 1, &fd); spice_assert(c == '@'); spice_assert(ret == 1); spice_assert(fd == -1); /* batch test */ ret = reds_stream_send_msgfd(st[0], 0); spice_assert(ret == 1); ret = reds_stream_send_msgfd(st[0], 0); spice_assert(ret == 1); ret = sock_fd_read(sv[1], &c, 1, &fd); spice_assert(c == '@'); spice_assert(ret == 1); spice_assert(fd != -1); close(fd); ret = sock_fd_read(sv[1], &c, 1, &fd); spice_assert(c == '@'); spice_assert(ret == 1); spice_assert(fd != -1); close(fd); reds_stream_free(st[0]); reds_stream_free(st[1]); return 0; }
CursorChannelClient* cursor_channel_client_new(CursorChannel *cursor, RedClient *client, RedsStream *stream, int mig_target, uint32_t *common_caps, int num_common_caps, uint32_t *caps, int num_caps) { spice_return_val_if_fail(cursor, NULL); spice_return_val_if_fail(client, NULL); spice_return_val_if_fail(stream, NULL); spice_return_val_if_fail(!num_common_caps || common_caps, NULL); spice_return_val_if_fail(!num_caps || caps, NULL); CursorChannelClient *ccc = (CursorChannelClient*)common_channel_new_client(&cursor->common, sizeof(CursorChannelClient), client, stream, mig_target, FALSE, common_caps, num_common_caps, caps, num_caps); spice_return_val_if_fail(ccc != NULL, NULL); ring_init(&ccc->cursor_cache_lru); ccc->cursor_cache_available = CLIENT_CURSOR_CACHE_SIZE; return ccc; }
static CursorItem *cursor_item_new(QXLInstance *qxl, RedCursorCmd *cmd, uint32_t group_id) { CursorItem *cursor_item; spice_return_val_if_fail(cmd != NULL, NULL); cursor_item = g_slice_new0(CursorItem); cursor_item->qxl = qxl; cursor_item->refs = 1; cursor_item->group_id = group_id; cursor_item->red_cursor = cmd; return cursor_item; }
int spice_pixman_image_get_format(pixman_image_t *image, pixman_format_code_t *format) { PixmanData *data; spice_return_val_if_fail(format != NULL, 0); data = (PixmanData *)pixman_image_get_destroy_data(image); if (data != NULL && data->format != 0) { *format = data->format; return 1; } spice_warn_if_reached(); return 0; }
// return FALSE when operation fails (due to failure in allocation) static int lz_read_image_segments(Encoder *encoder, uint8_t *first_lines, unsigned int num_first_lines) { LzImageSegment *image_seg; uint32_t size_delta = 0; unsigned int num_lines = num_first_lines; uint8_t* lines = first_lines; int row; spice_return_val_if_fail(!encoder->head_image_segs, FALSE); image_seg = lz_alloc_image_seg(encoder); if (!image_seg) { goto error_1; } image_seg->lines = lines; image_seg->lines_end = lines + num_lines * encoder->stride; image_seg->size_delta = size_delta; size_delta += num_lines * encoder->stride / RGB_BYTES_PER_PIXEL[encoder->type]; for (row = num_first_lines; row < encoder->height; row += num_lines) { num_lines = encoder->usr->more_lines(encoder->usr, &lines); if (num_lines <= 0) { encoder->usr->error(encoder->usr, "more lines failed\n"); } image_seg = lz_alloc_image_seg(encoder); if (!image_seg) { goto error_1; } image_seg->lines = lines; image_seg->lines_end = lines + num_lines * encoder->stride; image_seg->size_delta = size_delta; size_delta += num_lines * encoder->stride / RGB_BYTES_PER_PIXEL[encoder->type]; } return TRUE; error_1: lz_reset_image_seg(encoder); return FALSE; }
int reds_stream_send_msgfd(RedsStream *stream, int fd) { struct msghdr msgh = { 0, }; struct iovec iov; int r; const size_t fd_size = 1 * sizeof(int); struct cmsghdr *cmsg; union { struct cmsghdr hdr; char data[CMSG_SPACE(fd_size)]; } control; spice_return_val_if_fail(reds_stream_is_plain_unix(stream), -1); /* set the payload */ iov.iov_base = (char*)"@"; iov.iov_len = 1; msgh.msg_iovlen = 1; msgh.msg_iov = &iov; if (fd != -1) { msgh.msg_control = control.data; msgh.msg_controllen = sizeof(control.data); /* CMSG_SPACE() might be larger than CMSG_LEN() as it can include some * padding. We set the whole control data to 0 to avoid valgrind warnings */ memset(control.data, 0, sizeof(control.data)); cmsg = CMSG_FIRSTHDR(&msgh); cmsg->cmsg_len = CMSG_LEN(fd_size); cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; memcpy(CMSG_DATA(cmsg), &fd, fd_size); } do { r = sendmsg(stream->socket, &msgh, MSG_NOSIGNAL); } while (r < 0 && (errno == EINTR || errno == EAGAIN)); return r; }
bool reds_stream_is_plain_unix(const RedsStream *s) { spice_return_val_if_fail(s != NULL, false); if (reds_stream_get_family(s) != AF_UNIX) { return false; } #if HAVE_SASL if (s->priv->sasl.conn) { return false; } #endif if (s->priv->ssl) { return false; } return true; }