1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-28 11:55:44 +03:00

homework: only do image locks for regular image files

If an image file is actually a block device taking a lock on it doesn't
really make sense for us: it will interfere with udev's block device
probing logic, and it's not going to propagated across the network
anyway (which is what we are after here). Hence simply don't do it.

Follow-up for 2aaf565a2d
This commit is contained in:
Lennart Poettering 2021-10-14 15:38:03 +02:00
parent 6a1301d8c9
commit 2aa94bb88a

View File

@ -1058,6 +1058,21 @@ static int lock_image_fd(int image_fd, const char *ip) {
if (r < 0)
return log_error_errno(r, "Failed to parse $SYSTEMD_LUKS_LOCK environment variable: %m");
if (r > 0) {
struct stat st;
if (fstat(image_fd, &st) < 0)
return log_error_errno(errno, "Failed to stat image file: %m");
if (S_ISBLK(st.st_mode)) {
/* Locking block devices doesn't really make sense, as this might interfear with
* udev's workings, and these locks aren't network propagated anyway, hence not what
* we are after here. */
log_debug("Not locking image file '%s', since it's a block device.", ip);
return 0;
}
r = stat_verify_regular(&st);
if (r < 0)
return log_error_errno(r, "Image file to lock is not a regular file: %m");
if (flock(image_fd, LOCK_EX|LOCK_NB) < 0) {
if (errno == EWOULDBLOCK)