mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-01 22:58:40 -04:00
connection: Clear fds we shouldn't close to -1
This initializes all the fd arguments in closures to -1 and clears them back to -1 when they've been dispatched or serialized. This means that any valid fd in a closure is currently libwayland's responsibility to close in the case of an error. Signed-off-by: Derek Foreman <derekf@osg.samsung.com> Reviewed-by: Daniel Stone <daniels@collabora.com>
This commit is contained in:
parent
e802094c9b
commit
52609ddf79
1 changed files with 24 additions and 0 deletions
|
|
@ -524,6 +524,17 @@ wl_argument_from_va_list(const char *signature, union wl_argument *args,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wl_closure_clear_fds(struct wl_closure *closure)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; closure->message->signature[i]; i++) {
|
||||||
|
if (closure->message->signature[i] == 'h')
|
||||||
|
closure->args[i].h = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static struct wl_closure *
|
static struct wl_closure *
|
||||||
wl_closure_init(const struct wl_message *message, uint32_t size,
|
wl_closure_init(const struct wl_message *message, uint32_t size,
|
||||||
int *num_arrays, union wl_argument *args)
|
int *num_arrays, union wl_argument *args)
|
||||||
|
|
@ -557,6 +568,14 @@ wl_closure_init(const struct wl_message *message, uint32_t size,
|
||||||
closure->message = message;
|
closure->message = message;
|
||||||
closure->count = count;
|
closure->count = count;
|
||||||
|
|
||||||
|
/* Set these all to -1 so we can close any that have been
|
||||||
|
* set to a real value during wl_closure_destroy().
|
||||||
|
* We may have copied a bunch of fds into the closure with
|
||||||
|
* memcpy previously, but those are undup()d client fds
|
||||||
|
* that we would have replaced anyway.
|
||||||
|
*/
|
||||||
|
wl_closure_clear_fds(closure);
|
||||||
|
|
||||||
return closure;
|
return closure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -948,6 +967,8 @@ wl_closure_invoke(struct wl_closure *closure, uint32_t flags,
|
||||||
opcode, target->interface->name);
|
opcode, target->interface->name);
|
||||||
}
|
}
|
||||||
ffi_call(&cif, implementation[opcode], NULL, ffi_args);
|
ffi_call(&cif, implementation[opcode], NULL, ffi_args);
|
||||||
|
|
||||||
|
wl_closure_clear_fds(closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -956,6 +977,8 @@ wl_closure_dispatch(struct wl_closure *closure, wl_dispatcher_func_t dispatcher,
|
||||||
{
|
{
|
||||||
dispatcher(target->implementation, target, opcode, closure->message,
|
dispatcher(target->implementation, target, opcode, closure->message,
|
||||||
closure->args);
|
closure->args);
|
||||||
|
|
||||||
|
wl_closure_clear_fds(closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
@ -980,6 +1003,7 @@ copy_fds_to_connection(struct wl_closure *closure,
|
||||||
"can't send file descriptor");
|
"can't send file descriptor");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
closure->args[i].h = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue