fs-util: Handle dangling symlinks in openat_report_new()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 24 Jul 2024 08:41:24 +0000 (10:41 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 24 Jul 2024 16:58:41 +0000 (18:58 +0200)
commit0dd82dab91eaac5e7b17bd5e9a1e07c6d2b78dca
tree5d5412fae49e988ead3eee3c06e57ad9478ab726
parentb91ad562280ec4f37ba970f1f167d2d626da2692
fs-util: Handle dangling symlinks in openat_report_new()

openat() will always resolve symlinks, except if O_NOFOLLOW is passed
or O_CREAT|O_EXCL is passed. This means that if a dangling symlink is
passed to openat_report_new(), the first call to openat() will always
fail with ENOENT and the second call to openat() will always fail with
EEXIST.

Let's catch this case explicitly and fallback to creating the file with
just O_CREAT and assume we're the ones that created the file. We can't
resolve the symlink with chase() because this function is itself called
by chase() so we could end up in weird recursive calls if we'd try to do
so.
src/basic/fs-util.c
src/test/test-fs-util.c