[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#240203: sem_wait return value error


Please apply attached patch for correcting the documentation issue.

People have been writing code not checking sem_wait() for far too long
and this is really a important issue! For instance, the following
program would be intended to hang forever:

#include <semaphore.h>
#include <stdio.h>
#include <signal.h>
#include <errno.h>

void sig(int sig) {
sem_t sem;
int err;
int main(void) {
	signal(SIGWINCH, sig);
	sem_init(&sem, 0, 0);
	err = errno;
	return 0;

But if one just resizes the terminal in which it is running, hence a
SIGWINCH is sent, sem_wait returns -1/EINTR (normal posix behavior) and
the program terminates...

--- sem_wait_orig.3	2005-10-08 15:49:42.000000000 +0200
+++ sem_wait.3	2005-10-08 15:50:35.000000000 +0200
@@ -83,7 +83,7 @@
-The !sem_wait! and !sem_getvalue! functions always return 0.
+The !sem_getvalue! function always returns 0.
 All other semaphore functions return 0 on success and -1 on error, in
 addition to writing an error code in !errno!.
@@ -99,6 +99,18 @@
 |pshared| is not zero
+The !sem_wait! function sets !errno! to the following code on error:
+A signal interrupted this function. Hence the operation was
+completed and the caller needs to try again.
 The !sem_trywait! function sets !errno! to the following error code on error:

Reply to: