summaryrefslogtreecommitdiff
path: root/x11/libxshmfence/files
diff options
context:
space:
mode:
authortnn <tnn>2016-05-04 02:43:31 +0000
committertnn <tnn>2016-05-04 02:43:31 +0000
commit879465653e7a6a03d5371c99b129186ea4e3b0d4 (patch)
tree365f694264386045abbfb4d9acfe04bfe56bb28c /x11/libxshmfence/files
parentde0db1c16591bdaaf052926a0b290fa518b498d3 (diff)
downloadpkgsrc-879465653e7a6a03d5371c99b129186ea4e3b0d4.tar.gz
avoid using mktemp since it triggers warnings
Bump rev.
Diffstat (limited to 'x11/libxshmfence/files')
-rw-r--r--x11/libxshmfence/files/xshmfence_semaphore.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/x11/libxshmfence/files/xshmfence_semaphore.c b/x11/libxshmfence/files/xshmfence_semaphore.c
index 330c09b64ba..666f7c1f57e 100644
--- a/x11/libxshmfence/files/xshmfence_semaphore.c
+++ b/x11/libxshmfence/files/xshmfence_semaphore.c
@@ -25,13 +25,16 @@
#include "config.h"
#endif
-#include <fcntl.h>
-#include <string.h>
#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
#include <unistd.h>
#include "xshmfenceint.h"
+static sem_t *mksemtemp(char *, const char *);
+
#define LOCK() do {} while (sem_wait(f->lock) != 0)
#define UNLOCK() do { sem_post(f->lock); } while (0)
#define COND_WAIT() do {} while (sem_wait(f->cond) != 0)
@@ -155,16 +158,12 @@ xshmfence_init(int fd)
__sync_fetch_and_and(&f.triggered, 0);
__sync_fetch_and_and(&f.waiting, 0);
- strlcpy(f.lockname, "/xshmfl-XXXX", sizeof(f.lockname));
- mktemp(f.lockname);
- lock = sem_open(f.lockname, O_CREAT|O_EXCL, 0600, 1);
+ lock = mksemtemp(f.lockname, "/xshmfl-%i");
if (lock == SEM_FAILED) {
err(EXIT_FAILURE, "xshmfence_init: sem_open");
}
-
- strlcpy(f.condname, "/xshmfc-XXXX", sizeof(f.condname));
- mktemp(f.condname);
- cond = sem_open(f.condname, O_CREAT|O_EXCL, 0600, 0);
+
+ cond = mksemtemp(f.condname, "/xshmfl-%i");
if (cond == SEM_FAILED) {
err(EXIT_FAILURE, "xshmfence_init: sem_open");
}
@@ -221,3 +220,22 @@ xshmfence_close_semaphore(struct xshmfence *f)
sem_unlink(f->condname);
}
}
+
+static sem_t *
+mksemtemp(char *name, const char *template)
+{
+ sem_t *ret;
+ pid_t p;
+ p = getpid();
+ for(;;) {
+ sprintf(name, template, p);
+ ret = sem_open(name, O_CREAT|O_EXCL, 0600, 1);
+ if (ret == SEM_FAILED) {
+ if (errno == EEXIST) {
+ p++;
+ continue;
+ }
+ }
+ return ret;
+ }
+}