lkml.org 
[lkml]   [2008]   [Apr]   [28]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
DateSun, 27 Apr 2008 22:11:28 -0700 (PDT)
FromDavide Libenzi <>
SubjectRe: [PATCH v2] eventfd, signalfd, timerfd, epoll_create w/flags
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




\
 
 \ /
  Last update: 2008-04-28 07:13    [from the cache]
©2003-2008