Commit Graph

239 Commits

Author SHA1 Message Date
Joshua C. Colp ba68bb9221 utils: Make behavior of ast_strsep* match strsep.
Given the scenario of passing an empty string to the
ast_strsep functions the functions would return NULL
instead of an empty string. This is counter to how
strsep itself works.

This change alters the behavior of the functions to
match that of strsep.

Fixes: #565
(cherry picked from commit 167d393c0f)
2024-03-07 14:17:22 +00:00
Brad Smith afe0fb310d main/utils: Simplify the FreeBSD ast_get_tid() handling
FreeBSD has had kernel threads for 20+ years.

(cherry picked from commit 57ea2912e2)
2024-03-07 14:17:22 +00:00
Brad Smith 089ddaaaed main/utils: Implement ast_get_tid() for OpenBSD
Implement the ast_get_tid() function for OpenBSD. OpenBSD supports
getting the TID via getthrid().

(cherry picked from commit e7943dd4d9)
2024-01-12 18:29:19 +00:00
Mike Bradeen 714950bd7c utils: add lock timestamps for DEBUG_THREADS
Adds last locked and unlocked timestamps as well as a
counter for the number of times the lock has been
attempted (vs locked/unlocked) to debug output printed
using the DEBUG_THREADS option.

Resolves: #110
(cherry picked from commit 3acdffc17e)
2023-07-10 11:49:48 +00:00
George Joseph 8cbea1c7ef res_geolocation: Fix segfault when there's an empty element
Fixed a segfault caused by var_list_from_loc_info() encountering
an empty location info element.

Fixed an issue in ast_strsep() where a value with only whitespace
wasn't being preserved.

Fixed an issue in ast_variable_list_from_quoted_string() where
an empty value was considered a failure.

ASTERISK-30215
Reported by: Dan Cropp

Change-Id: Ieca64e061a6d9298f0196c694b60d986ef82613a
2022-09-13 09:51:25 -05:00
Philip Prindeville 2c4c44ca64 main/utils: allow checking for command in $PATH
ASTERISK-30037

Change-Id: I4b6f7264c8c737c476c798d2352f3232b263bbdf
2022-09-12 09:49:21 -05:00
George Joseph 5fe9887701 Geolocation: Base Asterisk Prereqs
* Added ast_variable_list_from_quoted_string()
  Parse a quoted string into an ast_variable list.

* Added ast_str_substitute_variables_full2()
  Perform variable/function/expression substitution on an ast_str.

* Added ast_strsep_quoted()
  Like ast_strsep except you can specify a specific quote character.
  Also added unit test.

* Added ast_xml_find_child_element()
  Find a direct child element by name.

* Added ast_xml_doc_dump_memory()
  Dump the specified document to a buffer

* ast_datastore_free() now checks for a NULL datastore
  before attempting to destroy it.

Change-Id: I5dcefed2f5f93a109e8b489e18d80d42e45244ec
2022-07-07 08:19:14 -05:00
Michał Górny 2b490787eb main/utils: Implement ast_get_tid() for NetBSD
Implement the ast_get_tid() function for NetBSD system.  NetBSD supports
getting the TID via _lwp_self().

ASTERISK-29850

Change-Id: If57fd3f9ea15ef5d010bfbdcbbbae9b379f72f8c
2022-01-19 11:36:52 -06:00
Naveen Albert d374d63ef8 app_voicemail: Refactor email generation functions
Refactors generic functions used for email generation
into utils.c so that they can be used by multiple
modules, including app_voicemail and app_minivm,
to avoid code duplication.

ASTERISK-29715 #close

Change-Id: I1de0ed3483623e9599711129edc817c45ad237ee
2021-11-30 09:28:46 -06:00
Josh Soref f382775241 main: Spelling fixes
Correct typos of the following word families:

analysis
nuisance
converting
although
transaction
desctitle
acquire
update
evaluate
thousand
this
dissolved
management
integrity
reconstructed
decrement
further on
irrelevant
currently
constancy
anyway
unconstrained
featuregroups
right
larger
evaluated
encumbered
languages
digits
authoritative
framing
blindxfer
tolerate
traverser
exclamation
perform
permissions
rearrangement
performing
processing
declension
happily
duplicate
compound
hundred
returns
elicit
allocate
actually
paths
inheritance
atxferdropcall
earlier
synchronization
multiplier
acknowledge
across
against
thousands
joyous
manipulators
guaranteed
emulating
soundfile

ASTERISK-29714

Change-Id: I926ba4b11e9f6dd3fdd93170ab1f9b997910be70
2021-11-15 17:33:27 -06:00
Ben Ford 0564d12280 STIR/SHAKEN: Switch to base64 URL encoding.
STIR/SHAKEN encodes using base64 URL format. Currently, we just use
base64. New functions have been added that convert to and from base64
encoding.

The origid field should also be an UUID. This means there's no reason to
have it as an option in stir_shaken.conf, as we can simply generate one
when creating the Identity header.

https://wiki.asterisk.org/wiki/display/AST/OpenSIPit+2021

Change-Id: Icf094a2a54e87db91d6b12244c9f5ba4fc2e0b8c
2021-05-12 06:42:55 -05:00
Ben Ford 9ed6387c14 utils.c: NULL terminate ast_base64decode_string.
With the addition of STIR/SHAKEN, the function ast_base64decode_string
was added for convenience since there is a lot of converting done during
the STIR/SHAKEN process. This function returned the decoded string for
you, but did not NULL terminate it, causing some issues (specifically
with MALLOC_DEBUG). Now, the returned string is NULL terminated, and the
documentation has been updated to reflect this.

Change-Id: Icdd7d05b323b0c47ff6ed43492937a03641bdcf5
2020-08-06 12:19:48 -05:00
Ben Ford 1274117102 res_stir_shaken: Add outbound INVITE support.
Integrated STIR/SHAKEN support with outgoing INVITEs. When an INVITE is
sent, the caller ID will be checked to see if there is a certificate
that corresponds to it. If so, that information will be retrieved and an
Identity header will be added to the SIP message. The format is:

header.payload.signature;info=<public_key_url>alg=ES256;ppt=shaken

Header, payload, and signature are all BASE64 encoded. The public key
URL is retrieved from the certificate. Currently the algorithm and ppt
are ES256 and shaken, respectively. This message is signed and can be
used for verification on the receiving end.

Two new configuration options have been added to the certificate object:
attestation and origid. The attestation is required and must be A, B, or
C. origid is the origination identifier.

A new utility function has been added as well that takes a string,
allocates space, BASE64 encodes it, then returns it, eliminating the
need to calculate the size yourself.

Change-Id: I1f84d6a5839cb2ed152ef4255b380cfc2de662b4
2020-06-18 17:45:27 -05:00
Ben Ford 3927f79cb5 res_stir_shaken: Add inbound INVITE support.
Integrated STIR/SHAKEN support with incoming INVITES. Upon receiving an
INVITE, the Identity header is retrieved, parsing the message to verify
the signature. If any of the parsing fails,
AST_STIR_SHAKEN_VERIFY_NOT_PRESENT will be added to the channel for this
caller ID. If verification itself fails,
AST_STIR_SHAKEN_VERIFY_SIGNATURE_FAILED will be added. If anything in
the payload does not line up with the SIP signaling,
AST_STIR_SHAKEN_VERIFY_MISMATCH will be added. If all of the above steps
pass, then AST_STIR_SHAKEN_VERIFY_PASSED will be added, completing the
verification process.

A new config option has been added to the general section for
stir_shaken.conf. "signature_timeout" is the amount of time a signature
will be considered valid. If an INVITE is received and the amount of
time between when it was received and when it was signed is greater than
signature_timeout, verification will fail.

Some changes were also made to signing and verification. There was an
error where the whole JSON string was being signed rather than the
header combined with the payload. This has been changed to sign the
correct thing. Verification has been changed to do this as well, and the
unit tests have been updated to reflect these changes.

A couple of utility functions have also been added. One decodes a BASE64
string and returns the decoded string, doing all the length calculations
for you. The other retrieves a string value from a header in a rdata
object.

Change-Id: I855f857be3d1c63b64812ac35d9ce0534085b913
2020-06-08 10:50:16 -05:00
Sean Bright bedf16b041 utils: Don't set or clear flags that don't need setting or clearing
Change-Id: I0e7fb507ac09b15e45e1ff8501ecfca67afa5217
2018-12-11 10:08:07 -05:00
Sean Bright 6d69fb3cc2 utils: Wrap socket() and pipe() to reduce syscalls
Some platforms provide an implementation of socket() and pipe2() that allow the
caller to specify that the resulting file descriptors should be non-blocking.

Using these allows us to potentially elide 3 calls into 1 by avoiding extraneous
calls to fcntl() to set the O_NONBLOCK flag afterwards.

In passing, change ast_alertpipe_init() to use pipe2() directly instead of the
wrapper if it is available.

Change-Id: I3ebe654fb549587537161506c6c950f4ab298bb0
2018-12-07 09:06:08 -05:00
George Joseph ece5f8015f backtrace: Refactor ast_bt_get_symbols so it doesn't crash
We've been seeing crashes in libbfd when we attempt to generate
a stack trace from multiple threads.  It turns out that libbfd
is NOT thread-safe.  It can cache the bfd structure and give it to
multiple threads without protecting itself.  To get around this,
we've added a global mutex around the bfd functions and also have
refactored the use of those functions to be more efficient and
to provide more information about inlined functions.

Also added a few more tests to test_pbx.c.  One just calls
ast_assert() and the other calls ast_log_backtrace().  Neither are
run by default.

WARNING:  This change necessitated changing the return value of
ast_bt_get_symbols() from an array of strings to a VECTOR of
strings.  However, the use of this function outside Asterisk is not
likely.

ASTERISK-28140

Change-Id: I79d02862ddaa2423a0809caa4b3b85c128131621
2018-11-19 05:49:39 -07:00
Jenkins2 bbd962bc4b Merge "utils: Avoid an unused variable in Solaris 11." 2018-06-22 07:42:53 -05:00
Alexander Traud a5c53bd323 utils: Avoid an unused variable in Solaris 11.
With ./configure --enable-dev-mode[=noisy], the build fails because every
warning gets an error. Therefore, Asterisk has to be free of warnings and this
variable must go.

Change-Id: I63dd2bc4833b9bdb04602f83422d16caf289d46a
2018-06-21 12:01:53 +02:00
Richard Mudgett 0989b63047 autoservice: Don't start channel autoservice if the thread is a user interface.
Executing dialplan functions from either AMI or ARI by getting a variable
could place the channel into autoservice.  However, these user interface
threads do not handle the channel's media so we wind up with two threads
attempting to handle the media.

There can be one and only one thread handling a channel's media at a time.
Otherwise, we don't know which thread is going to handle the media frames.

ASTERISK-27625

Change-Id: If2dc94ce15ddabf923ed1e2a65ea0ef56e013e49
2018-06-19 15:02:52 -05:00
Alexander Traud efe40ff671 BuildSystem: Add DragonFly BSD.
ASTERISK-27820

Change-Id: I310896143e94d65da1c2be3bb448204a8b86d557
2018-04-20 12:50:03 +02:00
Jenkins2 4b7872c9db Merge "core: Remove ABI effects of MALLOC_DEBUG." 2018-03-13 13:54:19 -05:00
Alexander Traud 58f44f225a utils: In Solaris, avoid a warning about an unused variable.
When HAVE_GETHOSTBYNAME_R_5 was set by the script ./configure, GCC 7.3.0 found
an unused variable. Actually, the variable was used (set to a dummy value) but
the compiler optimization might have removed that. Instead, this change ensures
that the variable 'res' is only used when it is really required.

Change-Id: Ic3ea23ccf84ac4bc2d501b514985b989030abab5
2018-03-07 16:32:05 +01:00
Richard Mudgett c711e4076a core: Remove ABI effects of MALLOC_DEBUG.
This allows asterisk to be compiled with MALLOC_DEBUG to load modules
built without MALLOC_DEBUG.  Now pre-compiled third-party modules will
still work regardless of MALLOC_DEBUG being enabled or not.

Change-Id: Ic07ad80b2c2df894db984cf27b16a69383ce0e10
2018-03-01 13:13:55 -06:00
Corey Farrell 23381d2c5e Build System: Require __sync or __atomic functions.
This change causes the configure script to throw an error if neither
__sync nor __atomic builtin functions are available.

ASTERISK-27619

Change-Id: Ie01a281e0f5c41dfeeb5f250c1ccea8752f56ef9
2018-01-25 10:38:45 -05:00
Corey Farrell bf33a09c37 core: Fix multiple trivial issues in the core.
* Fix small leaks in from error conditions in sdp.c and translate.c.
* Check new file descriptor is less than 0, not less than or equal.

Change-Id: Id7782775486175c739e0c4bf3ea5e17e3f452a99
2017-12-19 00:36:24 -05:00
Sean Bright 2ffe52a116 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
2017-12-08 13:28:04 -06:00
Richard Mudgett ee08f10d06 Fix ast_(v)asprintf() malloc failure usage conditions.
When (v)asprintf() fails, the state of the allocated buffer is undefined.
The library had better not leave an allocated buffer as a result or no one
will know to free it.  The most likely way it can return failure is for an
allocation failure.  If the printf conversion fails then you actually have
a threading problem which is much worse because another thread modified
the parameter values.

* Made __ast_asprintf()/__ast_vasprintf() set the returned buffer to NULL
on failure.  That is much more useful than either an uninitialized pointer
or a pointer that has already been freed.  Many uses won't have to check
for failure to ensure that the buffer won't be double freed or prevent an
attempt to free an uninitialized pointer.

* stasis.c: Fixed memory leak in multi_object_blob_to_ami() allocated by
ast_asprintf().

* ari/resource_bridges.c:ari_bridges_play_helper(): Remove assignment to
the wrong thing which is now not needed even if assigning to the right
thing.

Change-Id: Ib5252fb8850ecf0f78ed0ee2ca0796bda7e91c23
2017-11-06 12:47:30 -05:00
Corey Farrell 569e9a8391 Single API for ast_store_lock_info and ast_remove_lock_info.
This makes the 'bt' parameter unconditional for ast_store_lock_info and
ast_remove_lock_info.  The 'bt' parameter is unused when HAVE_BKTR is
undefined.

Change-Id: Ieced0e920928b735a39c3b5952b806c473d67453
2017-10-24 16:11:39 -04:00
Corey Farrell 58d032112b Fix compiler warnings on Fedora 26 / GCC 7.
GCC 7 has added capability to produce warnings, this fixes most of those
warnings.  The specific warnings are disabled in a few places:

* app_voicemail.c: truncation of paths more than 4096 chars in many places.
* chan_mgcp.c: callid truncated to 80 chars.
* cdr.c: two userfields are combined to cdr copy, fix would break ABI.
* tcptls.c: ignore use of deprecated method SSLv3_client_method().

ASTERISK-27156 #close

Change-Id: I65f280e7d3cfad279d16f41823a4d6fddcbc4c88
2017-08-01 15:42:38 -06:00
Sean Bright 59203c51cc core: Use eventfd for alert pipes on Linux when possible
The primary win of switching to eventfd when possible is that it only
uses a single file descriptor while pipe() will use two. This means for
each bridge channel we're reducing the number of required file
descriptors by 1, and - if you're using timerfd - we also now have 1
less file descriptor per Asterisk channel.

The API is not ideal (passing int arrays), but this is the cleanest
approach I could come up with to maintain API/ABI.

I've also removed what I believe to be an erroneous code block that
checked the non-blocking flag on the pipe ends for each read. If the
file descriptor is 'losing' its non-blocking mode, it is because of a
bug somewhere else in our code.

In my testing I haven't seen any measurable difference in performance.

Change-Id: Iff0fb1573e7f7a187d5211ddc60aa8f3da3edb1d
2017-04-24 11:50:09 -05:00
Guido Falsi 75230f4c01 res_rtp: Fix regression when IPv6 is not available.
The latest Release candidate fails to create RTP streams when IPv6
is not available. Due to the changes made in September the ast_sockaddr
structure passed around to create these streams is always of AF_INET6
type, causing failure when used for IPv4. This patch adds a utility
function to check for availability of IPv6 and applies such check
at startup to determine how to create the ast_sockaddr structures.

ASTERISK-26617 #close

Change-Id: I627a4e91795e821111e1cda523f083a40d0e0c3e
2016-11-30 14:18:05 -05:00
Timo Teräs 070a51bf7c Implement internal abstraction for iostreams
fopencookie/funclose is a non-standard API and should not be used
in portable software. Additionally, the way FILE's fd is used in
non-blocking mode is undefined behaviour and cannot be relied on.

This introduces internal abstraction for io streams, that allows
implementing the desired virtualization of read/write operations
with necessary timeout handling.

ASTERISK-24515 #close
ASTERISK-24517 #close

Change-Id: Id916aef418b665ced6a7489aef74908b6e376e85
2016-11-15 22:25:14 +02:00
Corey Farrell a6e5bae3ef Remove ASTERISK_REGISTER_FILE.
ASTERISK_REGISTER_FILE no longer has any purpose so this commit removes
all traces of it.

Previously exported symbols removed:
* __ast_register_file
* __ast_unregister_file
* ast_complete_source_filename

This also removes the mtx_prof static variable that was declared when
MTX_PROFILE was enabled.  This variable was only used in lock.c so it
is now initialized in that file only.

ASTERISK-26480 #close

Change-Id: I1074af07d71f9e159c48ef36631aa432c86f9966
2016-10-27 09:53:55 -04:00
George Joseph 6651c66e68 utils.c: Fix ast_set_default_eid for multiple platforms
ast_set_default_eid was searching for ethX, emX, enoX, ensX and even
pciD#U interface names.  While this was a good attempt, it wasn't
inclusive enough to capture interfaces like enp6s0 or ens6d1, etc.

Rather than relying on interface names, we now simply find the first
interface returned by the OS that has a hardware address and that
address isn't all 0x00 or all 0xff.  The code IS different for BSD,
Solaris and Linux based on what method is available for enumerating
interfaces.

Tested on:
FreeBSD9
CentOS6
Ubuntu14
Fedora24

I was unable to test on Solaris at this time but the code for Solaris
is used elsewhere at Digium.

Change-Id: Iaa6db87ca78a9a375e47d70e043ae08c1448cb72
2016-10-16 18:35:39 -05:00
Corey Farrell 2a03575c30 astobj2: Add backtrace to log_bad_ao2.
* Compile __ast_assert_failed unconditionally.
* Use __ast_assert_failed to log messages from log_bad_ao2
* Remove calls to ast_assert(0) that happen after log_bad_ao2 was run.

Change-Id: I48f1af44b2718ad74a421ff75cb6397b924a9751
2016-09-30 19:25:40 -04:00
Corey Farrell 8c5c95ad89 core: Remove ABI effects of LOW_MEMORY.
This allows asterisk to compiled with LOW_MEMORY to load modules built
without LOW_MEMORY.

ASTERISK-26398 #close

Change-Id: I24b78ac9493ab933b11087a8b6794f3c96d4872d
2016-09-29 03:22:28 -04:00
Corey Farrell 8061d9f66f Fix naming mismatch of allocator functions.
Allocator functions that take file/line/func parameters are prefixed
with single-underscore when MALLOC_DEBUG is not defined,
double-underscore when it is defined.  This change updates all
allocators that accept file/line/func to have the same prototype in
either ABI mode.  The parameter order of __ast_vasprintf and
__ast_asprintf in utils.h have been changed to match that of astmm.h.

End-use allocator macro's have been removed from astmm.h and moved to an
unconditional part of utils.h.

Change-Id: I823bb6ce2b5675b3a4735948f10a3b420e9a023a
2016-08-19 20:16:36 -04:00
Alexei Gradinari e85adbd947 core: Entity ID is not set or invalid
The Exchanging Device and Mailbox States could not working
if the Entity ID (EID) is not set manually and can't be obtained
from ethernet interface.

This patch replaces debug message to warning
and addes missing description about option 'entityid' to
asterisk.conf.sample.

With this patch the asterisk also:
(1) decline loading the modules which won't work without EID:
    res_corosync and res_pjsip_publish_asterisk.
(2) warn if EID is empty on loading next modules:
    pbx_dundi, res_xmpp

Starting with v197 systemd/udev will automatically assign "predictable"
names for all local Ethernet interfaces.
This patch also addes some new ethernet prefixes "eno" and "ens".

ASTERISK-26164 #close

Change-Id: I72d712f1ad5b6f64571bb179c5cb12461e7c58c6
2016-08-15 13:35:59 -05:00
Corey Farrell 8f6e9ffcc6 Add conditional support for noreturn functions.
This adds support for tagging functions with the noreturn attribute.
If DO_CRASH is enabled then ast_do_crash never returns.  If AST_DEVMODE
and DO_CRASH are enabled then failed assertions never return.  This can
resolve a large number of false positives with static analyzers.

ASTERISK-26220 #close

Change-Id: Icfb61e5fe54574eced4c3e88b317244f467ec753
2016-07-19 22:45:10 -05:00
George Joseph 4d40b161c3 stringfields: Refactor to allow fields to be added to the end of structures
String fields are great, except that you can't add new ones without breaking
ABI compatibility because it shifts down everything else in the structure.
The only alternative is to add your own char * field to the end of the
structure and manage the memory yourself which isn't ideal, especially since
you then can't use the OPT_STRINGFIELD_T type.

Background:

The reason string fields had to be declared inside the
AST_DECLARE_STRING_FIELDS block was to facilitate iteration over all declared
fields for initialization, compare and copy.  Since AST_DECLARE_STRING_FIELDS
declared the pool, then the fields, then the manager, you could use the offsets
of the pool and manager and iterate over the sequential addresses in between to
access the fields. The actual pool, field allocation and field set operations
don't actually care where the field is.  It's just iteration over the fields
that was the problem.

Solution: Extended String Fields

An extended string field is one that is declared outside the
AST_DECLARE_STRING_FIELDS block but still (anywhere) inside the parent
structure.  Other than using AST_STRING_FIELD_EXTENDED instead of
AST_STRING_FIELD, it looks the same as other string fields.  It's storage comes
from the pool and it participates in string field compare and copy operations
peformed on the parent structure. It's also a valid target for the
OPT_STRINGFIELD_T aco option type.

Implementation:

To keep track of the extended fields and make sure that ABI isn't broken, the
existing embedded_pool pointer in the manager structure was repurposed to be a
pointer to a separate header structure that contains the embedded_pool pointer
plus a vector of fields.  The length of the manager structure didn't change and
the embedded_pool pointer isn't used in the macros, only the stringfields C
code.  A side benefit of this is that changing the header structure in the
future won't break ABI.

ast_string_fields_init initializes the normal string fields and appends them to
the vector, and subsequent calls to ast_string_field_init_extended initialize
and append the extended fields. Cleanup, ast_string_fields_cmp, and
ast_string_fields_copy can now work on the vector instead of sequentially
traversing the addresses between the pool and manager.

The total size of a structure using string fields didn't change, whether using
extended fields or not, nor have the offsets of any structure members, either
inside the original block or outside.  Adding an extended field to the end of a
structure is the same as adding a char *.

Details:

The stringfield C code was pulled out from utils.c and into stringfields.c.
It just made sense.

Additional work was done in ast_string_field_init and
ast_calloc_with_stringfields to handle the allocation of the new header
structure and the vector, and the associated cleanup.  In the process some
additional NULL pointer checking was added.

A lot of work was done in stringfields.h since the logic for compare and copy
is there.  Documentation was added as well as somne additional NULL checking.

The ability to call ast_calloc_with_stringfields with a number of structures
greater than 1 never really worked.  Well, the calloc worked but there was no
way to access the additional structures or clean them up.  It was agreed that
there was no use case for requesting more than 1 structure so an ast_assert
was added to prevent it and the iteration code removed.

Testing:

The stringfield unit tests were updated to test both normal and extended
fields.  Tests for ast_string_field_ptr_set_by_fields and
ast_calloc_with_stringfields were also added.

As an ABI test, 13 was compiled from git and the res_pjsip_* modules, except
res_pjsip itself, saved off.  The patch was then added and a full compile and
install was performed.  Then the older res_pjsip_* moduled were copied over the
installed versions so res_pjsip was new and the rest were old.  No issues.

contact->aor, which is a char * at the end of contact, was then changed to an
extended string field and a recompile and reinstall was performed, again
leaving stock versions of the the res_pjsip_* modules.  Again, no issues with
the res_pjsip_* modules using the old stringfield implementation and with
contact->aor as a char *, and res_pjsip itself using the new stringfield
implementation and contact->aor being an extended string field.

Finally, several existing string fields were converted to extended string
fields to test OPT_STRINGFIELD_T.  Again, no issues.

Change-Id: I235db338c5b178f5a13b7946afbaa5d4a0f91d61
2016-04-04 19:07:53 -05:00
George Joseph 433d2c4bbf utils.c: Fix typo in handle_show_locks
ast_cli_allow_on_shutdown(e) should have been ast_cli_allow_at_shutdown(e).

Change-Id: I4f092495c0b2bfd85c2651e0b5877bf4d05d9faf
2016-04-01 13:11:34 -05:00
Mark Michelson 89e94e886c Restrict CLI/AMI commands on shutdown.
During stress testing, we have frequently seen crashes occur because a
CLI or AMI command attempts to access information that is in the process
of being destroyed.

When addressing how to fix this issue, we initially considered fixing
individual crashes we observed. However, the changes required to fix
those problems would introduce considerable overhead to the nominal
case. This is not reasonable in order to prevent a crash from occurring
while Asterisk is already shutting down.

Instead, this change makes it so AMI and CLI commands cannot be executed
if Asterisk is being shut down. For AMI, this is absolute. For CLI,
though, certain commands can be registered so that they may be run
during Asterisk shutdown.

ASTERISK-25825 #close

Change-Id: I8887e215ac352fadf7f4c1e082da9089b1421990
2016-03-24 16:59:24 -05:00
Diederik de Groot 7856762f2f main: Use ast_strdup instead of strdup
Fix compile error in main/utils.c because strdup was used in dummy_start

Change-Id: Id61a6cf4f3cbf235450441e10e7da101a6335793
2016-01-07 10:34:15 +01:00
Richard Mudgett eccdf2250b Fix sscanf() format string type mismatch.
ASTERISK-25615
Reported by: George Joseph

Change-Id: Ieff35307254ca193f3d473cff2e396ca57c7ce0b
2015-12-14 16:22:25 -06:00
Matt Jordan b47b632107 Merge "main/utils: Don't emit an ERROR message if the read end of a pipe closes" 2015-12-14 06:45:07 -06:00
Matt Jordan 9a96a86e2d main/utils: Don't emit an ERROR message if the read end of a pipe closes
An ERROR or WARNING message should generally indicate that something has gone
wrong in Asterisk. In the case of writing to a file descriptor, Asterisk is not
in control of when the far end closes its reading on a file descriptor. If the
far end does close the file descriptor in an unclean fashion, this isn't a bug
or error in Asterisk, particularly when the situation can be gracefully
handled in Asterisk.

Currently, when this happens, a user would see the following somewhat cryptic
ERROR message:

  "utils.c: write() returned error: Broken pipe"

There's a few problems with this:
(1) It doesn't provide any context, other than 'something broke a pipe'
(2) As noted, it isn't actually an error in Asterisk
(3) It can get rather spammy if the thing breaking the pipe occurs often, such
    as a FastAGI server
(4) Spammy ERROR messages make Asterisk appear to be having issues, or can even
    mask legitimate issues

This patch changes ast_carefulwrite to only log an ERROR if we actually had one
that was reasonably under our control. For debugging purposes, we still emit
a debug message if we detect that the far side has stopped reading.

Change-Id: Ia503bb1efcec685fa6f3017bedf98061f8e1b566
2015-12-13 13:26:29 -06:00
George Joseph 3e6637feb5 pjsip/config_transport: Check pjproject version at runtime for async ops
pjproject < 2.5.0 will segfault on a tls transport if async_operations
is greater than 1.  A runtime version check has been added to throw
an error if the version is < 2.5.0 and async_operations > 1.

To assist in the check, a new api "ast_compare_versions" was added
to utils which compares 2 major.minor.patch.extra version strings.

ASTERISK-25615 #close

Change-Id: I8e88bb49cbcfbca88d9de705496d6f6a8c938a98
Reported-by: George Joseph
Tested-by: George Joseph
2015-12-12 11:16:08 -06:00
George Joseph a987434564 res_pjsip: Add existence and readablity checks for tls related files
Both transport and endpoint now check for the existence and readability
of tls certificate and key files before passing them on to pjproject.
This will cause the object to not load rather than waiting for pjproject
to discover that there's a problem when a session is attempted.

NOTE: chan_sip also uses ast_rtp_dtls_cfg_parse but it's located
in build_peer which is gigantic and I didn't want to disturb it.
Error messages will emit but it won't interrupt chan_sip loading.

ASTERISK-25618 #close

Change-Id: Ie43f2c1d653ac1fda6a6f6faecb7c2ebadaf47c9
Reported-by: George Joseph
Tested-by: George Joseph
2015-12-08 18:04:33 -06:00
Guido Falsi fbdb42c9fc Core/General: Add #ifdef needed on FreeBSD.
pthread_attr_init() defaults to PTHREAD_EXPLICIT_SCHED on FreeBSD
too.

ASTERISK-25310 #close
Reported by: Guido Falsi

Change-Id: Iae6befac9028b5b9795f86986a4a08a1ae6ab7c4
2015-09-03 21:29:37 -05:00