From d04fbb52b7d317f2487f27f18e182cfa89f0e9fe Mon Sep 17 00:00:00 2001 From: tnn Date: Wed, 4 May 2016 02:43:31 +0000 Subject: [PATCH] avoid using mktemp since it triggers warnings Bump rev. --- x11/libxshmfence/Makefile | 4 +-- 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 722cf76c9c3a..258aa18cd426 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 330c09b64ba0..666f7c1f57e6 100644 --- a/x11/libxshmfence/files/xshmfence_semaphore.c +++ b/x11/libxshmfence/files/xshmfence_semaphore.c @@ -25,13 +25,16 @@ #include "config.h" #endif -#include -#include #include +#include +#include +#include #include #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; + } +}