From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14257 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Sergei Trofimovich Newsgroups: gmane.linux.lib.musl.general Subject: return-value/errno for utimensat(, NULL, NULL, 0) mismatch across musl and glibc: bug or a feature? Date: Tue, 25 Jun 2019 21:35:25 +0100 Message-ID: <20190625213525.0407b535@sf> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="162085"; mail-complaints-to="usenet@blaine.gmane.org" To: musl@lists.openwall.com Original-X-From: musl-return-14273-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jun 25 23:16:20 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1hfsnb-000g13-LE for gllmg-musl@m.gmane.org; Tue, 25 Jun 2019 23:16:19 +0200 Original-Received: (qmail 17908 invoked by uid 550); 25 Jun 2019 21:16:16 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 11886 invoked from network); 25 Jun 2019 20:35:45 -0000 X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Xref: news.gmane.org gmane.linux.lib.musl.general:14257 Archived-At: Hi musl@ folk! The original issue popped in https://bugs.gentoo.org/549108#c22. There glibc's utimensat() wrapper handles one corner case differently from musl's wrapper. Here is the minimal reproducer: $ cat a.c #include #include #include #include int main() { int fd = open("f", O_WRONLY|O_CREAT, 0666); return utimensat(fd, NULL, NULL, 0); } On glibc (x86_64 linux-5.2-rc5): $ gcc a.c -o a && strace -etrace=open,openat,utimensat,exit_group ./a openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 openat(AT_FDCWD, "f", O_WRONLY|O_CREAT, 0666) = 3 exit_group(-1) = ? +++ exited with 255 +++ On musl (x86_64 linux-5.2-rc5): $ gcc a.c -o a && strace -etrace=open,openat,utimensat,exit_group ./a open("f", O_WRONLY|O_CREAT, 0666) = 3 utimensat(3, NULL, NULL, 0) = 0 exit_group(0) = ? The difference stems from this extra check in glibc: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/utimensat.c;h=04b549f360b88a7e7c1e5e617158caf73299736b;hb=HEAD#l32 int utimensat (int fd, const char *file, const struct timespec tsp[2], int flags) { if (file == NULL) return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); /* Avoid implicit array coercion in syscall macros. */ return INLINE_SYSCALL (utimensat, 4, fd, file, &tsp[0], flags); } while musl just calls the syscall directly: https://git.musl-libc.org/cgit/musl/tree/src/stat/utimensat.c int utimensat(int fd, const char *path, const struct timespec times[2], int flags) { int r = __syscall(SYS_utimensat, fd, path, times, flags); // ... return __syscall_ret(r); } Is this divergence expected? Or maybe it's accidental? Does it make sense to handle non-directory fds in utimensat() according to POSIX? I wonder if we should drop the unstable test or some of libc implementations actually deviates from the spec. Thank you! -- Sergei