]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Added handling of FD_CLOEXEC flag
authorJaroslav Kysela <perex@perex.cz>
Tue, 4 Feb 2003 13:35:59 +0000 (13:35 +0000)
committerJaroslav Kysela <perex@perex.cz>
Tue, 4 Feb 2003 13:35:59 +0000 (13:35 +0000)
src/control/control_hw.c
src/hwdep/hwdep_hw.c
src/rawmidi/rawmidi_hw.c
src/seq/seq_hw.c
src/timer/timer_hw.c

index f62174d021dc3084b7affebbc32c6c547b9a3005..90d2e1ea0e246d9d6e31864f249be65439525f9f 100644 (file)
@@ -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);
index 5794264836fa208f707a92fa4462c7b8f9719ca7..24ec8689352ebcfa82a7b25dcbf6a3cfec5c96dd 100644 (file)
@@ -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);
index 0abe9092d926d5fe6790dbe5b43cfad1167b6fb4..f18b0042dbe4f26d4325656be87fbbd1ee760995 100644 (file)
@@ -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");
index af66703226efb865d0d761f6aeef367f12b32095..532395ef5910cce4c8edee19c6c5f082bfb632f6 100644 (file)
@@ -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);
index af90a39e573c51f9690d4d340b3cec173eb43982..82d03cf19b1af9d00df5bc94205c2d63a279bec2 100644 (file)
@@ -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) {