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:
Sean Bright
2017-12-07 10:52:39 -05:00
parent 54a86779a3
commit f726f11974
19 changed files with 103 additions and 104 deletions

View File

@@ -2048,7 +2048,7 @@ static int handle_connection(const char *agiurl, const struct ast_sockaddr addr,
FastAGI defaults to port 4573 */
static enum agi_result launch_netscript(char *agiurl, char *argv[], int *fds)
{
int s = 0, flags;
int s = 0;
char *host, *script;
int num_addrs = 0, i = 0;
struct ast_sockaddr *addrs;
@@ -2078,14 +2078,7 @@ static enum agi_result launch_netscript(char *agiurl, char *argv[], int *fds)
continue;
}
if ((flags = fcntl(s, F_GETFL)) < 0) {
ast_log(LOG_WARNING, "fcntl(F_GETFL) failed: %s\n", strerror(errno));
close(s);
continue;
}
if (fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0) {
ast_log(LOG_WARNING, "fnctl(F_SETFL) failed: %s\n", strerror(errno));
if (ast_fd_set_flags(s, O_NONBLOCK)) {
close(s);
continue;
}
@@ -2251,9 +2244,8 @@ static enum agi_result launch_script(struct ast_channel *chan, char *script, int
close(toast[1]);
return AGI_RESULT_FAILURE;
}
res = fcntl(audio[1], F_GETFL);
if (res > -1)
res = fcntl(audio[1], F_SETFL, res | O_NONBLOCK);
res = ast_fd_set_flags(audio[1], O_NONBLOCK);
if (res < 0) {
ast_log(LOG_WARNING, "unable to set audio pipe parameters: %s\n", strerror(errno));
close(fromast[0]);