[systemd-devel] [PATCH] tree-wide: Introduce a dup_cloexec inline helper

Lennart Poettering lennart at poettering.net
Wed Apr 22 13:19:29 PDT 2015


On Wed, 22.04.15 16:29, Cristian Rodríguez (crrodriguez at opensuse.org) wrote:

> - Nicer & easier to remember than fcntl(fd, F_DUPFD_CLOEXEC, 3)
> - Update CODING_STYLE
> - Use it tree-wide

I am not convinced this is a good idea like this.

Our own functions tend to return proper negative error codes. This
function should hence do the same, at least.

Also, It shouldn't be called dup_cloexec() I think, since that
misleads people to think it is just a cloexec version of dup(), which
it isn't. Maybe a name like dupfd_cloexec() would be better, since it
doesn't try to be similar named to dup(), and in fact is closer to
"F_DUPFD_CLOEXEC" that it internall wraps.

> +static inline int dup_cloexec(int oldfd)
> +{
> +        return fcntl(oldfd, F_DUPFD_CLOEXEC, STDERR_FILENO + 1);
> +}

We place the opening { on the same line as the function name, see
CODING_STYLE.

Also, a comment next to that declaration is probably a good idea, to
explain why this function exists at all, and is better than dup().

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list