mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-16 09:46:22 +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:
@@ -55,17 +55,8 @@ int ast_alertpipe_init(int alert_pipe[2])
|
||||
ast_log(LOG_WARNING, "Failed to create alert pipe: %s\n", strerror(errno));
|
||||
return -1;
|
||||
} else {
|
||||
int flags = fcntl(alert_pipe[0], F_GETFL);
|
||||
if (fcntl(alert_pipe[0], F_SETFL, flags | O_NONBLOCK) < 0) {
|
||||
ast_log(LOG_WARNING, "Failed to set non-blocking mode on alert pipe: %s\n",
|
||||
strerror(errno));
|
||||
ast_alertpipe_close(alert_pipe);
|
||||
return -1;
|
||||
}
|
||||
flags = fcntl(alert_pipe[1], F_GETFL);
|
||||
if (fcntl(alert_pipe[1], F_SETFL, flags | O_NONBLOCK) < 0) {
|
||||
ast_log(LOG_WARNING, "Failed to set non-blocking mode on alert pipe: %s\n",
|
||||
strerror(errno));
|
||||
if (ast_fd_set_flags(alert_pipe[0], O_NONBLOCK)
|
||||
|| ast_fd_set_flags(alert_pipe[1], O_NONBLOCK)) {
|
||||
ast_alertpipe_close(alert_pipe);
|
||||
return -1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user