public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: Michal Privoznik <mprivozn@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 1/2] util: Introduce set_cloexec()
Date: Tue, 6 Jun 2023 22:59:04 +0200	[thread overview]
Message-ID: <20230606225904.17cf1954@elisabeth> (raw)
In-Reply-To: <99c455f027b5d94f45e34abb8ce875814e4dc534.1686037337.git.mprivozn@redhat.com>

On Tue,  6 Jun 2023 13:41:29 +0200
Michal Privoznik <mprivozn@redhat.com> wrote:

> This function is going to be used on FDs inherited from parent.
> Parent can't set O_CLOEXEC obviously, so we have to set it
> ourselves.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  util.c | 17 +++++++++++++++++
>  util.h |  1 +
>  2 files changed, 18 insertions(+)
> 
> diff --git a/util.c b/util.c
> index 1d00404..9817c74 100644
> --- a/util.c
> +++ b/util.c
> @@ -526,6 +526,23 @@ int write_file(const char *path, const char *buf)
>  	return len == 0 ? 0 : -1;
>  }
>  
> +/**
> + * set_cloexec() - Set Close-on-exec flag on given FD
> + * @fd:		FD to set the flag on

Nits: "close-on-exec", "file descriptor".

> + *
> + * Return: 0 on success, -1 on any error

I'd rather return errno as set by fcntl(), for consistency.

> + */
> +int set_cloexec(int fd)
> +{
> +	int fflags;
> +	if ((fflags = fcntl(fd, F_GETFD)) < 0)
> +		return -1;
> +	fflags |= FD_CLOEXEC;
> +	if ((fcntl(fd, F_SETFD, fflags)) < 0)
> +		return -1;
> +	return 0;
> +}

...but in general, I'm not convinced this is really needed. O_CLOEXEC
has been the only file _descriptor_ flag for 16 years, and I have some
doubts another one will ever come up (and at that point, we wouldn't
probably want to have it set by default anyway).

I'd just set it with a direct call. This is not a strong preference
though.

-- 
Stefano


  reply	other threads:[~2023-06-06 20:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-06 11:41 [PATCH 0/2] Introduce --log-fd option Michal Privoznik
2023-06-06 11:41 ` [PATCH 1/2] util: Introduce set_cloexec() Michal Privoznik
2023-06-06 20:59   ` Stefano Brivio [this message]
2023-06-06 11:41 ` [PATCH 2/2] conf, log: Introduce --log-fd option Michal Privoznik
2023-06-06 20:59   ` Stefano Brivio
2023-06-06 20:58 ` [PATCH 0/2] " Stefano Brivio
2023-06-07 11:38   ` Michal Prívozník
2023-06-07 14:42     ` Stefano Brivio
2023-06-08 11:51       ` Michal Prívozník
2023-06-13  3:12         ` Stefano Brivio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230606225904.17cf1954@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=mprivozn@redhat.com \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).