From patchwork Thu Dec 19 16:24:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 103438 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 3078D3858D26 for ; Thu, 19 Dec 2024 16:25:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3078D3858D26 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fPv4LLQZ X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 3333E3858D20 for ; Thu, 19 Dec 2024 16:24:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3333E3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3333E3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734625469; cv=none; b=SnSNhqCj7ClrkLyTOyy8N4PsdqqkKHvhqBXiudpB81SmJlnQ+kKEbmUEogCivTtd3jgB+Hb9Z/2iLneVYFMnzC0pwgXjf0IA6BuU9JkkV0sP2LozKt3v/O7bGXecmbJQMdpmpo1BYtdOAlPb278v0o+7CvpbpnUe3QJy3CDio1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734625469; c=relaxed/simple; bh=y9TJQGpkN1IveyxL3mF9sQpYP/DwPyMVuhaEIAqp4gk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=LzzVErfr3WFoMZdfDB9/YoKgFiw+ti99OYJGdDiOznYTYkoOlcFYr2S9RU39i/DrrSQREF4SsGosWZc5bUloZdnX5c/UV3u+DdPD8f21Mlmf+uOXChfBVp5oP05GpmK9Pjf/778JDEUxrOD1BxrituxdPOKwa0zCcpgHY5jNl8o= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3333E3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734625468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=Cdyx0Eimw0d/jOnWVMWuVVgvBwv4cqh0yM0yCKtcW+w=; b=fPv4LLQZgFa6m3/Ju16nKNZ1I08BazoS567HdoeObXDHydlup11myvXZZEzFYtOb53AJIh V92PrNbWxPT7EKPh9asopgvMZUMvoows/5v4w+rtnoRa365iXv9asVd+g/WYWQVduGhA4E 970WbzaJkFqFKW4NpEBptWI+jG2n6+M= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-199-ftncPpf0Mr6KP9c-C376Xw-1; Thu, 19 Dec 2024 11:24:27 -0500 X-MC-Unique: ftncPpf0Mr6KP9c-C376Xw-1 X-Mimecast-MFC-AGG-ID: ftncPpf0Mr6KP9c-C376Xw Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BE0EE19560AF for ; Thu, 19 Dec 2024 16:24:26 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.21]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DB051195608A for ; Thu, 19 Dec 2024 16:24:25 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] Linux: Accept null arguments for utimensat pathname Date: Thu, 19 Dec 2024 17:24:22 +0100 Message-ID: <87zfkrwsi1.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 9-7o__BZDdbQW60qa66nUbSsrdNbm_LZoAP6jgrwbn8_1734625466 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org This matches kernel behavior. With this change, it is possible to use utimensat as a replacement for the futimens interface, similar to what glibc does internally. Tested on i686-linux-gnu and x86_64-linux-gnu. Reviewed-by: Paul Eggert --- io/sys/stat.h | 4 ++-- io/tst-utimensat.c | 32 ++++++++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/utimensat.c | 3 --- 3 files changed, 34 insertions(+), 5 deletions(-) base-commit: d421d36582281a62e05f96a1bfb085db9d85f40b diff --git a/io/sys/stat.h b/io/sys/stat.h index 0e4edb483d..dd96b88d0f 100644 --- a/io/sys/stat.h +++ b/io/sys/stat.h @@ -433,13 +433,13 @@ extern int mkfifoat (int __fd, const char *__path, __mode_t __mode) extern int utimensat (int __fd, const char *__path, const struct timespec __times[2], int __flags) - __THROW __nonnull ((2)); + __THROW; # else # ifdef __REDIRECT_NTH extern int __REDIRECT_NTH (utimensat, (int fd, const char *__path, const struct timespec __times[2], int flags), - __utimensat64) __nonnull ((2)); + __utimensat64); # else # define utimensat __utimensat64 # endif diff --git a/io/tst-utimensat.c b/io/tst-utimensat.c index 2a756d7b07..43786817b5 100644 --- a/io/tst-utimensat.c +++ b/io/tst-utimensat.c @@ -39,6 +39,38 @@ test_utimesat_helper (const char *testfile, int fd, const char *testlink, TEST_COMPARE (st.stx_mtime.tv_sec, ts[1].tv_sec); } + /* Alter the timestamp using a NULL path. */ + { + struct timespec ts1[2] = {ts[0], ts[1]}; + ts1[0].tv_sec ^= 1; + ts1[1].tv_sec ^= 1; + + TEST_VERIFY_EXIT (utimensat (fd, NULL, ts1, 0) == 0); + + struct statx st; + xstatx (fd, "", AT_EMPTY_PATH, STATX_BASIC_STATS, &st); + + /* Check if seconds for atime match */ + TEST_COMPARE (st.stx_atime.tv_sec, ts[0].tv_sec ^ 1); + + /* Check if seconds for mtime match */ + TEST_COMPARE (st.stx_mtime.tv_sec, ts[1].tv_sec ^ 1); + } + + /* And switch it back using a NULL path. */ + { + TEST_VERIFY_EXIT (utimensat (fd, NULL, ts, 0) == 0); + + struct statx st; + xstatx (fd, "", AT_EMPTY_PATH, STATX_BASIC_STATS, &st); + + /* Check if seconds for atime match */ + TEST_COMPARE (st.stx_atime.tv_sec, ts[0].tv_sec); + + /* Check if seconds for mtime match */ + TEST_COMPARE (st.stx_mtime.tv_sec, ts[1].tv_sec); + } + { struct statx stfile_orig; xstatx (AT_FDCWD, testfile, AT_SYMLINK_NOFOLLOW, STATX_BASIC_STATS, diff --git a/sysdeps/unix/sysv/linux/utimensat.c b/sysdeps/unix/sysv/linux/utimensat.c index 991897f50d..f3ba1aa647 100644 --- a/sysdeps/unix/sysv/linux/utimensat.c +++ b/sysdeps/unix/sysv/linux/utimensat.c @@ -75,9 +75,6 @@ int __utimensat64 (int fd, const char *file, const struct __timespec64 tsp64[2], int flags) { - if (file == NULL) - return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); - return __utimensat64_helper (fd, file, &tsp64[0], flags); }