summaryrefslogtreecommitdiffstats
path: root/lib/libsndio
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2014-08-15 03:51:40 +0000
committerguenther <guenther@openbsd.org>2014-08-15 03:51:40 +0000
commit0205f8e66ce8c2d9c439542953f237a17f23b194 (patch)
tree145b45ce27a69aca56b4834c4cd72e953fad812f /lib/libsndio
parentCreate a function which loads sgd in the mfi_iop_ops struct so that skinny (diff)
downloadwireguard-openbsd-0205f8e66ce8c2d9c439542953f237a17f23b194.tar.xz
wireguard-openbsd-0205f8e66ce8c2d9c439542953f237a17f23b194.zip
Use O_CLOEXEC wherever we open a file and then call fcntl(F_SETFD, FD_CLOEXEC)
on it, simplifying error checking, reducing system calls, and improving thread-safety for libraries. ok miod@
Diffstat (limited to 'lib/libsndio')
-rw-r--r--lib/libsndio/mio_rmidi.c11
-rw-r--r--lib/libsndio/sio_sun.c8
2 files changed, 4 insertions, 15 deletions
diff --git a/lib/libsndio/mio_rmidi.c b/lib/libsndio/mio_rmidi.c
index 79f78933f05..cb9d30cb997 100644
--- a/lib/libsndio/mio_rmidi.c
+++ b/lib/libsndio/mio_rmidi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mio_rmidi.c,v 1.13 2013/11/13 22:38:22 ratchov Exp $ */
+/* $OpenBSD: mio_rmidi.c,v 1.14 2014/08/15 03:51:40 guenther Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -77,21 +77,14 @@ _mio_rmidi_open(const char *str, unsigned int mode, int nbio)
flags = O_RDWR;
else
flags = (mode & MIO_OUT) ? O_WRONLY : O_RDONLY;
- while ((fd = open(path, flags | O_NONBLOCK)) < 0) {
+ while ((fd = open(path, flags | O_NONBLOCK | O_CLOEXEC)) < 0) {
if (errno == EINTR)
continue;
DPERROR(path);
goto bad_free;
}
- if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
- DPERROR("FD_CLOEXEC");
- goto bad_close;
- }
hdl->fd = fd;
return (struct mio_hdl *)hdl;
- bad_close:
- while (close(hdl->fd) < 0 && errno == EINTR)
- ; /* retry */
bad_free:
free(hdl);
return NULL;
diff --git a/lib/libsndio/sio_sun.c b/lib/libsndio/sio_sun.c
index 948302eaa96..db2b1ce39c9 100644
--- a/lib/libsndio/sio_sun.c
+++ b/lib/libsndio/sio_sun.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sio_sun.c,v 1.11 2014/03/05 20:40:49 ratchov Exp $ */
+/* $OpenBSD: sio_sun.c,v 1.12 2014/08/15 03:51:40 guenther Exp $ */
/*
* Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
*
@@ -363,16 +363,12 @@ _sio_sun_open(const char *str, unsigned int mode, int nbio)
else
flags = (mode & SIO_PLAY) ? O_WRONLY : O_RDONLY;
- while ((fd = open(path, flags | O_NONBLOCK)) < 0) {
+ while ((fd = open(path, flags | O_NONBLOCK | O_CLOEXEC)) < 0) {
if (errno == EINTR)
continue;
DPERROR(path);
goto bad_free;
}
- if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
- DPERROR("FD_CLOEXEC");
- goto bad_close;
- }
/*
* pause the device