From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id DF7F25A0262 for ; Tue, 6 Jun 2023 22:59:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686085148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kbiYxl25VF2yQJXLFdxp+AlaetF3k99viFkSF6kJDI8=; b=Csng/LZt4I5L1YH1IOG5Evq2O29aYjnc6z6lIqhUjFifmeeonjdVt1zWWnYHJxLjlfp1cD F4pOXrn16j3g7KlP26OazRm+NrgXiMtI6OagXjSDIIcvH8sG15saDJr5p+tsuWaOYPKFur iIbgdmlhUh2egwvUdsvOOCKfQIw1xc0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-563-3Tod5MGxPxu_tdNtchBTDg-1; Tue, 06 Jun 2023 16:59:07 -0400 X-MC-Unique: 3Tod5MGxPxu_tdNtchBTDg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 08C35280D582 for ; Tue, 6 Jun 2023 20:59:07 +0000 (UTC) Received: from elisabeth (unknown [10.39.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 507D2400E6C6; Tue, 6 Jun 2023 20:59:06 +0000 (UTC) Date: Tue, 6 Jun 2023 22:59:04 +0200 From: Stefano Brivio To: Michal Privoznik Subject: Re: [PATCH 1/2] util: Introduce set_cloexec() Message-ID: <20230606225904.17cf1954@elisabeth> In-Reply-To: <99c455f027b5d94f45e34abb8ce875814e4dc534.1686037337.git.mprivozn@redhat.com> References: <99c455f027b5d94f45e34abb8ce875814e4dc534.1686037337.git.mprivozn@redhat.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: DG3I7CI2LAZMMYHO2FZ3JO44CZD4MBY6 X-Message-ID-Hash: DG3I7CI2LAZMMYHO2FZ3JO44CZD4MBY6 X-MailFrom: sbrivio@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Tue, 6 Jun 2023 13:41:29 +0200 Michal Privoznik 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 > --- > 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