Skip to contentSkip to conversation

master - dmeventd: pthread_sigmask in single function

PATCH Zdenek Kabelac 1 participant 1 message Oct 3, 2016

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=00f883a4aa10079bac21c294ce5ed34f11af8ac7
Commit:        00f883a4aa10079bac21c294ce5ed34f11af8ac7
Parent:        d70f1127624fa64ee691eb4c9d4bce5a4845f985
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Mon Oct 3 15:39:54 2016 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Mon Oct 3 17:47:28 2016 +0200

dmeventd: pthread_sigmask in single function

Integrate back _unblock_sigalrm() and check for error code of pthread_sigmask() function so we do not use uninitialized sigmask_t on error path (Coverity).

---
 WHATS_NEW_DM                |    1 +
 daemons/dmeventd/dmeventd.c |   25 ++++++++++---------------
 2 files changed, 11 insertions(+), 15 deletions(-)
WHATS_NEW_DM +1 -0
index 4303dc9..c69eb27 100644
@@ -1,5 +1,6 @@
 Version 1.02.136 - 
 ======================================
+  Check and report pthread_sigmask() failure in dmeventd.
   Check mem alloc fail in _canonicalize_field_ids().
   Use unsigned math when checking more then 31 legs of raid.
   Fix 'dmstats delete' with dmsetup older than v1.02.129
daemons/dmeventd/dmeventd.c +10 -15
index 25b34a7..6024e56 100644
@@ -829,17 +829,6 @@ static void _print_sigset(const char *prefix, const sigset_t *sigset)
 }
 #endif
 
-static sigset_t _unblock_sigalrm(void)
-{
-	sigset_t set, old;
-
-	sigemptyset(&set);
-	sigaddset(&set, SIGALRM);
-	pthread_sigmask(SIG_UNBLOCK, &set, &old);
-
-	return old;
-}
-
 enum {
 	DM_WAIT_RETRY,
 	DM_WAIT_INTR,
@@ -849,7 +838,7 @@ enum {
 /* Wait on a device until an event occurs. */
 static int _event_wait(struct thread_status *thread)
 {
-	sigset_t set;
+	sigset_t set, old;
 	int ret = DM_WAIT_RETRY;
 	struct dm_info info;
 
@@ -859,7 +848,12 @@ static int _event_wait(struct thread_status *thread)
 	 * This is so that you can break out of waiting on an event,
 	 * either for a timeout event, or to cancel the thread.
 	 */
-	set = _unblock_sigalrm();
+	sigemptyset(&set);
+	sigaddset(&set, SIGALRM);
+	if (pthread_sigmask(SIG_UNBLOCK, &set, &old) != 0) {
+		log_sys_error("pthread_sigmask", "unblock alarm");
+		return ret; /* What better */
+	}
 
 	if (dm_task_run(thread->wait_task)) {
 		thread->current_events |= DM_EVENT_DEVICE_ERROR;
@@ -883,10 +877,11 @@ static int _event_wait(struct thread_status *thread)
 		}
 	}
 
-	pthread_sigmask(SIG_SETMASK, &set, NULL);
+	if (pthread_sigmask(SIG_SETMASK, &old, NULL) != 0)
+		log_sys_error("pthread_sigmask", "block alarm");
 
 #ifdef DEBUG_SIGNALS
-	_print_sigset("dmeventd blocking ", &set);
+	_print_sigset("dmeventd blocking ", &old);
 #endif
 	DEBUGLOG("Completed waitevent task for %s.", thread->device.name);