diff options
-rw-r--r-- | apps/app_ices.c | 4 | ||||
-rw-r--r-- | channels/chan_phone.c | 4 | ||||
-rw-r--r-- | channels/vgrabbers.c | 8 | ||||
-rw-r--r-- | codecs/codec_dahdi.c | 7 | ||||
-rw-r--r-- | funcs/func_cdr.c | 127 | ||||
-rw-r--r-- | funcs/func_channel.c | 19 | ||||
-rw-r--r-- | include/asterisk/utils.h | 40 | ||||
-rw-r--r-- | main/alertpipe.c | 13 | ||||
-rw-r--r-- | main/asterisk.c | 4 | ||||
-rw-r--r-- | main/iostream.c | 2 | ||||
-rw-r--r-- | main/tcptls.c | 13 | ||||
-rw-r--r-- | main/udptl.c | 4 | ||||
-rw-r--r-- | main/utils.c | 34 | ||||
-rw-r--r-- | res/res_agi.c | 16 | ||||
-rw-r--r-- | res/res_http_websocket.c | 10 | ||||
-rw-r--r-- | res/res_musiconhold.c | 7 | ||||
-rw-r--r-- | res/res_pjsip/pjsip_cli.c | 24 | ||||
-rw-r--r-- | res/res_pjsip/pjsip_configuration.c | 17 | ||||
-rw-r--r-- | res/res_pktccops.c | 5 | ||||
-rw-r--r-- | res/res_rtp_asterisk.c | 3 | ||||
-rw-r--r-- | res/res_speech.c | 2 | ||||
-rw-r--r-- | res/res_stasis.c | 4 | ||||
-rw-r--r-- | res/res_timing_pthread.c | 4 |
23 files changed, 214 insertions, 157 deletions
diff --git a/apps/app_ices.c b/apps/app_ices.c index 4ca4b67c5..1194384d4 100644 --- a/apps/app_ices.c +++ b/apps/app_ices.c @@ -113,7 +113,6 @@ static int ices_exec(struct ast_channel *chan, const char *data) int fds[2]; int ms = -1; int pid = -1; - int flags; struct ast_format *oreadformat; struct ast_frame *f; char filename[256]=""; @@ -128,8 +127,7 @@ static int ices_exec(struct ast_channel *chan, const char *data) ast_log(LOG_WARNING, "Unable to create pipe\n"); return -1; } - flags = fcntl(fds[1], F_GETFL); - fcntl(fds[1], F_SETFL, flags | O_NONBLOCK); + ast_fd_set_flags(fds[1], O_NONBLOCK); ast_stopstream(chan); diff --git a/channels/chan_phone.c b/channels/chan_phone.c index 76891ac98..832f28b49 100644 --- a/channels/chan_phone.c +++ b/channels/chan_phone.c @@ -1191,7 +1191,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) { @@ -1224,8 +1223,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/vgrabbers.c b/channels/vgrabbers.c index 25817407e..169e59c5d 100644 --- a/channels/vgrabbers.c +++ b/channels/vgrabbers.c @@ -226,12 +226,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. diff --git a/codecs/codec_dahdi.c b/codecs/codec_dahdi.c index efb016853..941bb1fb2 100644 --- a/codecs/codec_dahdi.c +++ b/codecs/codec_dahdi.c @@ -613,7 +613,6 @@ static int dahdi_translate(struct ast_trans_pvt *pvt, uint32_t dst_dahdi_fmt, ui /* Request translation through zap if possible */ int fd; struct codec_dahdi_pvt *dahdip = pvt->pvt; - int flags; int tried_once = 0; const char *dev_filename = "/dev/dahdi/transcode"; @@ -659,11 +658,7 @@ retry: return -1; } - flags = fcntl(fd, F_GETFL); - if (flags > - 1) { - if (fcntl(fd, F_SETFL, flags | O_NONBLOCK)) - ast_log(LOG_WARNING, "Could not set non-block mode!\n"); - } + ast_fd_set_flags(fd, O_NONBLOCK); dahdip->fd = fd; diff --git a/funcs/func_cdr.c b/funcs/func_cdr.c index 573431237..2dd9f1578 100644 --- a/funcs/func_cdr.c +++ b/funcs/func_cdr.c @@ -356,7 +356,7 @@ static void cdr_read_callback(void *data, struct stasis_subscription *sub, struc static void cdr_write_callback(void *data, struct stasis_subscription *sub, struct stasis_message *message) { - struct cdr_func_payload *payload = stasis_message_data(message); + struct cdr_func_payload *payload; struct ast_flags flags = { 0 }; AST_DECLARE_APP_ARGS(args, AST_APP_ARG(variable); @@ -367,21 +367,17 @@ static void cdr_write_callback(void *data, struct stasis_subscription *sub, stru if (cdr_write_message_type() != stasis_message_type(message)) { return; } - + payload = stasis_message_data(message); if (!payload) { return; } - - if (ast_strlen_zero(payload->arguments)) { - ast_log(AST_LOG_WARNING, "%s requires a variable (%s(variable)=value)\n)", - payload->cmd, payload->cmd); - return; - } - if (!payload->value) { - ast_log(AST_LOG_WARNING, "%s requires a value (%s(variable)=value)\n)", - payload->cmd, payload->cmd); + if (ast_strlen_zero(payload->arguments) + || !payload->value) { + /* Sanity check. cdr_write() could never send these bad messages */ + ast_assert(0); return; } + parse = ast_strdupa(payload->arguments); AST_STANDARD_APP_ARGS(args, parse); @@ -389,32 +385,16 @@ static void cdr_write_callback(void *data, struct stasis_subscription *sub, stru ast_app_parse_options(cdr_func_options, &flags, NULL, args.options); } - if (!strcasecmp(args.variable, "accountcode")) { - ast_log(AST_LOG_WARNING, "Using the CDR function to set 'accountcode' is deprecated. Please use the CHANNEL function instead.\n"); - ast_channel_lock(payload->chan); - ast_channel_accountcode_set(payload->chan, payload->value); - ast_channel_unlock(payload->chan); - } else if (!strcasecmp(args.variable, "peeraccount")) { - ast_log(AST_LOG_WARNING, "The 'peeraccount' setting is not supported. Please set the 'accountcode' on the appropriate channel using the CHANNEL function.\n"); - } else if (!strcasecmp(args.variable, "userfield")) { + /* These are already handled by cdr_write() */ + ast_assert(strcasecmp(args.variable, "accountcode") + && strcasecmp(args.variable, "peeraccount") + && strcasecmp(args.variable, "amaflags")); + + if (!strcasecmp(args.variable, "userfield")) { ast_cdr_setuserfield(ast_channel_name(payload->chan), payload->value); - } else if (!strcasecmp(args.variable, "amaflags")) { - ast_log(AST_LOG_WARNING, "Using the CDR function to set 'amaflags' is deprecated. Please use the CHANNEL function instead.\n"); - if (isdigit(*payload->value)) { - int amaflags; - sscanf(payload->value, "%30d", &amaflags); - ast_channel_lock(payload->chan); - ast_channel_amaflags_set(payload->chan, amaflags); - ast_channel_unlock(payload->chan); - } else { - ast_channel_lock(payload->chan); - ast_channel_amaflags_set(payload->chan, ast_channel_string2amaflag(payload->value)); - ast_channel_unlock(payload->chan); - } } else { ast_cdr_setvar(ast_channel_name(payload->chan), args.variable, payload->value); } - return; } static void cdr_prop_write_callback(void *data, struct stasis_subscription *sub, struct stasis_message *message) @@ -523,27 +503,70 @@ static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse, return 0; } -static int cdr_write(struct ast_channel *chan, const char *cmd, char *parse, - const char *value) +static int cdr_write(struct ast_channel *chan, const char *cmd, char *arguments, + const char *value) { - RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup); - RAII_VAR(struct cdr_func_payload *, payload, NULL, ao2_cleanup); - RAII_VAR(struct stasis_message_router *, router, - ast_cdr_message_router(), ao2_cleanup); + struct stasis_message *message; + struct cdr_func_payload *payload; + struct stasis_message_router *router; + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(variable); + AST_APP_ARG(options); + ); + char *parse; if (!chan) { ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); return -1; } - - if (!router) { - ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: no message router\n", - ast_channel_name(chan)); + if (ast_strlen_zero(arguments)) { + ast_log(LOG_WARNING, "%s requires a variable (%s(variable)=value)\n)", + cmd, cmd); + return -1; + } + if (!value) { + ast_log(LOG_WARNING, "%s requires a value (%s(variable)=value)\n)", + cmd, cmd); return -1; } + parse = ast_strdupa(arguments); + AST_STANDARD_APP_ARGS(args, parse); + + /* These CDR variables are no longer supported or set directly on the channel */ + if (!strcasecmp(args.variable, "accountcode")) { + ast_log(LOG_WARNING, "Using the %s function to set 'accountcode' is deprecated. Please use the CHANNEL function instead.\n", + cmd); + ast_channel_lock(chan); + ast_channel_accountcode_set(chan, value); + ast_channel_unlock(chan); + return 0; + } + if (!strcasecmp(args.variable, "amaflags")) { + int amaflags; + + ast_log(LOG_WARNING, "Using the %s function to set 'amaflags' is deprecated. Please use the CHANNEL function instead.\n", + cmd); + if (isdigit(*value)) { + if (sscanf(value, "%30d", &amaflags) != 1) { + amaflags = AST_AMA_NONE; + } + } else { + amaflags = ast_channel_string2amaflag(value); + } + ast_channel_lock(chan); + ast_channel_amaflags_set(chan, amaflags); + ast_channel_unlock(chan); + return 0; + } + if (!strcasecmp(args.variable, "peeraccount")) { + ast_log(LOG_WARNING, "The 'peeraccount' setting is not supported. Please set the 'accountcode' on the appropriate channel using the CHANNEL function.\n"); + return 0; + } + + /* The remaining CDR variables are handled by CDR processing code */ if (!cdr_write_message_type()) { - ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: message type not available\n", + ast_log(LOG_WARNING, "Failed to manipulate CDR for channel %s: message type not available\n", ast_channel_name(chan)); return -1; } @@ -554,16 +577,26 @@ static int cdr_write(struct ast_channel *chan, const char *cmd, char *parse, } payload->chan = chan; payload->cmd = cmd; - payload->arguments = parse; + payload->arguments = arguments; payload->value = value; message = stasis_message_create(cdr_write_message_type(), payload); + ao2_ref(payload, -1); if (!message) { - ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: unable to create message\n", + ast_log(LOG_WARNING, "Failed to manipulate CDR for channel %s: unable to create message\n", ast_channel_name(chan)); return -1; } + router = ast_cdr_message_router(); + if (!router) { + ast_log(LOG_WARNING, "Failed to manipulate CDR for channel %s: no message router\n", + ast_channel_name(chan)); + ao2_ref(message, -1); + return -1; + } stasis_message_router_publish_sync(router, message); + ao2_ref(router, -1); + ao2_ref(message, -1); return 0; } @@ -586,7 +619,7 @@ static int cdr_prop_write(struct ast_channel *chan, const char *cmd, char *parse return -1; } - if (!cdr_write_message_type()) { + if (!cdr_prop_write_message_type()) { ast_log(AST_LOG_WARNING, "Failed to manipulate CDR for channel %s: message type not available\n", ast_channel_name(chan)); return -1; diff --git a/funcs/func_channel.c b/funcs/func_channel.c index eb3ceddb4..b72cb141e 100644 --- a/funcs/func_channel.c +++ b/funcs/func_channel.c @@ -495,18 +495,17 @@ static int func_channel_write_real(struct ast_channel *chan, const char *functio ast_bridge_set_after_go_on(chan, ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan), value); } } else if (!strcasecmp(data, "amaflags")) { - ast_channel_lock(chan); + int amaflags; + if (isdigit(*value)) { - int amaflags; - sscanf(value, "%30d", &amaflags); - ast_channel_amaflags_set(chan, amaflags); - } else if (!strcasecmp(value,"OMIT")){ - ast_channel_amaflags_set(chan, 1); - } else if (!strcasecmp(value,"BILLING")){ - ast_channel_amaflags_set(chan, 2); - } else if (!strcasecmp(value,"DOCUMENTATION")){ - ast_channel_amaflags_set(chan, 3); + if (sscanf(value, "%30d", &amaflags) != 1) { + amaflags = AST_AMA_NONE; + } + } else { + amaflags = ast_channel_string2amaflag(value); } + ast_channel_lock(chan); + ast_channel_amaflags_set(chan, amaflags); ast_channel_unlock(chan); } else if (!strcasecmp(data, "peeraccount")) locked_string_field_set(chan, peeraccount, value); diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h index 0a12b1d8a..c6c34074e 100644 --- a/include/asterisk/utils.h +++ b/include/asterisk/utils.h @@ -1141,4 +1141,44 @@ int ast_compare_versions(const char *version1, const char *version2); */ int ast_check_ipv6(void); +enum ast_fd_flag_operation { + AST_FD_FLAG_SET, + AST_FD_FLAG_CLEAR, +}; + +/* + * \brief Set flags on the given file descriptor + * \since 13.19 + * + * If getting or setting flags of the given file descriptor fails, logs an + * error message. + * + * \param fd File descriptor to set flags on + * \param flags The flag(s) to set + * + * \return -1 on error + * \return 0 if successful + */ +#define ast_fd_set_flags(fd, flags) \ + __ast_fd_set_flags((fd), (flags), AST_FD_FLAG_SET, __FILE__, __LINE__, __PRETTY_FUNCTION__) + +/* + * \brief Clear flags on the given file descriptor + * \since 13.19 + * + * If getting or setting flags of the given file descriptor fails, logs an + * error message. + * + * \param fd File descriptor to clear flags on + * \param flags The flag(s) to clear + * + * \return -1 on error + * \return 0 if successful + */ +#define ast_fd_clear_flags(fd, flags) \ + __ast_fd_set_flags((fd), (flags), AST_FD_FLAG_CLEAR, __FILE__, __LINE__, __PRETTY_FUNCTION__) + +int __ast_fd_set_flags(int fd, int flags, enum ast_fd_flag_operation op, + const char *file, int lineno, const char *function); + #endif /* _ASTERISK_UTILS_H */ diff --git a/main/alertpipe.c b/main/alertpipe.c index fa6ec7bcc..7932a7346 100644 --- a/main/alertpipe.c +++ b/main/alertpipe.c @@ -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; } diff --git a/main/asterisk.c b/main/asterisk.c index faac569c0..187a8ad6b 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -1569,7 +1569,6 @@ static void *listener(void *unused) int s; socklen_t len; int x; - int flags; struct pollfd fds[1]; for (;;) { if (ast_socket < 0) @@ -1607,8 +1606,7 @@ static void *listener(void *unused) close(s); break; } - flags = fcntl(consoles[x].p[1], F_GETFL); - fcntl(consoles[x].p[1], F_SETFL, flags | O_NONBLOCK); + ast_fd_set_flags(consoles[x].p[1], O_NONBLOCK); consoles[x].mute = 1; /* Default is muted, we will un-mute if necessary */ /* Default uid and gid to -2, so then in cli.c/cli_has_permissions() we will be able to know if the user didn't send the credentials. */ diff --git a/main/iostream.c b/main/iostream.c index d91863319..aaa74fae1 100644 --- a/main/iostream.c +++ b/main/iostream.c @@ -77,7 +77,7 @@ int ast_iostream_get_fd(struct ast_iostream *stream) void ast_iostream_nonblock(struct ast_iostream *stream) { - fcntl(stream->fd, F_SETFL, fcntl(stream->fd, F_GETFL) | O_NONBLOCK); + ast_fd_set_flags(stream->fd, O_NONBLOCK); } SSL *ast_iostream_get_ssl(struct ast_iostream *stream) diff --git a/main/tcptls.c b/main/tcptls.c index a6d0538af..02a2af5c6 100644 --- a/main/tcptls.c +++ b/main/tcptls.c @@ -223,7 +223,7 @@ void *ast_tcptls_server_root(void *data) pthread_t launched; for (;;) { - int i, flags; + int i; if (desc->periodic_fn) { desc->periodic_fn(desc); @@ -261,8 +261,7 @@ void *ast_tcptls_server_root(void *data) close(fd); continue; } - flags = fcntl(fd, F_GETFL); - fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); + ast_fd_clear_flags(fd, O_NONBLOCK); tcptls_session->stream = ast_iostream_from_fd(&fd); if (!tcptls_session->stream) { @@ -514,7 +513,6 @@ void ast_ssl_teardown(struct ast_tls_config *cfg) struct ast_tcptls_session_instance *ast_tcptls_client_start(struct ast_tcptls_session_instance *tcptls_session) { struct ast_tcptls_session_args *desc; - int flags; if (!(desc = tcptls_session->parent)) { goto client_start_error; @@ -528,8 +526,7 @@ struct ast_tcptls_session_instance *ast_tcptls_client_start(struct ast_tcptls_se goto client_start_error; } - flags = fcntl(desc->accept_fd, F_GETFL); - fcntl(desc->accept_fd, F_SETFL, flags & ~O_NONBLOCK); + ast_fd_clear_flags(desc->accept_fd, O_NONBLOCK); if (desc->tls_cfg) { desc->tls_cfg->enabled = 1; @@ -621,7 +618,6 @@ error: void ast_tcptls_server_start(struct ast_tcptls_session_args *desc) { - int flags; int x = 1; int tls_changed = 0; int sd_socket; @@ -740,8 +736,7 @@ void ast_tcptls_server_start(struct ast_tcptls_session_args *desc) } systemd_socket_activation: - flags = fcntl(desc->accept_fd, F_GETFL); - fcntl(desc->accept_fd, F_SETFL, flags | O_NONBLOCK); + ast_fd_set_flags(desc->accept_fd, O_NONBLOCK); if (ast_pthread_create_background(&desc->master, NULL, desc->accept_fn, desc)) { ast_log(LOG_ERROR, "Unable to launch thread for %s on %s: %s\n", desc->name, diff --git a/main/udptl.c b/main/udptl.c index 853e43c44..d982f6bcb 100644 --- a/main/udptl.c +++ b/main/udptl.c @@ -1012,7 +1012,6 @@ struct ast_udptl *ast_udptl_new_with_bindaddr(struct ast_sched_context *sched, s int x; int startplace; int i; - long int flags; RAII_VAR(struct udptl_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup); if (!cfg || !cfg->general) { @@ -1043,8 +1042,7 @@ struct ast_udptl *ast_udptl_new_with_bindaddr(struct ast_sched_context *sched, s ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno)); return NULL; } - flags = fcntl(udptl->fd, F_GETFL); - fcntl(udptl->fd, F_SETFL, flags | O_NONBLOCK); + ast_fd_set_flags(udptl->fd, O_NONBLOCK); #ifdef SO_NO_CHECK if (cfg->general->nochecksums) diff --git a/main/utils.c b/main/utils.c index dd7176295..a070da49f 100644 --- a/main/utils.c +++ b/main/utils.c @@ -2758,3 +2758,37 @@ int ast_compare_versions(const char *version1, const char *version2) } return extra[0] - extra[1]; } + +int __ast_fd_set_flags(int fd, int flags, enum ast_fd_flag_operation op, + const char *file, int lineno, const char *function) +{ + int f; + + f = fcntl(fd, F_GETFL); + if (f == -1) { + ast_log(__LOG_ERROR, file, lineno, function, + "Failed to get fcntl() flags for file descriptor: %s\n", strerror(errno)); + return -1; + } + + switch (op) { + case AST_FD_FLAG_SET: + f |= flags; + break; + case AST_FD_FLAG_CLEAR: + f &= ~flags; + break; + default: + ast_assert(0); + break; + } + + f = fcntl(fd, F_SETFL, f); + if (f == -1) { + ast_log(__LOG_ERROR, file, lineno, function, + "Failed to set fcntl() flags for file descriptor: %s\n", strerror(errno)); + return -1; + } + + return 0; +} diff --git a/res/res_agi.c b/res/res_agi.c index 13af48f49..85914c018 100644 --- a/res/res_agi.c +++ b/res/res_agi.c @@ -2046,7 +2046,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; @@ -2076,14 +2076,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; } @@ -2249,9 +2242,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]); diff --git a/res/res_http_websocket.c b/res/res_http_websocket.c index c1f9a29d6..baaa40fd9 100644 --- a/res/res_http_websocket.c +++ b/res/res_http_websocket.c @@ -951,17 +951,11 @@ static struct ast_http_uri websocketuri = { /*! \brief Simple echo implementation which echoes received text and binary frames */ static void websocket_echo_callback(struct ast_websocket *session, struct ast_variable *parameters, struct ast_variable *headers) { - int flags, res; + int res; ast_debug(1, "Entering WebSocket echo loop\n"); - if ((flags = fcntl(ast_websocket_fd(session), F_GETFL)) == -1) { - goto end; - } - - flags |= O_NONBLOCK; - - if (fcntl(ast_websocket_fd(session), F_SETFL, flags) == -1) { + if (ast_fd_set_flags(ast_websocket_fd(session), O_NONBLOCK)) { goto end; } diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index e4bb7a2d9..ef1b81c2a 100644 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -922,7 +922,6 @@ static struct mohclass *_get_mohbyname(const char *name, int warn, int flags, co static struct mohdata *mohalloc(struct mohclass *cl) { struct mohdata *moh; - long flags; if (!(moh = ast_calloc(1, sizeof(*moh)))) return NULL; @@ -934,10 +933,8 @@ static struct mohdata *mohalloc(struct mohclass *cl) } /* Make entirely non-blocking */ - flags = fcntl(moh->pipe[0], F_GETFL); - fcntl(moh->pipe[0], F_SETFL, flags | O_NONBLOCK); - flags = fcntl(moh->pipe[1], F_GETFL); - fcntl(moh->pipe[1], F_SETFL, flags | O_NONBLOCK); + ast_fd_set_flags(moh->pipe[0], O_NONBLOCK); + ast_fd_set_flags(moh->pipe[1], O_NONBLOCK); moh->f.frametype = AST_FRAME_VOICE; moh->f.subclass.format = cl->format; diff --git a/res/res_pjsip/pjsip_cli.c b/res/res_pjsip/pjsip_cli.c index 56ec191ed..4544a1717 100644 --- a/res/res_pjsip/pjsip_cli.c +++ b/res/res_pjsip/pjsip_cli.c @@ -82,31 +82,22 @@ int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags) return 0; } -static char *complete_show_sorcery_object(struct ao2_container *container, +static void complete_show_sorcery_object(struct ao2_container *container, struct ast_sip_cli_formatter_entry *formatter_entry, - const char *word, int state) + const char *word) { - char *result = NULL; - int wordlen = strlen(word); - int which = 0; - - struct ao2_iterator i = ao2_iterator_init(container, 0); + size_t wordlen = strlen(word); void *object; + struct ao2_iterator i = ao2_iterator_init(container, 0); while ((object = ao2_t_iterator_next(&i, "iterate thru endpoints table"))) { const char *id = formatter_entry->get_id(object); - if (!strncasecmp(word, id, wordlen) - && ++which > state) { - result = ast_strdup(id); + if (!strncasecmp(word, id, wordlen)) { + ast_cli_completion_add(ast_strdup(id)); } ao2_t_ref(object, -1, "toss iterator endpoint ptr before break"); - if (result) { - break; - } } ao2_iterator_destroy(&i); - - return result; } static void dump_str_and_free(int fd, struct ast_str *buf) @@ -211,7 +202,8 @@ char *ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_ if (cmd == CLI_GENERATE) { ast_free(context.output_buffer); - return complete_show_sorcery_object(container, formatter_entry, a->word, a->n); + complete_show_sorcery_object(container, formatter_entry, a->word); + return NULL; } if (is_container) { diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c index e63e158c4..76cf528eb 100644 --- a/res/res_pjsip/pjsip_configuration.c +++ b/res/res_pjsip/pjsip_configuration.c @@ -1,8 +1,19 @@ /* - * sip_cli_commands.c + * Asterisk -- An open source telephony toolkit. * - * Created on: Jan 25, 2013 - * Author: mjordan + * Copyright (C) 2013, Digium, Inc. + * + * Matt Jordan <mjordan@digium.com> + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. */ #include "asterisk.h" diff --git a/res/res_pktccops.c b/res/res_pktccops.c index e8d266cda..156c49dc7 100644 --- a/res/res_pktccops.c +++ b/res/res_pktccops.c @@ -648,7 +648,7 @@ static struct cops_gate *cops_gate_cmd(int cmd, struct cops_cmts *cmts, static int cops_connect(char *host, char *port) { - int s, sfd = -1, flags; + int s, sfd = -1; struct addrinfo hints; struct addrinfo *rp; struct addrinfo *result; @@ -674,8 +674,7 @@ static int cops_connect(char *host, char *port) if (sfd == -1) { ast_log(LOG_WARNING, "Failed socket\n"); } - flags = fcntl(sfd, F_GETFL); - fcntl(sfd, F_SETFL, flags | O_NONBLOCK); + ast_fd_set_flags(sfd, O_NONBLOCK); #ifdef HAVE_SO_NOSIGPIPE setsockopt(sfd, SOL_SOCKET, SO_NOSIGPIPE, &trueval, sizeof(trueval)); #endif diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c index 5aeb791d3..16eb7dddf 100644 --- a/res/res_rtp_asterisk.c +++ b/res/res_rtp_asterisk.c @@ -3048,8 +3048,7 @@ static int create_new_socket(const char *type, int af) } ast_log(LOG_WARNING, "Unable to allocate %s socket: %s\n", type, strerror(errno)); } else { - long flags = fcntl(sock, F_GETFL); - fcntl(sock, F_SETFL, flags | O_NONBLOCK); + ast_fd_set_flags(sock, O_NONBLOCK); #ifdef SO_NO_CHECK if (nochecksums) { setsockopt(sock, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums)); diff --git a/res/res_speech.c b/res/res_speech.c index d6c532971..31ad61acb 100644 --- a/res/res_speech.c +++ b/res/res_speech.c @@ -363,5 +363,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, - .load_pri = AST_MODPRI_APP_DEPEND, + .load_pri = AST_MODPRI_APP_DEPEND - 1, ); diff --git a/res/res_stasis.c b/res/res_stasis.c index f99dcee37..42a19bf56 100644 --- a/res/res_stasis.c +++ b/res/res_stasis.c @@ -2155,8 +2155,8 @@ static int load_module(void) return AST_MODULE_LOAD_SUCCESS; } -AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Stasis application support", - .load_pri = AST_MODPRI_APP_DEPEND, +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Stasis application support", + .load_pri = AST_MODPRI_APP_DEPEND - 1, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, diff --git a/res/res_timing_pthread.c b/res/res_timing_pthread.c index 09952f929..f52079643 100644 --- a/res/res_timing_pthread.c +++ b/res/res_timing_pthread.c @@ -130,9 +130,7 @@ static void *pthread_timer_open(void) } for (i = 0; i < ARRAY_LEN(timer->pipe); ++i) { - int flags = fcntl(timer->pipe[i], F_GETFL); - flags |= O_NONBLOCK; - fcntl(timer->pipe[i], F_SETFL, flags); + ast_fd_set_flags(timer->pipe[i], O_NONBLOCK); } ao2_lock(pthread_timers); |