summaryrefslogtreecommitdiff
path: root/channels
diff options
context:
space:
mode:
authorSean Bright <sean.bright@gmail.com>2017-12-07 10:52:39 -0500
committerSean Bright <sean.bright@gmail.com>2017-12-08 14:27:50 -0500
commitf726f119740373a01bef6e26e5c1f02dd277033f (patch)
treec86e6167c79cf6289258f423ec16341932ed9e69 /channels
parent54a86779a3d1cc2a1c859d76180f155865713bb5 (diff)
utils: Add convenience function for setting fd flags
There are many places in the code base where we ignore the return value of fcntl() when getting/setting file descriptior flags. This patch introduces a convenience function that allows setting or clearing file descriptor flags and will also log an error on failure for later analysis. Change-Id: I8b81901e1b1bd537ca632567cdb408931c6eded7
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_phone.c4
-rw-r--r--channels/chan_sip.c9
-rw-r--r--channels/vgrabbers.c8
3 files changed, 4 insertions, 17 deletions
diff --git a/channels/chan_phone.c b/channels/chan_phone.c
index b418b282b..67b1e1242 100644
--- a/channels/chan_phone.c
+++ b/channels/chan_phone.c
@@ -1193,7 +1193,6 @@ static struct phone_pvt *mkif(const char *iface, int mode, int txgain, int rxgai
{
/* Make a phone_pvt structure for this interface */
struct phone_pvt *tmp;
- int flags;
tmp = ast_calloc(1, sizeof(*tmp));
if (tmp) {
@@ -1226,8 +1225,7 @@ static struct phone_pvt *mkif(const char *iface, int mode, int txgain, int rxgai
ioctl(tmp->fd, PHONE_VAD, tmp->silencesupression);
#endif
tmp->mode = mode;
- flags = fcntl(tmp->fd, F_GETFL);
- fcntl(tmp->fd, F_SETFL, flags | O_NONBLOCK);
+ ast_fd_set_flags(tmp->fd, O_NONBLOCK);
tmp->owner = NULL;
ao2_cleanup(tmp->lastformat);
tmp->lastformat = NULL;
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 559e5c05b..b8cc7bf76 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -2948,14 +2948,7 @@ static void *_sip_tcp_helper_thread(struct ast_tcptls_session_instance *tcptls_s
goto cleanup;
}
- if ((flags = fcntl(tcptls_session->fd, F_GETFL)) == -1) {
- ast_log(LOG_ERROR, "error setting socket to non blocking mode, fcntl() failed: %s\n", strerror(errno));
- goto cleanup;
- }
-
- flags |= O_NONBLOCK;
- if (fcntl(tcptls_session->fd, F_SETFL, flags) == -1) {
- ast_log(LOG_ERROR, "error setting socket to non blocking mode, fcntl() failed: %s\n", strerror(errno));
+ if (ast_fd_set_flags(tcptls_session->fd, O_NONBLOCK)) {
goto cleanup;
}
diff --git a/channels/vgrabbers.c b/channels/vgrabbers.c
index 45dced4e1..3deb32fd1 100644
--- a/channels/vgrabbers.c
+++ b/channels/vgrabbers.c
@@ -227,12 +227,8 @@ static void *grab_v4l1_open(const char *dev, struct fbuf_t *geom, int fps)
v->b = *geom;
b = &v->b; /* shorthand */
- i = fcntl(fd, F_GETFL);
- if (-1 == fcntl(fd, F_SETFL, i | O_NONBLOCK)) {
- /* non fatal, just emit a warning */
- ast_log(LOG_WARNING, "error F_SETFL for %s [%s]\n",
- dev, strerror(errno));
- }
+ ast_fd_set_flags(fd, O_NONBLOCK);
+
/* set format for the camera.
* In principle we could retry with a different format if the
* one we are asking for is not supported.