]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/test/test-fs-util.c
fs-util: rework touch_file() so that it can touch socket file nodes
authorLennart Poettering <lennart@poettering.net>
Wed, 27 Dec 2017 15:20:28 +0000 (16:20 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 5 Jan 2018 12:55:08 +0000 (13:55 +0100)
commit9e3fa6e82773cb1d8687453ef0ba0ad9e5dda7d2
tree6ffb7f341c8cd68a22aee71225ddf3e967ca6d2c
parent5ae37ad833583e6c1c7765767b7f8360afca3b07
fs-util: rework touch_file() so that it can touch socket file nodes

Let's rework touch_file() so that it works correctly on sockets, fifos,
and device nodes: let's open an O_PATH file descriptor first and operate
based on that, if we can. This is usually the better option as it this
means we can open AF_UNIX nodes in the file system, and update their
timestamps and ownership correctly. It also means we can correctly touch
symlinks and block/character devices without triggering their drivers.

Moreover, by operating on an O_PATH fd we can make sure that we
operate on the same inode the whole time, and it can't be swapped out in
the middle.

While we are at it, rework the call so that we try to adjust as much as
we can before returning on error. This is a good idea as we call the
function quite often without checking its result, and hence it's best to
leave the files around in the most "correct" fashion possible.
src/basic/fs-util.c
src/test/test-fs-util.c