diff options
author | tnn <tnn@pkgsrc.org> | 2016-05-04 02:43:31 +0000 |
---|---|---|
committer | tnn <tnn@pkgsrc.org> | 2016-05-04 02:43:31 +0000 |
commit | 4e06490b7747662182bd8487ca372910d5164ed5 (patch) | |
tree | 365f694264386045abbfb4d9acfe04bfe56bb28c /x11 | |
parent | 25bba28a4272fffa54baa85fc2c6394eb4b07c9e (diff) | |
download | pkgsrc-4e06490b7747662182bd8487ca372910d5164ed5.tar.gz |
avoid using mktemp since it triggers warnings
Bump rev.
Diffstat (limited to 'x11')
-rw-r--r-- | x11/libxshmfence/Makefile | 4 | ||||
-rw-r--r-- | x11/libxshmfence/files/xshmfence_semaphore.c | 36 |
2 files changed, 29 insertions, 11 deletions
diff --git a/x11/libxshmfence/Makefile b/x11/libxshmfence/Makefile index 722cf76c9c3..258aa18cd42 100644 --- a/x11/libxshmfence/Makefile +++ b/x11/libxshmfence/Makefile @@ -1,7 +1,7 @@ -# $NetBSD: Makefile,v 1.4 2015/09/24 23:57:27 tnn Exp $ +# $NetBSD: Makefile,v 1.5 2016/05/04 02:43:31 tnn Exp $ DISTNAME= libxshmfence-1.2 -PKGREVISION= 2 +PKGREVISION= 3 CATEGORIES= x11 MASTER_SITES= http://xorg.freedesktop.org/archive/individual/lib/ EXTRACT_SUFX= .tar.bz2 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; + } +} |