mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
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
This commit is contained in:
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user