From a3130729619d6b05f32244ea6fe1d83cc52ff749 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 4 Feb 2003 13:35:59 +0000 Subject: [PATCH] Added handling of FD_CLOEXEC flag --- src/control/control_hw.c | 10 ++++++++-- src/hwdep/hwdep_hw.c | 11 +++++++++-- src/rawmidi/rawmidi_hw.c | 6 ++++++ src/seq/seq_hw.c | 6 ++++++ src/timer/timer_hw.c | 15 +++++++++++---- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/control/control_hw.c b/src/control/control_hw.c index f62174d0..90d2e1ea 100644 --- a/src/control/control_hw.c +++ b/src/control/control_hw.c @@ -315,10 +315,16 @@ int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card, int mode) if ((fd = open(filename, O_RDWR)) < 0) return -errno; } - + if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { + SYSERR("fcntl FD_CLOEXEC failed"); + err = -errno; + close(fd); + return err; + } if (ioctl(fd, SNDRV_CTL_IOCTL_PVERSION, &ver) < 0) { + err = -errno; close(fd); - return -errno; + return err; } if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_CTL_VERSION_MAX)) { close(fd); diff --git a/src/hwdep/hwdep_hw.c b/src/hwdep/hwdep_hw.c index 57942648..24ec8689 100644 --- a/src/hwdep/hwdep_hw.c +++ b/src/hwdep/hwdep_hw.c @@ -105,7 +105,7 @@ static snd_hwdep_ops_t snd_hwdep_hw_ops = { int snd_hwdep_hw_open(snd_hwdep_t **handle, const char *name, int card, int device, int mode) { - int fd, ver; + int fd, ver, ret; char filename[32]; snd_hwdep_t *hwdep; assert(handle); @@ -120,9 +120,16 @@ int snd_hwdep_hw_open(snd_hwdep_t **handle, const char *name, int card, int devi if ((fd = open(filename, mode)) < 0) return -errno; } + if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { + SYSERR("fcntl FD_CLOEXEC failed"); + ret = -errno; + close(fd); + return ret; + } if (ioctl(fd, SNDRV_HWDEP_IOCTL_PVERSION, &ver) < 0) { + ret = -errno; close(fd); - return -errno; + return ret; } if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_HWDEP_VERSION_MAX)) { close(fd); diff --git a/src/rawmidi/rawmidi_hw.c b/src/rawmidi/rawmidi_hw.c index 0abe9092..f18b0042 100644 --- a/src/rawmidi/rawmidi_hw.c +++ b/src/rawmidi/rawmidi_hw.c @@ -228,6 +228,12 @@ int snd_rawmidi_hw_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp, return -errno; } } + if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { + SYSERR("fcntl FD_CLOEXEC failed"); + ret = -errno; + close(fd); + return ret; + } if (ioctl(fd, SNDRV_RAWMIDI_IOCTL_PVERSION, &ver) < 0) { ret = -errno; SYSERR("SNDRV_RAWMIDI_IOCTL_PVERSION failed"); diff --git a/src/seq/seq_hw.c b/src/seq/seq_hw.c index af667032..532395ef 100644 --- a/src/seq/seq_hw.c +++ b/src/seq/seq_hw.c @@ -447,6 +447,12 @@ int snd_seq_hw_open(snd_seq_t **handle, const char *name, int streams, int mode) return -errno; } } + if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { + SYSERR("fcntl FD_CLOEXEC failed"); + ret = -errno; + close(fd); + return ret; + } if (ioctl(fd, SNDRV_SEQ_IOCTL_PVERSION, &ver) < 0) { SYSERR("SNDRV_SEQ_IOCTL_PVERSION failed"); close(fd); diff --git a/src/timer/timer_hw.c b/src/timer/timer_hw.c index af90a39e..82d03cf1 100644 --- a/src/timer/timer_hw.c +++ b/src/timer/timer_hw.c @@ -161,7 +161,7 @@ static snd_timer_ops_t snd_timer_hw_ops = { int snd_timer_hw_open(snd_timer_t **handle, const char *name, int dev_class, int dev_sclass, int card, int device, int subdevice, int mode) { - int fd, ver, tmode; + int fd, ver, tmode, ret; snd_timer_t *tmr; struct sndrv_timer_select sel; @@ -172,9 +172,16 @@ int snd_timer_hw_open(snd_timer_t **handle, const char *name, int dev_class, int tmode |= O_NONBLOCK; if ((fd = open(SNDRV_FILE_TIMER, tmode)) < 0) return -errno; + if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { + SYSERR("fcntl FD_CLOEXEC failed"); + ret = -errno; + close(fd); + return ret; + } if (ioctl(fd, SNDRV_TIMER_IOCTL_PVERSION, &ver) < 0) { + ret = -errno; close(fd); - return -errno; + return ret; } if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_TIMER_VERSION_MAX)) { close(fd); @@ -187,9 +194,9 @@ int snd_timer_hw_open(snd_timer_t **handle, const char *name, int dev_class, int sel.id.device = device; sel.id.subdevice = subdevice; if (ioctl(fd, SNDRV_TIMER_IOCTL_SELECT, &sel) < 0) { - int err = -errno; + ret = -errno; close(fd); - return err; + return ret; } tmr = (snd_timer_t *) calloc(1, sizeof(snd_timer_t)); if (tmr == NULL) { -- 2.47.1