summaryrefslogtreecommitdiff
path: root/src/basic/fs-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-03-20 18:20:01 +0100
committerSven Eden <yamakuzure@gmx.net>2018-06-28 09:24:07 +0200
commit18290595761869a7487aa38284665b16bf673340 (patch)
treea88453d8016f11f5235e902fcdfb68ade766d95f /src/basic/fs-util.c
parent705723a2a6177b50d561aab451133beab6f31efa (diff)
basic/fs-util: skip fsync_directory_of_file() if /proc/self/fd/ is not available (#8386)
When systemd is running under lorax (in Fedora compose process), it'd think that it failed to write /etc/machine-id, even though the write succeeded, because fsync_directory_of_file() would fail, because /proc/self/fd/ is not available. fsync_directory_of_file() is mostly an additional safety net, so I think it's best to just silently ignore the error. Strace of pid1: 35791 stat("/etc", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 35791 openat(AT_FDCWD, "/etc/machine-id", O_RDWR|O_CREAT|O_NOCTTY|O_CLOEXEC, 0444) = 3 35791 umask(022) = 000 35791 read(3, "", 38) = 0 35791 openat(AT_FDCWD, "/var/lib/dbus/machine-id", O_RDONLY|O_NOCTTY|O_NOFOLLOW|O_CLOEXEC) = -1 ENOENT (No such file o r directory) 35791 openat(AT_FDCWD, "/sys/class/dmi/id/product_name", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) 35791 openat(AT_FDCWD, "/sys/class/dmi/id/sys_vendor", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) 35791 openat(AT_FDCWD, "/sys/class/dmi/id/board_vendor", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) 35791 openat(AT_FDCWD, "/sys/class/dmi/id/bios_vendor", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) 35791 access("/proc/xen", F_OK) = -1 ENOENT (No such file or directory) 35791 openat(AT_FDCWD, "/sys/hypervisor/type", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) 35791 openat(AT_FDCWD, "/proc/cpuinfo", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) 35791 getrandom("\xb8\x82\xed\xd4\x35\x11\xd0\xeb\xa6\x79\xd7\x31\x6e\x7b\x99\xce", 16, GRND_NONBLOCK) = 16 35791 writev(2, [{iov_base="Initializing machine ID from random generator.", iov_len=46}, {iov_base="\n", iov_len=1}], 2) = 47 35791 lseek(3, 0, SEEK_SET) = 0 35791 ftruncate(3, 0) = 0 35791 write(3, "b882edd4351140eba679d7316e7b99ce\n", 33) = 33 35791 fsync(3) = 0 35791 fstat(3, {st_mode=S_IFREG|0444, st_size=33, ...}) = 0 35791 readlinkat(AT_FDCWD, "/proc/self/fd/3", 0x564df8c694c0, 99) = -1 ENOENT (No such file or directory) 35791 close(3) = 0 35791 umask(022) = 022 35791 openat(AT_FDCWD, "/run/machine-id", O_WRONLY|O_CREAT|O_NOCTTY|O_TRUNC|O_CLOEXEC, 0444) = 3 35791 write(3, "b882edd4351140eba679d7316e7b99ce\n", 33) = 33 35791 close(3) = 0 35791 umask(022) = 022 35791 mount("/run/machine-id", "/etc/machine-id", NULL, MS_BIND, NULL) = 0 35791 writev(2, [{iov_base="Installed transient /etc/machine-id file.", iov_len=41}, {iov_base="\n", iov_len=1}], 2) = 42 35791 mount(NULL, "/etc/machine-id", NULL, MS_RDONLY|MS_REMOUNT|MS_BIND, NULL) = 0 https://bugzilla.redhat.com/show_bug.cgi?id=1552843 (cherry picked from commit 3ceae1bc14d2da3fc1fe4753d6657759012256dc)
Diffstat (limited to 'src/basic/fs-util.c')
-rw-r--r--src/basic/fs-util.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index 687a406d7..e556ff7e0 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -993,8 +993,19 @@ int fsync_directory_of_file(int fd) {
return r;
r = fd_get_path(fd, &path);
- if (r < 0)
+ if (r < 0) {
+ log_debug("Failed to query /proc/self/fd/%d%s: %m",
+ fd,
+ r == -EOPNOTSUPP ? ", ignoring" : "");
+
+ if (r == -EOPNOTSUPP)
+ /* If /proc is not available, we're most likely running in some
+ * chroot environment, and syncing the directory is not very
+ * important in that case. Let's just silently do nothing. */
+ return 0;
+
return r;
+ }
if (!path_is_absolute(path))
return -EINVAL;