From patchwork Sun Apr 23 16:05:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 68187 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 76975385772C for ; Sun, 23 Apr 2023 16:06:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76975385772C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682265977; bh=T+9W8flSu9pnM8XKPgyKM+1hQ27FChDAsQNawyYn+H8=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=NkJsy0m8zR9eaUvNc2nqZf1/nnUBj/RBCFpapCV3ORwRh8wHEY+YxIdUyl5CstUJq 35GrLYN5rCO1polDSpd3cBfa/JhbQXxAyle/izIKBNCpyH/F3u0Gqpo5ZWQoryXlLY l3iOTtdv3eLyVsoSCDiofUFgt4fTFdY6/jWOOqZw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by sourceware.org (Postfix) with ESMTPS id 56F173858C83 for ; Sun, 23 Apr 2023 16:05:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 56F173858C83 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2a8b1b51dbdso31871661fa.0 for ; Sun, 23 Apr 2023 09:05:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682265951; x=1684857951; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T+9W8flSu9pnM8XKPgyKM+1hQ27FChDAsQNawyYn+H8=; b=EOMC25dKYRhXPqMB8xLU5W54o9iyl888xr4Jigrqug4642gpBZTtkdDyf8Ui3O9K5G /73oE5fwCet4bvMnCdp5A9lTQPRRvsk3osKm4ntYSs3ZZB4zi5vulN8SYKUuM7t5c8hD 1bj3BcSheFmYCN0w3WC3zL9C4TWRrexiV9R5Ofkxclho6QFZv4R6jGEC4p980lR04MTh NNx3HjoZHuddSe5gaHqtSzdKXkonBLKG0V86J2n+AV9D7OKGkN8NqH5nrBNIbYt4/EYe gXhLZnISo56sRCcyFAOkqFJqgfeGD29MOVcIRJiuOv9GnDqszDrz2ARVugFSfpFMWJoZ +czw== X-Gm-Message-State: AAQBX9fPZ0qvUAh59dWsyxfGyjMkDjk1qDmocTQtJrvXoJz2TpnBqiLj wYOQWTQzu3V+V0iaq0jq0IXmn3VFWbrkuQ== X-Google-Smtp-Source: AKy350YS44yy8X4TqusY1ANcfhn8YhdDObi3FJo8q6Gq6peX/mi/YEceHbrUDWr5rOQHsqPFjM1UBw== X-Received: by 2002:a2e:8095:0:b0:2a0:69e0:9f7a with SMTP id i21-20020a2e8095000000b002a069e09f7amr1937437ljg.41.1682265951083; Sun, 23 Apr 2023 09:05:51 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:4a57:e26d:6595:78ee:6d64]) by smtp.gmail.com with ESMTPSA id y20-20020a2e7d14000000b002a9ed7f6f90sm1411277ljc.73.2023.04.23.09.05.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Apr 2023 09:05:50 -0700 (PDT) To: libc-alpha@sourceware.org Cc: bug-hurd@gnu.org, Samuel Thibault Subject: [PATCH v2 2/4] hurd: Implement MSG_CMSG_CLOEXEC Date: Sun, 23 Apr 2023 19:05:46 +0300 Message-Id: <20230423160548.126576-2-bugaevc@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230423160548.126576-1-bugaevc@gmail.com> References: <20230423160548.126576-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This is a new flag that can be passed to recvmsg () to make it atomically set the CLOEXEC flag on all the file descriptors received using the SCM_RIGHTS mechanism. This is useful for all the same reasons that the other XXX_CLOEXEC flags are useful: namely, it provides atomicity with respect to another thread of the same process calling (fork and then) exec at the same time. This flag is already supported on Linux and FreeBSD. The flag's value, 0x40000, is choosen to match FreeBSD's. Signed-off-by: Sergey Bugaev --- sysdeps/mach/hurd/bits/socket.h | 5 ++++- sysdeps/mach/hurd/recvmsg.c | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sysdeps/mach/hurd/bits/socket.h b/sysdeps/mach/hurd/bits/socket.h index 2d78a916..c2392bed 100644 --- a/sysdeps/mach/hurd/bits/socket.h +++ b/sysdeps/mach/hurd/bits/socket.h @@ -197,8 +197,11 @@ enum #define MSG_WAITALL MSG_WAITALL MSG_DONTWAIT = 0x80, /* This message should be nonblocking. */ #define MSG_DONTWAIT MSG_DONTWAIT - MSG_NOSIGNAL = 0x0400 /* Do not generate SIGPIPE on EPIPE. */ + MSG_NOSIGNAL = 0x0400, /* Do not generate SIGPIPE on EPIPE. */ #define MSG_NOSIGNAL MSG_NOSIGNAL + MSG_CMSG_CLOEXEC = 0x40000 /* Atomically set close-on-exec flag + for file descriptors in SCM_RIGHTS. */ +#define MSG_CMSG_CLOEXEC MSG_CMSG_CLOEXEC }; diff --git a/sysdeps/mach/hurd/recvmsg.c b/sysdeps/mach/hurd/recvmsg.c index c08eb499..9a37a053 100644 --- a/sysdeps/mach/hurd/recvmsg.c +++ b/sysdeps/mach/hurd/recvmsg.c @@ -197,11 +197,12 @@ __libc_recvmsg (int fd, struct msghdr *message, int flags) for (j = 0; j < nfds; j++) { + int fd_flags = (flags & MSG_CMSG_CLOEXEC) ? O_CLOEXEC : 0; err = reauthenticate (ports[i], &newports[newfds]); if (err) goto cleanup; fds[j] = opened_fds[newfds] = _hurd_intern_fd (newports[newfds], - 0, 0); + fd_flags, 0); if (fds[j] == -1) { err = errno;