mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-12-18 08:56:42 -05:00
Added handling of FD_CLOEXEC flag
This commit is contained in:
parent
e5b227961e
commit
a313072961
5 changed files with 43 additions and 11 deletions
|
|
@ -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)
|
if ((fd = open(filename, O_RDWR)) < 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
|
||||||
if (ioctl(fd, SNDRV_CTL_IOCTL_PVERSION, &ver) < 0) {
|
SYSERR("fcntl FD_CLOEXEC failed");
|
||||||
|
err = -errno;
|
||||||
close(fd);
|
close(fd);
|
||||||
return -errno;
|
return err;
|
||||||
|
}
|
||||||
|
if (ioctl(fd, SNDRV_CTL_IOCTL_PVERSION, &ver) < 0) {
|
||||||
|
err = -errno;
|
||||||
|
close(fd);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_CTL_VERSION_MAX)) {
|
if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_CTL_VERSION_MAX)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
||||||
|
|
@ -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 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];
|
char filename[32];
|
||||||
snd_hwdep_t *hwdep;
|
snd_hwdep_t *hwdep;
|
||||||
assert(handle);
|
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)
|
if ((fd = open(filename, mode)) < 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
if (ioctl(fd, SNDRV_HWDEP_IOCTL_PVERSION, &ver) < 0) {
|
if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
|
||||||
|
SYSERR("fcntl FD_CLOEXEC failed");
|
||||||
|
ret = -errno;
|
||||||
close(fd);
|
close(fd);
|
||||||
return -errno;
|
return ret;
|
||||||
|
}
|
||||||
|
if (ioctl(fd, SNDRV_HWDEP_IOCTL_PVERSION, &ver) < 0) {
|
||||||
|
ret = -errno;
|
||||||
|
close(fd);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_HWDEP_VERSION_MAX)) {
|
if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_HWDEP_VERSION_MAX)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,12 @@ int snd_rawmidi_hw_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
|
||||||
return -errno;
|
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) {
|
if (ioctl(fd, SNDRV_RAWMIDI_IOCTL_PVERSION, &ver) < 0) {
|
||||||
ret = -errno;
|
ret = -errno;
|
||||||
SYSERR("SNDRV_RAWMIDI_IOCTL_PVERSION failed");
|
SYSERR("SNDRV_RAWMIDI_IOCTL_PVERSION failed");
|
||||||
|
|
|
||||||
|
|
@ -447,6 +447,12 @@ int snd_seq_hw_open(snd_seq_t **handle, const char *name, int streams, int mode)
|
||||||
return -errno;
|
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) {
|
if (ioctl(fd, SNDRV_SEQ_IOCTL_PVERSION, &ver) < 0) {
|
||||||
SYSERR("SNDRV_SEQ_IOCTL_PVERSION failed");
|
SYSERR("SNDRV_SEQ_IOCTL_PVERSION failed");
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
|
||||||
|
|
@ -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 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;
|
snd_timer_t *tmr;
|
||||||
struct sndrv_timer_select sel;
|
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;
|
tmode |= O_NONBLOCK;
|
||||||
if ((fd = open(SNDRV_FILE_TIMER, tmode)) < 0)
|
if ((fd = open(SNDRV_FILE_TIMER, tmode)) < 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
if (ioctl(fd, SNDRV_TIMER_IOCTL_PVERSION, &ver) < 0) {
|
if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
|
||||||
|
SYSERR("fcntl FD_CLOEXEC failed");
|
||||||
|
ret = -errno;
|
||||||
close(fd);
|
close(fd);
|
||||||
return -errno;
|
return ret;
|
||||||
|
}
|
||||||
|
if (ioctl(fd, SNDRV_TIMER_IOCTL_PVERSION, &ver) < 0) {
|
||||||
|
ret = -errno;
|
||||||
|
close(fd);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_TIMER_VERSION_MAX)) {
|
if (SNDRV_PROTOCOL_INCOMPATIBLE(ver, SNDRV_TIMER_VERSION_MAX)) {
|
||||||
close(fd);
|
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.device = device;
|
||||||
sel.id.subdevice = subdevice;
|
sel.id.subdevice = subdevice;
|
||||||
if (ioctl(fd, SNDRV_TIMER_IOCTL_SELECT, &sel) < 0) {
|
if (ioctl(fd, SNDRV_TIMER_IOCTL_SELECT, &sel) < 0) {
|
||||||
int err = -errno;
|
ret = -errno;
|
||||||
close(fd);
|
close(fd);
|
||||||
return err;
|
return ret;
|
||||||
}
|
}
|
||||||
tmr = (snd_timer_t *) calloc(1, sizeof(snd_timer_t));
|
tmr = (snd_timer_t *) calloc(1, sizeof(snd_timer_t));
|
||||||
if (tmr == NULL) {
|
if (tmr == NULL) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue