connection: Dont put fds in the connection until we send the closure

This commit is contained in:
Kristian Høgsberg 2012-04-21 23:50:09 -04:00
parent 9d37682db3
commit 0d6dea17b4

View file

@ -533,11 +533,6 @@ wl_connection_vmarshal(struct wl_connection *connection,
abort();
}
*fd_ptr = dup_fd;
if (wl_connection_put_fd(connection, dup_fd)) {
printf("request could not be mashaled: "
"can't send file descriptor");
return NULL;
}
break;
default:
fprintf(stderr, "unhandled format code: '%c'\n",
@ -767,11 +762,38 @@ wl_closure_invoke(struct wl_closure *closure,
ffi_call(&closure->cif, func, &result, closure->args);
}
static int
copy_fds_to_connection(struct wl_closure *closure,
struct wl_connection *connection)
{
const struct wl_message *message = closure->message;
uint32_t i, count;
int *fd;
count = strlen(message->signature) + 2;
for (i = 2; i < count; i++) {
if (message->signature[i - 2] != 'h')
continue;
fd = closure->args[i];
if (wl_connection_put_fd(connection, *fd)) {
fprintf(stderr, "request could not be marshaled: "
"can't send file descriptor");
return -1;
}
}
return 0;
}
int
wl_closure_send(struct wl_closure *closure, struct wl_connection *connection)
{
uint32_t size;
if (copy_fds_to_connection(closure, connection))
return -1;
size = closure->start[1] >> 16;
return wl_connection_write(connection, closure->start, size);
@ -782,6 +804,9 @@ wl_closure_queue(struct wl_closure *closure, struct wl_connection *connection)
{
uint32_t size;
if (copy_fds_to_connection(closure, connection))
return -1;
size = closure->start[1] >> 16;
return wl_connection_queue(connection, closure->start, size);