lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <BY2PR05MB19767A6672D0773553EAAE0AEB380@BY2PR05MB1976.namprd05.prod.outlook.com>
Date:	Wed, 21 Oct 2015 07:20:22 +0000
From:	"Kilian, Jens" <jens.kilian@...antest.com>
To:	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Missing wait_event_killable_timeout?

I'd like to use a version of wait_event_killable() with a timeout, but it seems to be missing?  I found a mention of it in a recent LKML message though:

	https://lkml.org/lkml/2015/10/14/337

Does this patch look reasonable?

diff --git a/include/linux/wait.h b/include/linux/wait.h
index 1e1bf9f..8419986 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -738,6 +738,41 @@ do {									\
 	__ret;								\
 })
 
+#define __wait_event_killable_timeout(wq, condition, timeout)   	\
+	___wait_event(wq, ___wait_cond_timeout(condition),		\
+		      TASK_KILLABLE, 0, timeout,			\
+		      __ret = schedule_timeout(__ret))
+
+/**
+ * wait_event_killable_timeout - sleep until a condition gets true or a timeout elapses
+ * @wq: the waitqueue to wait on
+ * @condition: a C expression for the event to wait for
+ * @timeout: timeout, in jiffies
+ *
+ * The process is put to sleep (TASK_KILLABLE) until the @condition
+ * evaluates to true or a signal is received.
+ * The @condition is checked each time the waitqueue @wq is woken up.
+ *
+ * wake_up() has to be called after changing any variable that could
+ * change the result of the wait condition.
+ *
+ * Returns:
+ * 0 if the @condition evaluated to %false after the @timeout elapsed,
+ * 1 if the @condition evaluated to %true after the @timeout elapsed,
+ * the remaining jiffies (at least 1) if the @condition evaluated
+ * to %true before the @timeout elapsed, or -%ERESTARTSYS if it was
+ * interrupted by a signal.
+ */
+#define wait_event_killable_timeout(wq, condition, timeout)	\
+({									\
+	long __ret = timeout;						\
+	might_sleep();							\
+	if (!___wait_cond_timeout(condition))				\
+		__ret = __wait_event_killable_timeout(wq,		\
+						condition, timeout);	\
+	__ret;								\
+})
+
 
 #define __wait_event_lock_irq(wq, condition, lock, cmd)			\
 	(void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0,	\


-- 
Jens Kilian

Advantest Europe GmbH
Managing Directors / Geschaeftsfuehrer: Josef Schraetzenstaller, Hans-Juergen Wagner
Vorsitzender des Aufsichtsrats / Chairman of the Supervisory Board: Hiroshi Nakamura
Commercial Court / Handelsregister: Muenchen HRB 71083, Seat / Sitz: Muenchen

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ