summaryrefslogtreecommitdiff
path: root/lib/librthread
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2013-11-21 17:43:58 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2013-11-21 17:43:58 +0000
commitb7e329cf5a70a64ce63375d6a45cdd1eb5415f9c (patch)
tree6561be6b904498417d0cae1c845429cf04ebf2bd /lib/librthread
parent816d35a9b5a95da60ee98625f98532000a8687ec (diff)
handle the fourth vararg value to sem_open
ok zhuk and presumably fgsch who just sent me a similar diff
Diffstat (limited to 'lib/librthread')
-rw-r--r--lib/librthread/rthread_sem.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/librthread/rthread_sem.c b/lib/librthread/rthread_sem.c
index 57d8f764bbd..a6889f8f278 100644
--- a/lib/librthread/rthread_sem.c
+++ b/lib/librthread/rthread_sem.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_sem.c,v 1.13 2013/11/20 23:18:17 tedu Exp $ */
+/* $OpenBSD: rthread_sem.c,v 1.14 2013/11/21 17:43:57 tedu Exp $ */
/*
* Copyright (c) 2004,2005,2013 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -24,6 +24,7 @@
#include <errno.h>
#include <fcntl.h>
#include <sha2.h>
+#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -315,12 +316,22 @@ sem_open(const char *name, int oflag, ...)
int created = 0, fd, oerrno;
sem_t sem;
sem_t *semp = SEM_FAILED;
+ mode_t unusedmode;
+ unsigned value = 0;
if (oflag & ~(O_CREAT | O_EXCL)) {
errno = EINVAL;
return (semp);
}
+ if (oflag & O_CREAT) {
+ va_list ap;
+ va_start(ap, oflag);
+ unusedmode = va_arg(ap, mode_t);
+ value = va_arg(ap, unsigned);
+ va_end(ap);
+ }
+
makesempath(name, sempath, sizeof(sempath));
fd = open(sempath, O_RDWR | O_NOFOLLOW | oflag, 0600);
if (fd == -1)
@@ -363,8 +374,10 @@ sem_open(const char *name, int oflag, ...)
errno = oerrno;
return (semp);
}
- if (created)
+ if (created) {
sem->lock = _SPINLOCK_UNLOCKED_ASSIGN;
+ sem->value = value;
+ }
sem->shared = 1;
semp = malloc(sizeof(*semp));
if (!semp) {
@@ -382,7 +395,7 @@ int
sem_close(sem_t *semp)
{
sem_t sem;
-
+
if (!semp || !(sem = *semp) || !sem->shared) {
errno = EINVAL;
return (-1);