diff options
author | paulo <paul@bayleaf.org.uk> | 2010-02-04 15:48:35 +0000 |
---|---|---|
committer | paulo <paul@bayleaf.org.uk> | 2010-02-04 15:48:35 +0000 |
commit | c7e46768ad62e4b9cdcef28095fa2bce55ef7cc1 (patch) | |
tree | 823514c9403eeb924b0b8a5c9029f45f174df46d | |
parent | 321902625926d21f511c2d0c55f5aad634224e75 (diff) | |
download | quagga-c7e46768ad62e4b9cdcef28095fa2bce55ef7cc1.tar.bz2 quagga-c7e46768ad62e4b9cdcef28095fa2bce55ef7cc1.tar.xz |
Missed a few non safe calls of strerror. Improved comments.
-rw-r--r-- | bgpd/bgp_dump.c | 2 | ||||
-rw-r--r-- | bgpd/bgp_main.c | 2 | ||||
-rw-r--r-- | bgpd/bgp_packet.c | 8 | ||||
-rw-r--r-- | lib/log.c | 4 | ||||
-rw-r--r-- | lib/pthread_safe.c | 23 |
5 files changed, 25 insertions, 14 deletions
diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c index 8087a403..0a18ae29 100644 --- a/bgpd/bgp_dump.c +++ b/bgpd/bgp_dump.c @@ -127,7 +127,7 @@ bgp_dump_open_file (struct bgp_dump *bgp_dump) if (bgp_dump->fp == NULL) { - zlog_warn ("bgp_dump_open_file: %s: %s", realpath, strerror (errno)); + zlog_warn ("bgp_dump_open_file: %s: %s", realpath, safe_strerror (errno)); umask(oldumask); return NULL; } diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index 3ad9e0c3..94f8c7e5 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -569,7 +569,7 @@ main (int argc, char **argv) /* Turn into daemon if daemon_mode is set. */ if (daemon_mode && daemon (0, 0) < 0) { - zlog_err("BGPd daemon failed: %s", strerror(errno)); + zlog_err("BGPd daemon failed: %s", safe_strerror(errno)); return (1); } diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index e416cd34..9d587428 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -804,7 +804,7 @@ bgp_open_send (struct peer *peer) if (BGP_DEBUG (normal, NORMAL)) zlog_debug ("%s sending OPEN, version %d, my as %u, holdtime %d, id %s", peer->host, BGP_VERSION_4, local_as, - send_holdtime, inet_ntoa (peer->local_id)); + send_holdtime, safe_inet_ntoa (peer->local_id)); if (BGP_DEBUG (normal, NORMAL)) zlog_debug ("%s send message type %d, length (incl. header) %d", @@ -1178,7 +1178,7 @@ bgp_open_receive (struct peer *peer, bgp_size_t size) zlog_debug ("%s rcv OPEN, version %d, remote-as (in open) %u," " holdtime %d, id %s", peer->host, version, remote_as, holdtime, - inet_ntoa (remote_id)); + safe_inet_ntoa (remote_id)); /* BEGIN to read the capability here, but dont do it yet */ capability = 0; @@ -1260,7 +1260,7 @@ bgp_open_receive (struct peer *peer, bgp_size_t size) { if (BGP_DEBUG (normal, NORMAL)) zlog_debug ("%s bad OPEN, wrong router identifier %s", - peer->host, inet_ntoa (remote_id)); + peer->host, safe_inet_ntoa (remote_id)); bgp_notify_send_with_data (peer, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_BAD_BGP_IDENT, notify_data_remote_id, 4); @@ -1393,7 +1393,7 @@ bgp_open_receive (struct peer *peer, bgp_size_t size) { if (BGP_DEBUG (normal, NORMAL)) zlog_debug ("%s bad OPEN, wrong router identifier %s", - peer->host, inet_ntoa (remote_id)); + peer->host, safe_inet_ntoa (remote_id)); bgp_notify_send_with_data (peer, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_BAD_BGP_IDENT, @@ -709,12 +709,10 @@ _zlog_abort_err (const char *mess, int err, const char *file, { const static size_t buff_size = 1024; char buff[buff_size]; - char err_mess[buff_size]; - strerror_r(err, err_mess, buff_size); snprintf(buff, buff_size, "%s, in file %s, line %u, function %s, error %d \"%s\"", mess, file, line, (function ? function : "?"), - err, err_mess); + err, safe_strerror(err)); zlog_abort(buff); } diff --git a/lib/pthread_safe.c b/lib/pthread_safe.c index a8da3a71..f67e6b2a 100644 --- a/lib/pthread_safe.c +++ b/lib/pthread_safe.c @@ -65,6 +65,7 @@ safe_finish(void) pthread_key_delete(tsd_key); } +/* called when thread terminates, clean up */ static void destructor(void* data) { @@ -97,16 +98,28 @@ safe_strerror(int errnum) } } +/* Thread safe version of inet_ntoa. Never returns NULL. + * Contents of result remains intact until another call of + * a safe_ function. + */ const char * safe_inet_ntoa (struct in_addr in) { - if (qpthreads_enabled) - return inet_ntop(AF_INET, &in, thread_buff(), buff_size); - else - return inet_ntoa(in); + static const char * unknown = "Unknown address"; + const char * buff; + + buff = (qpthreads_enabled) + ? inet_ntop(AF_INET, &in, thread_buff(), buff_size) + : inet_ntoa(in); + + return buff != NULL + ? buff + : unknown; } -/* Return the thread's buffer */ +/* Return the thread's buffer, create it if necessary. + * (pthread Thread Specific Data) + */ static char * thread_buff(void) { |