From 1e485991938851e12c96014858e7d2c9e7eed383 Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Mon, 12 Aug 2024 14:31:19 +0200 Subject: [PATCH] libdm: do not fail if GETVAL semctl fails for udev sync inc and dec While performing udev sync semaphore's inc/dec operation, we use the result from GETVAL semctl just to print a debug message with current value of that sempahore, nothing else. If the GETVAL fails for whetever reason while the actual inc/dec completes successfully, just log a warning message about the GETVAL (and print the debug messages without the actual semaphore value) and return success for the inc/dec operation as a whole. --- device_mapper/libdm-common.c | 31 ++++++++++++++++--------------- libdm/libdm-common.c | 31 ++++++++++++++++--------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/device_mapper/libdm-common.c b/device_mapper/libdm-common.c index db7c75277..ff96ed096 100644 --- a/device_mapper/libdm-common.c +++ b/device_mapper/libdm-common.c @@ -2443,14 +2443,14 @@ static int _udev_notify_sem_inc(uint32_t cookie, int semid) } if ((val = semctl(semid, 0, GETVAL)) < 0) { - log_error("cookie inc: semid %d: sem_ctl GETVAL failed for " + log_warn("cookie inc: semid %d: sem_ctl GETVAL failed for " "cookie 0x%" PRIx32 ": %s", semid, cookie, strerror(errno)); - return 0; - } - - log_debug_activation("Udev cookie 0x%" PRIx32 " (semid %d) incremented to %d", - cookie, semid, val); + log_debug_activation("Udev cookie 0x%" PRIx32 " (semid %d) incremented.", + cookie, semid); + } else + log_debug_activation("Udev cookie 0x%" PRIx32 " (semid %d) incremented to %d", + cookie, semid, val); return 1; } @@ -2460,12 +2460,10 @@ static int _udev_notify_sem_dec(uint32_t cookie, int semid) struct sembuf sb = {0, -1, IPC_NOWAIT}; int val; - if ((val = semctl(semid, 0, GETVAL)) < 0) { - log_error("cookie dec: semid %d: sem_ctl GETVAL failed for " - "cookie 0x%" PRIx32 ": %s", - semid, cookie, strerror(errno)); - return 0; - } + if ((val = semctl(semid, 0, GETVAL)) < 0) + log_warn("cookie dec: semid %d: sem_ctl GETVAL failed for " + "cookie 0x%" PRIx32 ": %s", + semid, cookie, strerror(errno)); if (semop(semid, &sb, 1) < 0) { switch (errno) { @@ -2484,9 +2482,12 @@ static int _udev_notify_sem_dec(uint32_t cookie, int semid) return 0; } - log_debug_activation("Udev cookie 0x%" PRIx32 " (semid %d) decremented to %d", - cookie, semid, val - 1); - + if (val < 0) + log_debug_activation("Udev cookie 0x%" PRIx32 " (semid %d) decremented.", + cookie, semid); + else + log_debug_activation("Udev cookie 0x%" PRIx32 " (semid %d) decremented to %d", + cookie, semid, val - 1); return 1; } diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c index 4054d6cc0..d347bfe16 100644 --- a/libdm/libdm-common.c +++ b/libdm/libdm-common.c @@ -2442,14 +2442,14 @@ static int _udev_notify_sem_inc(uint32_t cookie, int semid) } if ((val = semctl(semid, 0, GETVAL)) < 0) { - log_error("cookie inc: semid %d: sem_ctl GETVAL failed for " + log_warn("cookie inc: semid %d: sem_ctl GETVAL failed for " "cookie 0x%" PRIx32 ": %s", semid, cookie, strerror(errno)); - return 0; - } - - log_debug_activation("Udev cookie 0x%" PRIx32 " (semid %d) incremented to %d", - cookie, semid, val); + log_debug_activation("Udev cookie 0x%" PRIx32 " (semid %d) incremented.", + cookie, semid); + } else + log_debug_activation("Udev cookie 0x%" PRIx32 " (semid %d) incremented to %d", + cookie, semid, val); return 1; } @@ -2459,12 +2459,10 @@ static int _udev_notify_sem_dec(uint32_t cookie, int semid) struct sembuf sb = {0, -1, IPC_NOWAIT}; int val; - if ((val = semctl(semid, 0, GETVAL)) < 0) { - log_error("cookie dec: semid %d: sem_ctl GETVAL failed for " - "cookie 0x%" PRIx32 ": %s", - semid, cookie, strerror(errno)); - return 0; - } + if ((val = semctl(semid, 0, GETVAL)) < 0) + log_warn("cookie dec: semid %d: sem_ctl GETVAL failed for " + "cookie 0x%" PRIx32 ": %s", + semid, cookie, strerror(errno)); if (semop(semid, &sb, 1) < 0) { switch (errno) { @@ -2483,9 +2481,12 @@ static int _udev_notify_sem_dec(uint32_t cookie, int semid) return 0; } - log_debug_activation("Udev cookie 0x%" PRIx32 " (semid %d) decremented to %d", - cookie, semid, val - 1); - + if (val < 0) + log_debug_activation("Udev cookie 0x%" PRIx32 " (semid %d) decremented.", + cookie, semid); + else + log_debug_activation("Udev cookie 0x%" PRIx32 " (semid %d) decremented to %d", + cookie, semid, val - 1); return 1; }