Module Name:    src
Committed By:   apb
Date:           Fri Mar  8 09:33:00 UTC 2013

Modified Files:
        src/sys/kern: sys_sig.c

Log Message:
Properly differentiate between infinite timeout and zero timeout.
Local variable timo = -1 is used for zero timeout (non blocking mode).

Fixes PR 47625 from anthony.mallet


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/kern/sys_sig.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_sig.c
diff -u src/sys/kern/sys_sig.c:1.40 src/sys/kern/sys_sig.c:1.41
--- src/sys/kern/sys_sig.c:1.40	Fri Mar  8 08:48:38 2013
+++ src/sys/kern/sys_sig.c	Fri Mar  8 09:32:59 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_sig.c,v 1.40 2013/03/08 08:48:38 apb Exp $	*/
+/*	$NetBSD: sys_sig.c,v 1.41 2013/03/08 09:32:59 apb Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_sig.c,v 1.40 2013/03/08 08:48:38 apb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_sig.c,v 1.41 2013/03/08 09:32:59 apb Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -728,8 +728,12 @@ sigtimedwait1(struct lwp *l, const struc
 			return error;
 
 		timo = tstohz(&ts);
-		if (timo == 0 && ts.tv_sec == 0 && ts.tv_nsec != 0)
-			timo++;
+		if (timo == 0) {
+			if (ts.tv_sec == 0 && ts.tv_nsec == 0)
+				timo = -1; /* do not block */
+			else
+				timo = 1; /* the shortest possible timeout */
+		}
 
 		/*
 		 * Remember current uptime, it would be used in
@@ -738,7 +742,7 @@ sigtimedwait1(struct lwp *l, const struc
 		getnanouptime(&tsstart);
 	} else {
 		memset(&tsstart, 0, sizeof(tsstart)); /* XXXgcc */
-		timo = 0;
+		timo = 0; /* infinite timeout */
 	}
 
 	error = (*fetchss)(SCARG(uap, set), &l->l_sigwaitset,
@@ -765,6 +769,12 @@ sigtimedwait1(struct lwp *l, const struc
 		goto out;
 	}
 
+	if (timo < 0) {
+		/* If not allowed to block, return an error */
+		mutex_exit(p->p_lock);
+		return EAGAIN;
+	}
+
 	/*
 	 * Set up the sigwait list and wait for signal to arrive.
 	 * We can either be woken up or time out.

Reply via email to