chiark / gitweb /
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)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:49:55 +0000 (07:49 +0200)
commit080db1701adb8ea7fccceb115a10704a5ad3282c
treeeddeb916a869574016332c9f656eccca5e34a065
parent248448bd6f47d120677ed5e0f562db656ff07f17
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