[pseudo] [PATCH v2] linkat: Fix AT_EMPTY_PATH handling
Richard Purdie <[email protected]> Mon, 20 Jul 2026 11:55:00 +0100
| Newsgroups | org.yoctoproject.lists.yocto-patches |
|---|---|
| Message-ID | <[email protected]> |
Currently we don't cover the case where AT_EMPTY_PATH is set for linkat. Update the code to handle this case in a similar way to the /proc/self case which is similar. This is used by some systemd tools which OE might run at rootfs time such as hwdb generation. Signed-off-by: Richard Purdie <[email protected]> --- ports/unix/guts/linkat.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ports/unix/guts/linkat.c b/ports/unix/guts/linkat.c index 60fbf63..3fd708c 100644 --- a/ports/unix/guts/linkat.c +++ b/ports/unix/guts/linkat.c @@ -35,13 +35,18 @@ } #endif oldpath = oldname; - if (pseudo_chroot_len && !strncmp(oldpath, pseudo_chroot, pseudo_chroot_len) && + if (oldpath && *oldpath && pseudo_chroot_len && !strncmp(oldpath, pseudo_chroot, pseudo_chroot_len) && oldpath[pseudo_chroot_len] == '/') { oldpath += pseudo_chroot_len; } newpath = pseudo_root_path(__func__, __LINE__, newdirfd, newname, AT_SYMLINK_NOFOLLOW); + if ((!oldpath || !*oldpath) && (flags & AT_EMPTY_PATH)) { + tmpfile_fd = olddirfd; + // call actual link + rc = real_linkat(olddirfd, "", AT_FDCWD, newpath, flags); + } else /* weird special case: if you link /proc/self/fd/N, you're supposed * to get a link to fd N. Used in conjunction with opening a directory * with O_TMPFILE in flags, which actually opens an already-deleted