Re: [PATCH v2] eventfd, signalfd, timerfd, epoll_create w/flags
From: Davide Libenzi
Date: Mon Apr 28 2008 - 01:11:41 EST
On Sun, 27 Apr 2008, Ulrich Drepper wrote:
> + int fflags = 0;
> +
> + if (flags) {
> + if ((flags & EFD_CLOEXEC) != 0) {
> + fflags |= O_CLOEXEC;
> + flags &= ~EFD_CLOEXEC;
> + }
> + if (flags)
> + return -EINVAL;
> + }
...
> + int fflags = 0;
> +
> + if (flags) {
> + if ((flags & EPOLL_CLOEXEC) != 0) {
> + fflags |= O_CLOEXEC;
> + flags &= ~EPOLL_CLOEXEC;
> + }
> + if (flags)
> + return -EINVAL;
> + }
...
> + int fflags = 0;
> +
> + if (flags) {
> + if ((flags & SFD_CLOEXEC) != 0 && ufd == -1) {
> + fflags |= O_CLOEXEC;
> + flags &= ~SFD_CLOEXEC;
> + }
> + if (flags)
> + return -EINVAL;
> + }
...
> + int fflags = 0;
>
> - if (flags)
> - return -EINVAL;
> + if (flags) {
> + if ((flags & TFD_CLOEXEC) != 0) {
> + fflags |= O_CLOEXEC;
> + flags &= ~TFD_CLOEXEC;
> + }
> + if (flags)
> + return -EINVAL;
> + }
Maybe something like:
struct oflags_rmap {
int f, of;
};
unsigned int oflags_remap(const struct oflags_rmap *m, int n,
int f, int *rf)
{
int i;
for (i = 0, *rf = 0; i < n; i++, m++)
if (f & m->f) {
*rf |= m->of;
f &= ~m->f;
}
return f ? -EINVAL: 0;
}
Then, in all the cases above (modulo different "struct oflags_rmap"
fillings):
const struct oflags_rmap ormap[] = {
{ TFD_CLOEXEC, O_CLOEXEC }
};
error = oflags_remap(ormap, ARRAY_SIZE(ormap), flags, &fflags);
- Davide
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/