summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2013-11-21 17:43:57 +0000
committertedu <tedu@openbsd.org>2013-11-21 17:43:57 +0000
commita5de71bfe3572dbf350f4f416e51c354fb34bf30 (patch)
tree9cb81e3ffc837a7336fe88e3292223b739a7c85d /lib
parentsplit kernel parts of the if.h into a separate header file if_var.h (diff)
downloadwireguard-openbsd-a5de71bfe3572dbf350f4f416e51c354fb34bf30.tar.xz
wireguard-openbsd-a5de71bfe3572dbf350f4f416e51c354fb34bf30.zip
handle the fourth vararg value to sem_open
ok zhuk and presumably fgsch who just sent me a similar diff
Diffstat (limited to 'lib')
-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);