diff options
-rw-r--r-- | bgpd/bgp_dump.c | 2 | ||||
-rw-r--r-- | bgpd/bgp_fsm.c | 16 | ||||
-rw-r--r-- | bgpd/bgp_main.c | 2 | ||||
-rw-r--r-- | bgpd/bgp_network.c | 34 | ||||
-rw-r--r-- | bgpd/bgp_route.c | 2 | ||||
-rw-r--r-- | bgpd/bgp_vty.c | 7 | ||||
-rw-r--r-- | bgpd/bgpd.c | 5 | ||||
-rwxr-xr-x | configure.ac | 2 | ||||
-rw-r--r-- | lib/Makefile.am | 4 | ||||
-rw-r--r-- | lib/buffer.c | 8 | ||||
-rw-r--r-- | lib/command.c | 6 | ||||
-rw-r--r-- | lib/daemon.c | 6 | ||||
-rw-r--r-- | lib/errno_names.c | 311 | ||||
-rw-r--r-- | lib/errno_names.h | 26 | ||||
-rw-r--r-- | lib/log.c | 11 | ||||
-rw-r--r-- | lib/memory.c | 2 | ||||
-rw-r--r-- | lib/network.c | 4 | ||||
-rw-r--r-- | lib/pid_output.c | 14 | ||||
-rw-r--r-- | lib/privs.c | 198 | ||||
-rw-r--r-- | lib/pthread_safe.c | 230 | ||||
-rw-r--r-- | lib/pthread_safe.h | 10 | ||||
-rw-r--r-- | lib/qfstring.c | 33 | ||||
-rw-r--r-- | lib/qfstring.h | 5 | ||||
-rw-r--r-- | lib/sigevent.c | 2 | ||||
-rw-r--r-- | lib/smux.c | 104 | ||||
-rw-r--r-- | lib/sockopt.c | 33 | ||||
-rw-r--r-- | lib/sockunion.c | 45 | ||||
-rw-r--r-- | lib/sockunion.h | 8 | ||||
-rw-r--r-- | lib/stream.c | 4 | ||||
-rw-r--r-- | lib/thread.c | 2 | ||||
-rw-r--r-- | lib/vty.c | 2 | ||||
-rw-r--r-- | lib/vty_io.c | 58 |
32 files changed, 903 insertions, 293 deletions
diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c index 4bd48e4e..3bc318a5 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, safe_strerror (errno)); + zlog_warn("bgp_dump_open_file: %s: %s", realpath, errtoa(errno, 0).str); umask(oldumask); return NULL; } diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index 87e13ecb..9c323ffd 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -594,7 +594,7 @@ extern void bgp_fsm_io_fatal_error(bgp_connection connection, int err) { plog_err (connection->log, "%s [Error] bgp IO error: %s", - connection->host, safe_strerror(err)) ; + connection->host, errtoa(err, 0).str) ; assert(err != EFAULT) ; @@ -639,7 +639,7 @@ bgp_fsm_io_error(bgp_connection connection, int err) plog_debug(connection->log, "%s [Event] BGP connection closed fd %d (%s)", connection->host, qps_file_fd(connection->qf), - safe_strerror(err)) ; + errtoa(err, 0).str) ; } ; bgp_fsm_throw(connection, bgp_session_eTCP_dropped, NULL, err, @@ -1711,21 +1711,19 @@ static bgp_fsm_action(bgp_fsm_accept) */ static bgp_fsm_action(bgp_fsm_send_open) { - char buf_l[SU_ADDRSTRLEN] ; - char buf_r[SU_ADDRSTRLEN] ; - const char* how ; - if (BGP_DEBUG (normal, NORMAL)) { + const char* how ; + if (connection->ordinal == bgp_connection_primary) how = "connect" ; else how = "accept" ; zlog_debug("%s open %s(), local address %s", - sockunion2str(connection->su_remote, buf_r, sizeof(buf_r)), - how, - sockunion2str(connection->su_local, buf_l, sizeof(buf_l))) ; + sutoa(connection->su_remote).str, + how, + sutoa(connection->su_local).str) ; } ; bgp_connection_read_enable(connection) ; diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index 32cbf91b..434cfcfb 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -626,7 +626,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", safe_strerror(errno)); + zlog_err("BGPd daemon failed: %s", errtoa(errno, 0).str); return (1); } diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index d969a69b..856447d7 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -222,7 +222,7 @@ bgp_open_listener_on(const char* address, unsigned short port) ainfo->ai_protocol); if (sock_fd < 0) { - zlog_err ("socket: %s", safe_strerror (errno)); + zlog_err ("socket: %s", errtoa(errno, 0).str); continue; } @@ -254,7 +254,7 @@ bgp_open_listener_on(const char* address, unsigned short port) if (address && ((ret = inet_aton(address, &sin.sin_addr)) < 1)) { zlog_err("bgp_socket: could not parse ip address %s: %s", - address, safe_strerror (errno)); + address, errtoa(errno, 0).str); return ret; } #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN @@ -264,7 +264,7 @@ bgp_open_listener_on(const char* address, unsigned short port) sock_fd = socket (AF_INET, SOCK_STREAM, 0); if (sock_fd < 0) { - zlog_err ("socket: %s", safe_strerror (errno)); + zlog_err ("socket: %s", errtoa(errno, 0).str); return sock_fd; } @@ -355,21 +355,21 @@ bgp_init_listener(int sock_fd, struct sockaddr *sa, socklen_t salen) if (bgpd_privs.change(ZPRIVS_RAISE)) { err = errno ; - zlog_err("%s: could not raise privs: %s", __func__, safe_strerror(errno)); + zlog_err("%s: could not raise privs: %s", __func__, errtoa(errno, 0).str); } ; ret = bind(sock_fd, sa, salen) ; if (ret < 0) { err = errno ; - zlog_err ("%s: bind: %s", __func__, safe_strerror(err)); + zlog_err ("%s: bind: %s", __func__, errtoa(err, 0).str); } ; if (bgpd_privs.change(ZPRIVS_LOWER)) { if (err == 0) err = errno ; - zlog_err("%s: could not lower privs: %s", __func__, safe_strerror(errno)); + zlog_err("%s: could not lower privs: %s", __func__, errtoa(errno, 0).str); } ; if (err == 0) @@ -378,7 +378,7 @@ bgp_init_listener(int sock_fd, struct sockaddr *sa, socklen_t salen) if (ret < 0) { err = errno ; - zlog_err ("%s: listen: %s", __func__, safe_strerror(err)) ; + zlog_err ("%s: listen: %s", __func__, errtoa(err, 0).str) ; } } ; @@ -516,7 +516,6 @@ bgp_accept_action(qps_file qf, void* file_info) int sock_fd ; int err ; int family ; - char buf[SU_ADDRSTRLEN] ; /* Accept client connection. */ sock_fd = sockunion_accept(qps_file_fd(qf), &su_remote) ; @@ -524,13 +523,12 @@ bgp_accept_action(qps_file qf, void* file_info) { err = errno ; if (sock_fd == -1) - zlog_err("[Error] BGP socket accept failed (%s)", safe_strerror(err)) ; + zlog_err("[Error] BGP socket accept failed (%s)", errtoa(err, 0).str) ; return ; /* have no connection to report this to */ } ; if (BGP_DEBUG(events, EVENTS)) - zlog_debug("[Event] BGP connection from host %s", - sockunion2str(&su_remote, buf, sizeof(buf))) ; + zlog_debug("[Event] BGP connection from host %s", sutoa(&su_remote).str) ; /* See if we are ready to accept connections from the connecting party */ connection = bgp_peer_index_seek_accept(&su_remote, &exists) ; @@ -540,7 +538,7 @@ bgp_accept_action(qps_file qf, void* file_info) zlog_debug(exists ? "[Event] BGP accept IP address %s is not accepting" : "[Event] BGP accept IP address %s is not configured", - sockunion2str(&su_remote, buf, sizeof(buf))) ; + sutoa(&su_remote).str) ; close(sock_fd) ; return ; /* quietly reject connection */ /* TODO: RFC recommends sending a NOTIFICATION when refusing accept() */ @@ -843,7 +841,7 @@ bgp_bind_ifname(bgp_connection connection, int sock_fd) if (bgpd_privs.change (ZPRIVS_RAISE)) { err = errno ; - zlog_err ("bgp_bind: could not raise privs: %s", safe_strerror(errno)); + zlog_err ("bgp_bind: could not raise privs: %s", errtoa(errno, 0).str); } ; ret = setsockopt (sock_fd, SOL_SOCKET, SO_BINDTODEVICE, @@ -855,13 +853,13 @@ bgp_bind_ifname(bgp_connection connection, int sock_fd) { if (err == 0) err = errno ; - zlog_err ("bgp_bind: could not lower privs: %s", safe_strerror(errno)); + zlog_err ("bgp_bind: could not lower privs: %s", errtoa(errno, 0).str); } ; if (err != 0) { zlog (connection->log, LOG_INFO, "bind to interface %s failed (%s)", - connection->session->ifname, safe_strerror(err)); + connection->session->ifname, errtoa(err, 0).str) ; return err ; } #endif /* SO_BINDTODEVICE */ @@ -994,7 +992,7 @@ bgp_md5_set_socket(int sock_fd, union sockunion *su, const char *password) if (bgpd_privs.change(ZPRIVS_RAISE)) { err = errno ; - zlog_err("%s: could not raise privs: %s", __func__, safe_strerror(errno)); + zlog_err("%s: could not raise privs: %s", __func__, errtoa(errno, 0).str); } ; ret = sockopt_tcp_signature(sock_fd, su, password) ; @@ -1006,12 +1004,12 @@ bgp_md5_set_socket(int sock_fd, union sockunion *su, const char *password) { if (err == 0) err = errno ; - zlog_err("%s: could not lower privs: %s", __func__, safe_strerror(errno)); + zlog_err("%s: could not lower privs: %s", __func__, errtoa(errno, 0).str); } ; if (err != 0) zlog (NULL, LOG_WARNING, "cannot set TCP_MD5SIG option on socket %d: %s", - sock_fd, safe_strerror(err)) ; + sock_fd, errtoa(err, 0).str) ; return err ; } ; diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 5ca43c72..875ff648 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -6809,7 +6809,7 @@ route_vty_out_detail_header (struct vty *vty, struct bgp *bgp, if (! first) vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE); - vty_out (vty, " %s", sockunion2str (&peer->su, buf, sizeof(buf))); + vty_out (vty, " %s", sutoa(&peer->su).str); first = 1; } } diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 5e0374c1..1afc9f94 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -7527,8 +7527,7 @@ bgp_show_peer (struct vty *vty, struct peer *p) if (p->update_if) vty_out (vty, "%s", p->update_if); else if (p->update_source) - vty_out (vty, "%s", - sockunion2str (p->update_source, buf, sizeof(buf))); + vty_out (vty, "%s", sutoa(p->update_source).str); vty_out (vty, "%s", VTY_NEWLINE); } @@ -7578,7 +7577,7 @@ bgp_show_peer (struct vty *vty, struct peer *p) if (p->su_local) { vty_out (vty, "Local host: %s, Local port: %d%s", - sockunion2str (p->su_local, buf, sizeof(buf)), + sutoa(p->su_local).str, ntohs (p->su_local->sin.sin_port), VTY_NEWLINE); } @@ -7587,7 +7586,7 @@ bgp_show_peer (struct vty *vty, struct peer *p) if (p->su_remote) { vty_out (vty, "Foreign host: %s, Foreign port: %d%s", - sockunion2str (p->su_remote, buf, sizeof(buf)), + sutoa(p->su_remote).str, ntohs (p->su_remote->sin.sin_port), VTY_NEWLINE); } diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index b1ea09dc..1176d2d0 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -4066,7 +4066,6 @@ bgp_config_write_peer (struct vty *vty, struct bgp *bgp, { struct bgp_filter *filter; struct peer *g_peer = NULL; - char buf[SU_ADDRSTRLEN]; char *addr; filter = &peer->filter[afi][safi]; @@ -4166,8 +4165,8 @@ bgp_config_write_peer (struct vty *vty, struct bgp *bgp, || sockunion_cmp (g_peer->update_source, peer->update_source) != 0) vty_out (vty, " neighbor %s update-source %s%s", addr, - sockunion2str (peer->update_source, buf, sizeof(buf)), - VTY_NEWLINE); + sutoa(peer->update_source).str, + VTY_NEWLINE); /* advertisement-interval */ if (CHECK_FLAG (peer->config, PEER_CONFIG_ROUTEADV)) diff --git a/configure.ac b/configure.ac index 17ab4387..85784080 100755 --- a/configure.ac +++ b/configure.ac @@ -8,7 +8,7 @@ ## $Id$ AC_PREREQ(2.53) -AC_INIT(Quagga, 0.99.15, [http://bugzilla.quagga.net]) +AC_INIT(Quagga, 0.99.15ex01, [http://bugzilla.quagga.net]) AC_CONFIG_SRCDIR(lib/zebra.h) AC_CONFIG_MACRO_DIR([m4]) diff --git a/lib/Makefile.am b/lib/Makefile.am index 9022c245..09a2e3b8 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -16,7 +16,7 @@ libzebra_la_SOURCES = \ qtime.c qpthreads.c mqueue.c qpselect.c qtimers.c qpnexus.c \ command_queue.c qlib_init.c pthread_safe.c list_util.c \ vty_io.c vty_cli.c keystroke.c qstring.c vio_fifo.c vio_lines.c \ - qiovec.c qfstring.c + qiovec.c qfstring.c errno_names.c BUILT_SOURCES = memtypes.h route_types.h @@ -36,7 +36,7 @@ pkginclude_HEADERS = \ command_queue.h qlib_init.h qafi_safi.h \ confirm.h miyagi.h pthread_safe.h list_util.h node_type.h uty.h \ vty_io.h vty_cli.h keystroke.h qstring.h vio_fifo.h vio_lines.h \ - qiovec.h qfstring.h + qiovec.h qfstring.h errno_names.h EXTRA_DIST = regex.c regex-gnu.h memtypes.awk route_types.awk route_types.txt diff --git a/lib/buffer.c b/lib/buffer.c index b81924ec..816b0d1d 100644 --- a/lib/buffer.c +++ b/lib/buffer.c @@ -350,7 +350,7 @@ buffer_flush_window (struct buffer *b, int fd, int width, int height, if ((nbytes = writev(fd, c_iov, iov_size)) < 0) { zlog_warn("%s: writev to fd %d failed: %s", - __func__, fd, safe_strerror(errno)); + __func__, fd, errtoa(errno, 0).str) ; break; } @@ -362,7 +362,7 @@ buffer_flush_window (struct buffer *b, int fd, int width, int height, #else /* IOV_MAX */ if ((nbytes = writev (fd, iov, iov_index)) < 0) zlog_warn("%s: writev to fd %d failed: %s", - __func__, fd, safe_strerror(errno)); + __func__, fd, errtoa(errno, 0).str); #endif /* IOV_MAX */ /* Free printed buffer data. */ @@ -424,7 +424,7 @@ in one shot. */ /* Calling code should try again later. */ return BUFFER_PENDING; zlog_warn("%s: write error on fd %d: %s", - __func__, fd, safe_strerror(errno)); + __func__, fd, errtoa(errno, 0).str); return BUFFER_ERROR; } @@ -479,7 +479,7 @@ buffer_write(struct buffer *b, int fd, const void *p, size_t size) else { zlog_warn("%s: write error on fd %d: %s", - __func__, fd, safe_strerror(errno)); + __func__, fd, errtoa(errno, 0).str); return BUFFER_ERROR; } } diff --git a/lib/command.c b/lib/command.c index 6e1726dc..f67d0f8b 100644 --- a/lib/command.c +++ b/lib/command.c @@ -3131,12 +3131,12 @@ DEFUN (config_write_file, if (chmod (config_file, CONFIGFILE_MASK) != 0) { - vty_out (vty, "Can't chmod configuration file %s: %s (%d).%s", - config_file, safe_strerror(errno), errno, VTY_NEWLINE); + vty_out (vty, "Can't chmod configuration file %s: %s (%s).\n", + config_file, errtostr(errno, 0).str, errtoname(errno, 0).str); goto finished; } - vty_out (vty, "Configuration saved to %s%s", config_file, VTY_NEWLINE); + vty_out (vty, "Configuration saved to %s\n", config_file); ret = CMD_SUCCESS; diff --git a/lib/daemon.c b/lib/daemon.c index c473555b..daf3c320 100644 --- a/lib/daemon.c +++ b/lib/daemon.c @@ -1,7 +1,7 @@ /* * Daemonize routine * Copyright (C) 1997, 1999 Kunihiro Ishiguro - * + * * This file is part of GNU Zebra. * * GNU Zebra is free software; you can redistribute it and/or modify @@ -36,7 +36,7 @@ daemon (int nochdir, int noclose) /* In case of fork is error. */ if (pid < 0) { - zlog_err ("fork failed: %s", safe_strerror(errno)); + zlog_err ("fork failed: %s", errtoa(errno, 0).str); return -1; } @@ -49,7 +49,7 @@ daemon (int nochdir, int noclose) if (pid == -1) { - zlog_err ("setsid failed: %s", safe_strerror(errno)); + zlog_err ("setsid failed: %s", errtoa(errno, 0).str); return -1; } diff --git a/lib/errno_names.c b/lib/errno_names.c new file mode 100644 index 00000000..51f430a9 --- /dev/null +++ b/lib/errno_names.c @@ -0,0 +1,311 @@ +/* Mapping Error Numbers to their names + * Copyright (C) 2010 Chris Hall (GMCH), Highwayman + * + * This file is part of GNU Zebra. + * + * GNU Zebra is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * GNU Zebra is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Zebra; see the file COPYING. If not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include <stddef.h> +#include <errno.h> +#include "errno_names.h" + +/*============================================================================== + * Table to map error number to its name + */ +#define ERRNO(err) [err] = #err + +static const char* errno_name_table[] = +{ + /* Error number for no error + * + * (123456789012345), /-- no name is more than 15 characters + */ + ERRNO(EOK), /* No error */ + + /* POSIX Error Numbers -- taken Open Group Base Specifications Issue 7 + * IEEE Std 1003.1-2008 + */ + ERRNO(E2BIG), /* Argument list too long. */ + ERRNO(EACCES), /* Permission denied. */ + ERRNO(EADDRINUSE), /* Address in use. */ + ERRNO(EADDRNOTAVAIL), /* Address not available. */ + ERRNO(EAFNOSUPPORT), /* Address family not supported. */ +#if EAGAIN != EWOULDBLOCK + ERRNO(EAGAIN), /* Resource unavailable, try again + (may be the same value as [EWOULDBLOCK]). */ +#endif + ERRNO(EALREADY), /* Connection already in progress. */ + ERRNO(EBADF), /* Bad file descriptor. */ + ERRNO(EBADMSG), /* Bad message. */ + ERRNO(EBUSY), /* Device or resource busy. */ + ERRNO(ECANCELED), /* Operation canceled. */ + ERRNO(ECHILD), /* No child processes. */ + ERRNO(ECONNABORTED), /* Connection aborted. */ + ERRNO(ECONNREFUSED), /* Connection refused. */ + ERRNO(ECONNRESET), /* Connection reset. */ + ERRNO(EDEADLK), /* Resource deadlock would occur. */ + ERRNO(EDESTADDRREQ), /* Destination address required. */ + ERRNO(EDOM), /* Mathematics argument out of domain of function. */ + ERRNO(EDQUOT), /* Reserved. */ + ERRNO(EEXIST), /* File exists. */ + ERRNO(EFAULT), /* Bad address. */ + ERRNO(EFBIG), /* File too large. */ + ERRNO(EHOSTUNREACH), /* Host is unreachable. */ + ERRNO(EIDRM), /* Identifier removed. */ + ERRNO(EILSEQ), /* Illegal byte sequence. */ + ERRNO(EINPROGRESS), /* Operation in progress. */ + ERRNO(EINTR), /* Interrupted function. */ + ERRNO(EINVAL), /* Invalid argument. */ + ERRNO(EIO), /* I/O error. */ + ERRNO(EISCONN), /* Socket is connected. */ + ERRNO(EISDIR), /* Is a directory. */ + ERRNO(ELOOP), /* Too many levels of symbolic links. */ + ERRNO(EMFILE), /* File descriptor value too large. */ + ERRNO(EMLINK), /* Too many links. */ + ERRNO(EMSGSIZE), /* Message too large. */ + ERRNO(EMULTIHOP), /* Reserved. */ + ERRNO(ENAMETOOLONG), /* Filename too long. */ + ERRNO(ENETDOWN), /* Network is down. */ + ERRNO(ENETRESET), /* Connection aborted by network. */ + ERRNO(ENETUNREACH), /* Network unreachable. */ + ERRNO(ENFILE), /* Too many files open in system. */ + ERRNO(ENOBUFS), /* No buffer space available. */ + ERRNO(ENODATA), /* No message is available on the STREAM head read + queue. */ + ERRNO(ENODEV), /* No such device. */ + ERRNO(ENOENT), /* No such file or directory. */ + ERRNO(ENOEXEC), /* Executable file format error. */ + ERRNO(ENOLCK), /* No locks available. */ + ERRNO(ENOLINK), /* Reserved. */ + ERRNO(ENOMEM), /* Not enough space. */ + ERRNO(ENOMSG), /* No message of the desired type. */ + ERRNO(ENOPROTOOPT), /* Protocol not available. */ + ERRNO(ENOSPC), /* No space left on device. */ + ERRNO(ENOSR), /* No STREAM resources. */ + ERRNO(ENOSTR), /* Not a STREAM. */ + ERRNO(ENOSYS), /* Function not supported. */ + ERRNO(ENOTCONN), /* The socket is not connected. */ + ERRNO(ENOTDIR), /* Not a directory. */ + ERRNO(ENOTEMPTY), /* Directory not empty. */ + ERRNO(ENOTRECOVERABLE), /* State not recoverable. */ + ERRNO(ENOTSOCK), /* Not a socket. */ + ERRNO(ENOTSUP), /* Not supported + (may be the same value as [EOPNOTSUPP]). */ + ERRNO(ENOTTY), /* Inappropriate I/O control operation. */ + ERRNO(ENXIO), /* No such device or address. */ +#if EOPNOTSUPP != ENOTSUP + ERRNO(EOPNOTSUPP), /* Operation not supported on socket + (may be the same value as [ENOTSUP]). */ +#endif + ERRNO(EOVERFLOW), /* Value too large to be stored in data type. */ + ERRNO(EOWNERDEAD), /* Previous owner died. */ + ERRNO(EPERM), /* Operation not permitted. */ + ERRNO(EPIPE), /* Broken pipe. */ + ERRNO(EPROTO), /* Protocol error. */ + ERRNO(EPROTONOSUPPORT), /* Protocol not supported. */ + ERRNO(EPROTOTYPE), /* Protocol wrong type for socket. */ + ERRNO(ERANGE), /* Result too large. */ + ERRNO(EROFS), /* Read-only file system. */ + ERRNO(ESPIPE), /* Invalid seek. */ + ERRNO(ESRCH), /* No such process. */ + ERRNO(ESTALE), /* Reserved. */ + ERRNO(ETIME), /* Stream ioctl() timeout. */ + ERRNO(ETIMEDOUT), /* Connection timed out. */ + ERRNO(ETXTBSY), /* Text file busy. */ + ERRNO(EWOULDBLOCK), /* Operation would block + (may be the same value as [EAGAIN]). */ + ERRNO(EXDEV), /* Cross-device link. */ + +/* Linux Error Numbers -- for 2.6.30, taken 8-Apr-2010. + * + * (123456789012345), /-- no name is more than 15 characters + */ +#ifdef EADV + ERRNO(EADV), /* Advertise error */ +#endif +#ifdef EBADE + ERRNO(EBADE), /* Invalid exchange */ +#endif +#ifdef EBADFD + ERRNO(EBADFD), /* File descriptor in bad state */ +#endif +#ifdef EBADR + ERRNO(EBADR), /* Invalid request descriptor */ +#endif +#ifdef EBADRQC + ERRNO(EBADRQC), /* Invalid request code */ +#endif +#ifdef EBADSLT + ERRNO(EBADSLT), /* Invalid slot */ +#endif +#ifdef EBFONT + ERRNO(EBFONT), /* Bad font file format */ +#endif +#ifdef ECHRNG + ERRNO(ECHRNG), /* Channel number out of range */ +#endif +#ifdef ECOMM + ERRNO(ECOMM), /* Communication error on send */ +#endif +#ifdef EDEADLOCK + ERRNO(EDEADLOCK), /* same as EDEADLK */ +#endif +#ifdef EDOTDOT + ERRNO(EDOTDOT), /* RFS specific error */ +#endif +#ifdef EHOSTDOWN + ERRNO(EHOSTDOWN), /* Host is down */ +#endif +#ifdef EISNAM + ERRNO(EISNAM), /* Is a named type file */ +#endif +#ifdef EKEYEXPIRED + ERRNO(EKEYEXPIRED), /* Key has expired */ +#endif +#ifdef EKEYREJECTED + ERRNO(EKEYREJECTED), /* Key was rejected by service */ +#endif +#ifdef EKEYREVOKED + ERRNO(EKEYREVOKED), /* Key has been revoked */ +#endif +#ifdef EL2HLT + ERRNO(EL2HLT), /* Level 2 halted */ +#endif +#ifdef EL2NSYNC + ERRNO(EL2NSYNC), /* Level 2 not synchronized */ +#endif +#ifdef EL3HLT + ERRNO(EL3HLT), /* Level 3 halted */ +#endif +#ifdef EL3RST + ERRNO(EL3RST), /* Level 3 reset */ +#endif +#ifdef ELIBACC + ERRNO(ELIBACC), /* Can not access a needed shared library */ +#endif +#ifdef ELIBBAD + ERRNO(ELIBBAD), /* Accessing a corrupted shared library */ +#endif +#ifdef ELIBEXEC + ERRNO(ELIBEXEC), /* Cannot exec a shared library directly */ +#endif +#ifdef ELIBMAX + ERRNO(ELIBMAX), /* Attempting to link in too many shared libraries */ +#endif +#ifdef ELIBSCN + ERRNO(ELIBSCN), /* .lib section in a.out corrupted */ +#endif +#ifdef ELNRNG + ERRNO(ELNRNG), /* Link number out of range */ +#endif +#ifdef EMEDIUMTYPE + ERRNO(EMEDIUMTYPE), /* Wrong medium type */ +#endif +#ifdef ENAVAIL + ERRNO(ENAVAIL), /* No XENIX semaphores available */ +#endif +#ifdef ENOANO + ERRNO(ENOANO), /* No anode */ +#endif +#ifdef ENOCSI + ERRNO(ENOCSI), /* No CSI structure available */ +#endif +#ifdef ENOKEY + ERRNO(ENOKEY), /* Required key not available */ +#endif +#ifdef ENOMEDIUM + ERRNO(ENOMEDIUM), /* No medium found */ +#endif +#ifdef ENONET + ERRNO(ENONET), /* Machine is not on the network */ +#endif +#ifdef ENOPKG + ERRNO(ENOPKG), /* Package not installed */ +#endif +#ifdef ENOTBLK + ERRNO(ENOTBLK), /* Block device required */ +#endif +#ifdef ENOTNAM + ERRNO(ENOTNAM), /* Not a XENIX named type file */ +#endif +#ifdef ENOTUNIQ + ERRNO(ENOTUNIQ), /* Name not unique on network */ +#endif +#ifdef EPFNOSUPPORT + ERRNO(EPFNOSUPPORT), /* Protocol family not supported */ +#endif +#ifdef EREMCHG + ERRNO(EREMCHG), /* Remote address changed */ +#endif +#ifdef EREMOTE + ERRNO(EREMOTE), /* Object is remote */ +#endif +#ifdef EREMOTEIO + ERRNO(EREMOTEIO), /* Remote I/O error */ +#endif +#ifdef ERESTART + ERRNO(ERESTART), /* Interrupted system call should be restarted */ +#endif +#ifdef ESHUTDOWN + ERRNO(ESHUTDOWN), /* Cannot send after transport endpoint shutdown */ +#endif +#ifdef ESOCKTNOSUPPORT + ERRNO(ESOCKTNOSUPPORT), /* Socket type not supported */ +#endif +#ifdef ESRMNT + ERRNO(ESRMNT), /* Srmount error */ +#endif +#ifdef ESTRPIPE + ERRNO(ESTRPIPE), /* Streams pipe error */ +#endif +#ifdef ETOOMANYREFS + ERRNO(ETOOMANYREFS), /* Too many references: cannot splice */ +#endif +#ifdef EUCLEAN + ERRNO(EUCLEAN), /* Structure needs cleaning */ +#endif +#ifdef EUNATCH + ERRNO(EUNATCH), /* Protocol driver not attached */ +#endif +#ifdef EUSERS + ERRNO(EUSERS), /* Too many users */ +#endif +#ifdef EXFULL + ERRNO(EXFULL), /* Exchange full */ +#endif +} ; + +enum { errno_last = (sizeof(errno_name_table) / sizeof(char*)) - 1 } ; + +/*============================================================================== + * Lookup the name for given error number. + * + * Returns: address of string, or NULL if not known + * + * NB: for 0 returns "EOK". + * + * NB: async-signal-safe and thread-safe ! + */ +extern const char* +errno_name_lookup(int err) +{ + if ((err < 0) || (err > errno_last)) + return NULL ; + return errno_name_table[err] ; +} ; + + diff --git a/lib/errno_names.h b/lib/errno_names.h new file mode 100644 index 00000000..f095640d --- /dev/null +++ b/lib/errno_names.h @@ -0,0 +1,26 @@ +/* Mapping Error Numbers to their names -- header + * Copyright (C) 2010 Chris Hall (GMCH), Highwayman + * + * This file is part of GNU Zebra. + * + * GNU Zebra is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * GNU Zebra is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Zebra; see the file COPYING. If not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef EOK +#define EOK 0 +#endif + +extern const char* errno_name_lookup(int err) ; @@ -289,7 +289,7 @@ uvzlog_line(struct logline* ll, struct zlog *zl, int priority, va_end(vac); /* Set pointer to where the '\0' is. */ - p = ll->p_nl = qfs_end(&qfs) ; + p = ll->p_nl = qfs_ptr(&qfs) ; } ; /* finish off with '\r''\n''\0' or '\n''\0' as required */ @@ -753,9 +753,9 @@ _zlog_abort_err (const char *mess, int err, const char *file, const static size_t buff_size = 1024; char buff[buff_size]; snprintf(buff, buff_size, - "%s, in file %s, line %u, function %s, error %d \"%s\"", + "%s, in file %s, line %u, function %s, %s", mess, file, line, (function ? function : "?"), - err, safe_strerror(err)); + errtoa(err, 0).str); zlog_abort(buff); } @@ -939,8 +939,9 @@ zlog_rotate (struct zlog *zl) { /* can't call logging while locked */ char *fname = strdup(zl->filename); - uzlog(NULL, LOG_ERR, "Log rotate failed: cannot open file %s for append: %s", - fname, safe_strerror(save_errno)); + uzlog(NULL, LOG_ERR, + "Log rotate failed: cannot open file %s for append: %s", + fname, errtoa(save_errno, 0).str); free(fname); result = -1; } diff --git a/lib/memory.c b/lib/memory.c index f68dd298..fb0e8d0d 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -100,7 +100,7 @@ static void __attribute__ ((noreturn)) zerror (const char *fname, int type, size_t size) { zlog_err ("%s : can't allocate memory for `%s' size %d: %s\n", - fname, lookup (mstr, type), (int) size, safe_strerror(errno)); + fname, lookup (mstr, type), (int) size, errtoa(errno, 0).str); log_memstats(LOG_WARNING); /* N.B. It might be preferable to call zlog_backtrace_sigsafe here, since that function should definitely be safe in an OOM condition. But diff --git a/lib/network.c b/lib/network.c index 61d98717..ae67a402 100644 --- a/lib/network.c +++ b/lib/network.c @@ -209,13 +209,13 @@ set_nonblocking(int fd) if ((flags = fcntl(fd, F_GETFL)) < 0) { zlog_warn("fcntl(F_GETFL) failed for fd %d: %s", - fd, safe_strerror(errno)); + fd, errtoa(errno, 0).str); return -1; } if (fcntl(fd, F_SETFL, (flags | O_NONBLOCK)) < 0) { zlog_warn("fcntl failed setting fd %d non-blocking: %s", - fd, safe_strerror(errno)); + fd, errtoa(errno, 0).str); return -1; } return 0; diff --git a/lib/pid_output.c b/lib/pid_output.c index 5261babc..17081dad 100644 --- a/lib/pid_output.c +++ b/lib/pid_output.c @@ -17,7 +17,7 @@ * You should have received a copy of the GNU General Public License * along with GNU Zebra; see the file COPYING. If not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. + * 02111-1307, USA. */ #include <zebra.h> @@ -39,7 +39,7 @@ pid_output (const char *path) oldumask = umask(0777 & ~PIDFILE_MASK); fp = fopen (path, "w"); - if (fp != NULL) + if (fp != NULL) { fprintf (fp, "%d\n", (int) pid); fclose (fp); @@ -49,7 +49,7 @@ pid_output (const char *path) /* XXX Why do we continue instead of exiting? This seems incompatible with the behavior of the fcntl version below. */ zlog_warn("Can't fopen pid lock file %s (%s), continuing", - path, safe_strerror(errno)); + path, errtoa(errno, 0).str); umask(oldumask); return -1; } @@ -63,7 +63,7 @@ pid_output (const char *path) int fd; pid_t pid; char buf[16]; - struct flock lock; + struct flock lock; mode_t oldumask; pid = getpid (); @@ -73,7 +73,7 @@ pid_output (const char *path) if (fd < 0) { zlog_err("Can't create pid lock file %s (%s), exiting", - path, safe_strerror(errno)); + path, errtoa(errno, 0).str); umask(oldumask); exit(1); } @@ -97,10 +97,10 @@ pid_output (const char *path) pidsize = strlen(buf); if ((tmp = write (fd, buf, pidsize)) != (int)pidsize) zlog_err("Could not write pid %d to pid_file %s, rc was %d: %s", - (int)pid,path,tmp,safe_strerror(errno)); + (int)pid,path,tmp, errtoa(errno, 0).str); else if (ftruncate(fd, pidsize) < 0) zlog_err("Could not truncate pid_file %s to %u bytes: %s", - path,(u_int)pidsize,safe_strerror(errno)); + path,(u_int)pidsize, errtoa(errno, 0).str); } return pid; } diff --git a/lib/privs.c b/lib/privs.c index 91114a7e..be3265ed 100644 --- a/lib/privs.c +++ b/lib/privs.c @@ -1,4 +1,4 @@ -/* +/* * Zebra privileges. * * Copyright (C) 2003 Paul Jakma. @@ -19,7 +19,7 @@ * You should have received a copy of the GNU General Public License * along with GNU Zebra; see the file COPYING. If not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. + * 02111-1307, USA. */ #include <zebra.h> #include "log.h" @@ -43,7 +43,7 @@ static qpt_mutex_t privs_mutex; * sets are mostly opaque, to hold a set of privileges, related in some way. * storage binds together a set of sets we're interested in. * (in reality: cap_value_t and priv_t are ints) - */ + */ #ifdef HAVE_LCAPS /* Linux doesn't have a 'set' type: a set of related privileges */ struct _pset { @@ -53,7 +53,7 @@ struct _pset { typedef cap_value_t pvalue_t; typedef struct _pset pset_t; typedef cap_t pstorage_t; - + #elif defined (HAVE_SOLARIS_CAPABILITIES) typedef priv_t pvalue_t; typedef priv_set_t pset_t; @@ -62,7 +62,7 @@ typedef priv_set_t *pstorage_t; #error "HAVE_CAPABILITIES defined, but neither LCAPS nor Solaris Capabilties!" #endif /* HAVE_LCAPS */ #endif /* HAVE_CAPABILITIES */ - + /* the default NULL state we report is RAISED, but could be LOWERED if * zprivs_terminate is called and the NULL handler is installed. */ @@ -135,7 +135,7 @@ static struct [ZCAP_CHROOT] = { 1, (pvalue_t []) { PRIV_PROC_CHROOT }, }, [ZCAP_NICE] = { 1, (pvalue_t []) { PRIV_PROC_PRIOCNTL }, }, [ZCAP_PTRACE] = { 1, (pvalue_t []) { PRIV_PROC_SESSION }, }, - [ZCAP_DAC_OVERRIDE] = { 2, (pvalue_t []) { PRIV_FILE_DAC_EXECUTE, + [ZCAP_DAC_OVERRIDE] = { 2, (pvalue_t []) { PRIV_FILE_DAC_EXECUTE, PRIV_FILE_DAC_READ, PRIV_FILE_DAC_SEARCH, PRIV_FILE_DAC_WRITE, @@ -146,7 +146,7 @@ static struct [ZCAP_FOWNER] = { 1, (pvalue_t []) { PRIV_FILE_OWNER }, }, #endif /* HAVE_SOLARIS_CAPABILITIES */ }; - + #ifdef HAVE_LCAPS /* Linux forms of capabilities methods */ /* convert zebras privileges to system capabilities */ @@ -155,42 +155,42 @@ zcaps2sys (zebra_capabilities_t *zcaps, int num) { pset_t *syscaps; int i, j = 0, count = 0; - + if (!num) return NULL; - + /* first count up how many system caps we have */ for (i= 0; i < num; i++) count += cap_map[zcaps[i]].num; - + if ( (syscaps = XCALLOC (MTYPE_PRIVS, (sizeof(pset_t) * num))) == NULL) { fprintf (stderr, "%s: could not allocate syscaps!", __func__); return NULL; } - + syscaps->caps = XCALLOC (MTYPE_PRIVS, (sizeof (pvalue_t) * count)); - + if (!syscaps->caps) { fprintf (stderr, "%s: could not XCALLOC caps!", __func__); return NULL; } - + /* copy the capabilities over */ count = 0; for (i=0; i < num; i++) for (j = 0; j < cap_map[zcaps[i]].num; j++) syscaps->caps[count++] = cap_map[zcaps[i]].system_caps[j]; - + /* iterations above should be exact same as previous count, obviously.. */ syscaps->num = count; - + return syscaps; } /* set or clear the effective capabilities to/from permitted */ -int +int zprivs_change_caps (zebra_privs_ops_t op) { cap_flag_value_t cflag; @@ -223,8 +223,8 @@ zprivs_change_caps (zebra_privs_ops_t op) } if ( change && !cap_set_flag (zprivs_state.caps, CAP_EFFECTIVE, - zprivs_state.syscaps_p->num, - zprivs_state.syscaps_p->caps, + zprivs_state.syscaps_p->num, + zprivs_state.syscaps_p->caps, cflag)) result = cap_set_proc (zprivs_state.caps); @@ -248,14 +248,14 @@ zprivs_state_caps (void) UNLOCK exit (1); } - + for (i=0; i < zprivs_state.syscaps_p->num; i++) { - if ( cap_get_flag (zprivs_state.caps, zprivs_state.syscaps_p->caps[i], + if ( cap_get_flag (zprivs_state.caps, zprivs_state.syscaps_p->caps[i], CAP_EFFECTIVE, &val) ) { zlog_warn ("zprivs_state_caps: could not cap_get_flag, %s", - safe_strerror (errno) ); + errtoa(errno, 0).str) ; result = ZPRIVS_UNKNOWN; break; } @@ -280,7 +280,7 @@ zprivs_caps_init (struct zebra_privs_t *zprivs) if ( prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) == -1 ) { fprintf (stderr, "privs_init: could not set PR_SET_KEEPCAPS, %s\n", - safe_strerror (errno) ); + errtostr(errno, 0).str) ; exit(1); } @@ -295,50 +295,50 @@ zprivs_caps_init (struct zebra_privs_t *zprivs) { if ( setreuid (zprivs_state.zuid, zprivs_state.zuid) ) { - fprintf (stderr, "zprivs_init (cap): could not setreuid, %s\n", - safe_strerror (errno)); - exit (1); + fprintf (stderr, "zprivs_init (cap): could not setreuid, %s\n", + errtostr(errno, 0).str) ; + exit (1); } } - + if ( !(zprivs_state.caps = cap_init()) ) { - fprintf (stderr, "privs_init: failed to cap_init, %s\n", - safe_strerror (errno)); + fprintf (stderr, "privs_init: failed to cap_init, %s\n", + errtostr(errno, 0).str) ; exit (1); } if ( cap_clear (zprivs_state.caps) ) { - fprintf (stderr, "privs_init: failed to cap_clear, %s\n", - safe_strerror (errno)); + fprintf (stderr, "privs_init: failed to cap_clear, %s\n", + errtostr(errno, 0).str) ; exit (1); } - + /* set permitted caps */ - cap_set_flag(zprivs_state.caps, CAP_PERMITTED, + cap_set_flag(zprivs_state.caps, CAP_PERMITTED, zprivs_state.syscaps_p->num, zprivs_state.syscaps_p->caps, CAP_SET); - + /* set inheritable caps, if any */ if (zprivs_state.syscaps_i && zprivs_state.syscaps_i->num) { - cap_set_flag(zprivs_state.caps, CAP_INHERITABLE, - zprivs_state.syscaps_i->num, - zprivs_state.syscaps_i->caps, + cap_set_flag(zprivs_state.caps, CAP_INHERITABLE, + zprivs_state.syscaps_i->num, + zprivs_state.syscaps_i->caps, CAP_SET); } - - /* apply caps. CAP_EFFECTIVE is cleared. we'll raise the caps as + + /* apply caps. CAP_EFFECTIVE is cleared. we'll raise the caps as * and when, and only when, they are needed. */ - if ( cap_set_proc (zprivs_state.caps) ) + if ( cap_set_proc (zprivs_state.caps) ) { fprintf (stderr, "privs_init: initial cap_set_proc failed\n"); exit (1); } - + /* set methods for the caller to use */ zprivs->change = zprivs_change_caps; zprivs->current_state = zprivs_state_caps; @@ -352,12 +352,12 @@ zprivs_caps_terminate (void) cap_clear (zprivs_state.caps); /* and boom, capabilities are gone forever */ - if ( cap_set_proc (zprivs_state.caps) ) + if ( cap_set_proc (zprivs_state.caps) ) { fprintf (stderr, "privs_terminate: cap_set_proc failed, %s", - safe_strerror (errno) ); + errtostr(errno, 0).str) ; exit (1); - } + } /* free up private state */ if (zprivs_state.syscaps_p->num) @@ -365,18 +365,18 @@ zprivs_caps_terminate (void) XFREE (MTYPE_PRIVS, zprivs_state.syscaps_p->caps); XFREE (MTYPE_PRIVS, zprivs_state.syscaps_p); } - + if (zprivs_state.syscaps_i && zprivs_state.syscaps_i->num) { XFREE (MTYPE_PRIVS, zprivs_state.syscaps_i->caps); XFREE (MTYPE_PRIVS, zprivs_state.syscaps_i); } - + cap_free (zprivs_state.caps); } #elif defined (HAVE_SOLARIS_CAPABILITIES) /* !HAVE_LCAPS */ - -/* Solaris specific capability/privilege methods + +/* Solaris specific capability/privilege methods * * Resources: * - the 'privileges' man page @@ -390,30 +390,30 @@ zcaps2sys (zebra_capabilities_t *zcaps, int num) { pset_t *syscaps; int i, j = 0; - + if ((syscaps = priv_allocset()) == NULL) { fprintf (stderr, "%s: could not allocate syscaps!\n", __func__); exit (1); } - + priv_emptyset (syscaps); - + for (i=0; i < num; i++) for (j = 0; j < cap_map[zcaps[i]].num; j++) priv_addset (syscaps, cap_map[zcaps[i]].system_caps[j]); - + return syscaps; } /* callback exported to users to RAISE and LOWER effective privileges * from nothing to the given permitted set and back down */ -int +int zprivs_change_caps (zebra_privs_ops_t op) { int result = 0; - + LOCK /* should be no possibility of being called without valid caps */ @@ -424,7 +424,7 @@ zprivs_change_caps (zebra_privs_ops_t op) UNLOCK exit (1); } - + /* to raise: copy original permitted into our working effective set * to lower: just clear the working effective set */ @@ -448,25 +448,25 @@ zprivs_change_caps (zebra_privs_ops_t op) } else result = -1; - + UNLOCK - + return result; } /* Retrieve current privilege state, is it RAISED or LOWERED? */ -zebra_privs_current_t +zebra_privs_current_t zprivs_state_caps (void) { zebra_privs_current_t result = ZPRIVS_UNKNOWN; pset_t *effective; - + LOCK if ( (effective = priv_allocset()) == NULL) { fprintf (stderr, "%s: failed to get priv_allocset! %s\n", __func__, - safe_strerror (errno)); + errtoa(errno, 0).str); } else { @@ -474,7 +474,7 @@ zprivs_state_caps (void) if (getppriv (PRIV_EFFECTIVE, effective)) { fprintf (stderr, "%s: failed to get state! %s\n", __func__, - safe_strerror (errno)); + errtoa(errno, 0).str); } else { @@ -487,7 +487,7 @@ zprivs_state_caps (void) if (effective) priv_freeset (effective); } - + UNLOCK return result; } @@ -497,11 +497,11 @@ zprivs_caps_init (struct zebra_privs_t *zprivs) { pset_t *basic; pset_t *empty; - + /* the specified sets */ zprivs_state.syscaps_p = zcaps2sys (zprivs->caps_p, zprivs->cap_num_p); zprivs_state.syscaps_i = zcaps2sys (zprivs->caps_i, zprivs->cap_num_i); - + /* nonsensical to have gotten here but not have capabilities */ if (!zprivs_state.syscaps_p) { @@ -509,7 +509,7 @@ zprivs_caps_init (struct zebra_privs_t *zprivs) "but no valid capabilities supplied\n", __func__); } - + /* We retain the basic set in our permitted set, as Linux has no * equivalent. The basic set on Linux hence is implicit, always * there. @@ -519,11 +519,11 @@ zprivs_caps_init (struct zebra_privs_t *zprivs) fprintf (stderr, "%s: couldn't get basic set!\n", __func__); exit (1); } - + /* Add the basic set to the permitted set */ priv_union (basic, zprivs_state.syscaps_p); priv_freeset (basic); - + /* we need an empty set for 'effective', potentially for inheritable too */ if ( (empty = priv_allocset()) == NULL) { @@ -531,20 +531,20 @@ zprivs_caps_init (struct zebra_privs_t *zprivs) exit (1); } priv_emptyset (empty); - - /* Hey kernel, we know about privileges! + + /* Hey kernel, we know about privileges! * this isn't strictly required, use of setppriv should have same effect */ if (setpflags (PRIV_AWARE, 1)) { fprintf (stderr, "%s: error setting PRIV_AWARE!, %s\n", __func__, - safe_strerror (errno) ); + errtoa(errno, 0).str ); exit (1); } - + /* need either valid or empty sets for both p and i.. */ assert (zprivs_state.syscaps_i && zprivs_state.syscaps_p); - + /* we have caps, we have no need to ever change back the original user * change real, effective and saved to the specified user. */ @@ -552,25 +552,25 @@ zprivs_caps_init (struct zebra_privs_t *zprivs) { if ( setreuid (zprivs_state.zuid, zprivs_state.zuid) ) { - fprintf (stderr, "%s: could not setreuid, %s\n", - __func__, safe_strerror (errno)); + fprintf (stderr, "%s: could not setreuid, %s\n", + __func__, errtoa(errno, 0).str); exit (1); } } - + /* set the permitted set */ if (setppriv (PRIV_SET, PRIV_PERMITTED, zprivs_state.syscaps_p)) { fprintf (stderr, "%s: error setting permitted set!, %s\n", __func__, - safe_strerror (errno) ); + errtoa(errno, 0).str ); exit (1); } - + /* set the inheritable set */ if (setppriv (PRIV_SET, PRIV_INHERITABLE, zprivs_state.syscaps_i)) { fprintf (stderr, "%s: error setting inheritable set!, %s\n", __func__, - safe_strerror (errno) ); + errtoa(errno, 0).str ); exit (1); } @@ -578,13 +578,13 @@ zprivs_caps_init (struct zebra_privs_t *zprivs) if (setppriv (PRIV_SET, PRIV_EFFECTIVE, empty)) { fprintf (stderr, "%s: error setting effective set!, %s\n", __func__, - safe_strerror (errno) ); + errtoa(errno, 0).str ); exit (1); } - + /* we'll use this as our working-storage privset */ zprivs_state.caps = empty; - + /* set methods for the caller to use */ zprivs->change = zprivs_change_caps; zprivs->current_state = zprivs_state_caps; @@ -594,26 +594,26 @@ static void zprivs_caps_terminate (void) { assert (zprivs_state.caps); - + /* clear all capabilities */ priv_emptyset (zprivs_state.caps); setppriv (PRIV_SET, PRIV_EFFECTIVE, zprivs_state.caps); setppriv (PRIV_SET, PRIV_PERMITTED, zprivs_state.caps); setppriv (PRIV_SET, PRIV_INHERITABLE, zprivs_state.caps); - + /* free up private state */ if (zprivs_state.syscaps_p) priv_freeset (zprivs_state.syscaps_p); if (zprivs_state.syscaps_i) priv_freeset (zprivs_state.syscaps_i); - + priv_freeset (zprivs_state.caps); } #else /* !HAVE_LCAPS && ! HAVE_SOLARIS_CAPABILITIES */ #error "Neither Solaris nor Linux capabilities, dazed and confused..." #endif /* HAVE_LCAPS */ #endif /* HAVE_CAPABILITIES */ - + int zprivs_change_uid (zebra_privs_ops_t op) { @@ -699,7 +699,7 @@ zprivs_init(struct zebra_privs_t *zprivs) LOCK /* NULL privs */ - if (! (zprivs->user || zprivs->group + if (! (zprivs->user || zprivs->group || zprivs->cap_num_p || zprivs->cap_num_i) ) { zprivs->change = zprivs_change_null; @@ -735,10 +735,10 @@ zprivs_init(struct zebra_privs_t *zprivs) if ( setgroups (1, &zprivs_state.vtygrp) ) { fprintf (stderr, "privs_init: could not setgroups, %s\n", - safe_strerror (errno) ); + errtostr(errno, 0).str) ; UNLOCK exit (1); - } + } } else { @@ -748,7 +748,7 @@ zprivs_init(struct zebra_privs_t *zprivs) exit (1); } } - + if (zprivs->group) { if ( (grentry = getgrnam (zprivs->group)) ) @@ -766,12 +766,12 @@ zprivs_init(struct zebra_privs_t *zprivs) if ( setregid (zprivs_state.zgid, zprivs_state.zgid) ) { fprintf (stderr, "zprivs_init: could not setregid, %s\n", - safe_strerror (errno) ); + errtostr(errno, 0).str) ; UNLOCK exit (1); } } - + #ifdef HAVE_CAPABILITIES zprivs_caps_init (zprivs); #else /* !HAVE_CAPABILITIES */ @@ -781,18 +781,18 @@ zprivs_init(struct zebra_privs_t *zprivs) * * This is not worth that much security wise, but all we can do. */ - zprivs_state.zsuid = geteuid(); + zprivs_state.zsuid = geteuid(); if ( zprivs_state.zuid ) { if ( setreuid (-1, zprivs_state.zuid) ) { - fprintf (stderr, "privs_init (uid): could not setreuid, %s\n", - safe_strerror (errno)); + fprintf (stderr, "privs_init (uid): could not setreuid, %s\n", + errtoa(errno, 0).str); UNLOCK exit (1); } } - + zprivs->change = zprivs_change_uid; zprivs->current_state = zprivs_state_uid; #endif /* HAVE_CAPABILITIES */ @@ -800,7 +800,7 @@ zprivs_init(struct zebra_privs_t *zprivs) UNLOCK } -void +void zprivs_terminate (struct zebra_privs_t *zprivs) { if (!zprivs) @@ -808,7 +808,7 @@ zprivs_terminate (struct zebra_privs_t *zprivs) fprintf (stderr, "%s: no privs struct given, terminating", __func__); exit (0); } - + LOCK #ifdef HAVE_CAPABILITIES @@ -818,8 +818,8 @@ zprivs_terminate (struct zebra_privs_t *zprivs) { if ( setreuid (zprivs_state.zuid, zprivs_state.zuid) ) { - fprintf (stderr, "privs_terminate: could not setreuid, %s", - safe_strerror (errno) ); + fprintf (stderr, "privs_terminate: could not setreuid, %s", + errtoa(errno, 0).str ); UNLOCK exit (1); } @@ -847,7 +847,7 @@ zprivs_get_ids(struct zprivs_ids_t *ids) : (ids->gid_normal = -1); (zprivs_state.vtygrp) ? (ids->gid_vty = zprivs_state.vtygrp) : (ids->gid_vty = -1); - + UNLOCK return; } diff --git a/lib/pthread_safe.c b/lib/pthread_safe.c index f67e6b2a..b6c429e4 100644 --- a/lib/pthread_safe.c +++ b/lib/pthread_safe.c @@ -35,7 +35,10 @@ #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> +#include <errno.h> +#include "qfstring.h" +#include "errno_names.h" /* prototypes */ static void destructor(void* data); @@ -98,6 +101,226 @@ safe_strerror(int errnum) } } +/*------------------------------------------------------------------------------ + * Construct string to describe the given error of the form: + * + * ENAME '<strerror>' + * + * where <strerror> is given by strerror() or, if pthreads_enabled, strerror_r() + * + * Truncates the result to the given len (0 => no truncation). But silently + * imposes the maximum length allowed by the strerror_t. + * + * If has to truncate, places "..." at the end of the message to show this has + * happened. + * + * If a name is not known then (assuming strerror() won't know it either): + * + * ERRNO=999 *unknown error* + * + * For err==0 returns: + * + * EOK 'no error' + * + * Thread safe replacement for strerror. Never returns NULL. + */ +static void +errtox(strerror_t* st, int err, int len, int want) +{ + qf_str_t qfs ; + + const char* q ; + int ql ; + + /* Prepare. */ + int errno_saved = errno ; + + if ((len <= 0) || (len >= (int)sizeof(st->str))) + len = sizeof(st->str) - 1 ; + qfs_init(&qfs, st->str, len + 1) ; + + q = "" ; + ql = 0 ; + + /* If want the error name, do that now. */ + if (want & 1) + { + const char* name = errno_name_lookup(err) ; + + if (name != NULL) + qfs_append(&qfs, name) ; + else + qfs_printf(&qfs, "ERRNO=%d", err) ; + } ; + + /* name and string ? */ + if (want == 3) + { + qfs_append(&qfs, " ") ; + q = "'" ; + ql = 2 ; + } ; + + /* If want the error string, do that now */ + if (want & 2) + { + char buf[400] ; /* impossibly vast */ + int ret ; + const char* errm ; + + if (err == 0) + errm = "no error" ; + else + { + if (qpthreads_enabled) + { + /* POSIX is not explicit about what happens if the buffer is not + * big enough to accommodate the message, except that an ERANGE + * error may be raised. + * + * By experiment: glibc-2.10.2-1.x86_64 returns -1, with errno + * set to ERANGE and no string at all if the buffer is too small. + * + * A huge buffer is used to get the message, and that is later + * truncated, if necessary, to fit in the strerror_t structure. + */ + + buf[0] = '\0' ; /* make sure starts empty */ + ret = strerror_r(err, buf, sizeof(buf)) ; + errm = buf ; + if (ret != 0) + ret = errno ; + } + else + { + /* POSIX says that strerror *will* return something, but it is + * known that it may return NULL if the error number is not + * recognised. + */ + errno = 0 ; + errm = strerror(err) ; + ret = errno ; + if ((ret == 0) && ((errm == NULL) || (*errm == '\0'))) + ret = EINVAL ; + } ; + + /* Deal with errors, however exotic. */ + if (ret != 0) + { + q = "*" ; + ql = 2 ; /* force "*" "quotes" */ + if (ret == EINVAL) + errm = "unknown error" ; + else if (ret == ERANGE) + { + if (*errm == '\0') + errm = "vast error message" ; + } + else + { + qf_str_t qfs_b ; + qfs_init(&qfs_b, buf, sizeof(buf)) ; + qfs_printf(&qfs_b, "strerror%s(%d) returned error %d", + qpthreads_enabled ? "_r" : "", err, ret) ; + errm = buf ; + } ; + } ; + } ; + + /* Add strerror to the result... looking out for overflow. */ + len = strlen(errm) ; + + if ((len + ql) <= qfs_left(&qfs)) /* accounting for "quotes" */ + qfs_printf(&qfs, "%s%s%s", q, errm, q) ; + else + qfs_printf(&qfs, "%s%.*s...%s", q, qfs_left(&qfs) - ql - 3, errm, q) ; + /* -ve precision is ignored ! */ + } ; + + /* Put back errno */ + errno = errno_saved ; +} ; + +/*------------------------------------------------------------------------------ + * Construct string to describe the given error of the form: + * + * ENAME '<strerror>' + * + * where <strerror> is given by strerror() or, if pthreads_enabled, strerror_r() + * + * Truncates the result to the given len (0 => no truncation). But silently + * imposes the maximum length allowed by the strerror_t. + * + * If has to truncate, places "..." at the end of the message to show this has + * happened. + * + * If a name is not known then (assuming strerror() won't know it either): + * + * ERRNO=999 *unknown error* + * + * For err==0 returns: + * + * EOK 'no error' + * + * Thread safe replacement for strerror. Never returns NULL. + */ +extern strerror_t +errtoa(int err, int len) +{ + strerror_t st ; + + errtox(&st, err, len, 3) ; /* name and message */ + + return st ; +} ; + +/*------------------------------------------------------------------------------ + * Convert error number to its name + + * If a name is not known then: + * + * ERRNO=999 + * + * For err==0 returns: + * + * EOK + * + * Truncates the result to the given len (0 => no truncation). But silently + * imposes the maximum length allowed by the strerror_t. + * + * This is thread-safe. + */ +extern strerror_t +errtoname(int err, int len) +{ + strerror_t st ; + + errtox(&st, err, len, 1) ; /* name */ + + return st ; +} ; + +/*------------------------------------------------------------------------------ + * Alternative thread-safe safe_strerror() + * + * Truncates the result to the given len (0 => no truncation). But silently + * imposes the maximum length allowed by the strerror_t. + * + * If the <strerror> will not fit in the strerror_t, it is truncated and + * '...' placed at the end to show this has happened. + * + * Thread safe replacement for strerror. Never returns NULL. + */ +extern strerror_t +errtostr(int err, int len) +{ + strerror_t st ; + + errtox(&st, err, len, 2) ; /* message */ + + return st ; +} ; + /* Thread safe version of inet_ntoa. Never returns NULL. * Contents of result remains intact until another call of * a safe_ function. @@ -135,3 +358,10 @@ thread_buff(void) return buff; } + + + + + + + diff --git a/lib/pthread_safe.h b/lib/pthread_safe.h index 81adc668..0b2d7cdf 100644 --- a/lib/pthread_safe.h +++ b/lib/pthread_safe.h @@ -24,9 +24,19 @@ #include <netinet/in.h> +typedef struct strerror strerror_t ; +struct strerror +{ + char str[121] ; /* cannot imagine anything as big */ +} ; + extern void safe_init_r(void); extern void safe_finish(void); extern const char * safe_strerror(int errnum); extern const char * safe_inet_ntoa (struct in_addr in); +extern strerror_t errtoa(int err, int len) ; +extern strerror_t errtoname(int err, int len) ; +extern strerror_t errtostr(int err, int len) ; + #endif /* PTHREAD_SAFE_H_ */ diff --git a/lib/qfstring.c b/lib/qfstring.c index 30ee441c..583d729f 100644 --- a/lib/qfstring.c +++ b/lib/qfstring.c @@ -40,10 +40,33 @@ qfs_init(qf_str qfs, char* str, size_t size) { assert(size > 0) ; - qfs->str = qfs->ptr = str ; - qfs->end = qfs->str + size - 1 ; + qfs->str = str ; + qfs->end = str + size - 1 ; *str = '\0' ; + qfs->ptr = str ; +} ; + +/*------------------------------------------------------------------------------ + * Initialise qf_str which already contains string -- to given size (which + * includes the '\n') + * + * This may be used to prepare for appending to a buffer which already contains + * something. + * + * Sets pointers, setting the write pointer to the existing terminating '\n'. + * + * This operation is async-signal-safe. + */ +extern void +qfs_init_as_is(qf_str qfs, char* str, size_t size) +{ + assert(size > 0) ; + + qfs->str = str ; + qfs->end = str + size - 1 ; + + qfs->ptr = strchr(str, '\0') ; } ; /*------------------------------------------------------------------------------ @@ -205,7 +228,7 @@ qfs_append_justified(qf_str qfs, const char* src, int width) extern void qfs_append_justified_n(qf_str qfs, const char* src, size_t n, int width) { - if (n >= abs(width)) + if ((int)n >= abs(width)) width = 0 ; if (width > 0) @@ -861,7 +884,7 @@ qfs_vprintf(qf_str qfs, const char *format, va_list args) } ; /*------------------------------------------------------------------------------ - * %s handler + * %s handler -- tolerates NULL pointer * * Accepts: width * precision @@ -892,7 +915,7 @@ qfs_arg_string(qf_str qfs, va_list args, enum pf_flags flags, if (flags != (flags & pf_precision)) return pfp_failed ; - len = strlen(src) ; + len = (src != NULL) ? strlen(src) : 0 ; if (((precision > 0) || (flags & pf_precision)) && (len > precision)) len = precision ; diff --git a/lib/qfstring.h b/lib/qfstring.h index fbc83fe8..83caa13d 100644 --- a/lib/qfstring.h +++ b/lib/qfstring.h @@ -96,11 +96,12 @@ enum pf_flags */ extern void qfs_init(qf_str qfs, char* str, size_t size) ; +extern void qfs_init_as_is(qf_str qfs, char* str, size_t size) ; extern void qfs_term(qf_str qfs, const char* src) ; Inline int qfs_len(qf_str qfs) ; -Inline void* qfs_end(qf_str qfs) ; +Inline void* qfs_ptr(qf_str qfs) ; Inline int qfs_left(qf_str qfs) ; extern void qfs_append(qf_str qfs, const char* src) ; @@ -139,7 +140,7 @@ qfs_len(qf_str qfs) * Address of the terminating '\0'. */ Inline void* -qfs_end(qf_str qfs) +qfs_ptr(qf_str qfs) { return qfs->ptr ; } ; diff --git a/lib/sigevent.c b/lib/sigevent.c index a3d4219c..6e50d631 100644 --- a/lib/sigevent.c +++ b/lib/sigevent.c @@ -310,7 +310,7 @@ trap_default_signals(void) } if (sigaction(sigmap[i].sigs[j],&act,NULL) < 0) zlog_warn("Unable to set signal handler for signal %d: %s", - sigmap[i].sigs[j],safe_strerror(errno)); + sigmap[i].sigs[j], errtoa(errno, 0).str); } } @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * along with GNU Zebra; see the file COPYING. If not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. + * 02111-1307, USA. */ #include <zebra.h> @@ -45,7 +45,7 @@ enum smux_event {SMUX_SCHEDULE, SMUX_CONNECT, SMUX_READ}; void smux_event (enum smux_event, int); - + /* SMUX socket. */ int smux_sock = -1; @@ -81,7 +81,7 @@ static struct cmd_node smux_node = /* thread master */ static struct thread_master *master; - + void * oid_copy (void *dest, const void *src, size_t size) { @@ -93,7 +93,7 @@ oid2in_addr (oid oid[], int len, struct in_addr *addr) { int i; u_char *pnt; - + if (len == 0) return; @@ -108,7 +108,7 @@ oid_copy_addr (oid oid[], struct in_addr *addr, int len) { int i; u_char *pnt; - + if (len == 0) return; @@ -155,7 +155,7 @@ oid_compare_part (oid *o1, int o1_len, oid *o2, int o2_len) return 0; } - + static void smux_oid_dump (const char *prefix, const oid *oid, size_t oid_len) { @@ -205,7 +205,7 @@ smux_socket (void) } for(res=res0; res; res=res->ai_next) { - if (res->ai_family != AF_INET + if (res->ai_family != AF_INET #ifdef HAVE_IPV6 && res->ai_family != AF_INET6 #endif /* HAVE_IPV6 */ @@ -244,7 +244,7 @@ smux_socket (void) #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */ sp = getservbyname ("smux", "tcp"); - if (sp != NULL) + if (sp != NULL) serv.sin_port = sp->s_port; else serv.sin_port = htons (SMUX_PORT_DEFAULT); @@ -289,7 +289,7 @@ smux_getresp_send (oid objid[], size_t objid_len, long reqid, long errstat, /* Place holder h1 for complete sequence */ ptr = asn_build_sequence (ptr, &len, (u_char) SMUX_GETRSP, 0); h1e = ptr; - + ptr = asn_build_int (ptr, &len, (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), &reqid, sizeof (reqid)); @@ -309,12 +309,12 @@ smux_getresp_send (oid objid[], size_t objid_len, long reqid, long errstat, h2 = ptr; /* Place holder h2 for one variable */ - ptr = asn_build_sequence (ptr, &len, + ptr = asn_build_sequence (ptr, &len, (u_char)(ASN_SEQUENCE | ASN_CONSTRUCTOR), 0); h2e = ptr; - ptr = snmp_build_var_op (ptr, objid, &objid_len, + ptr = snmp_build_var_op (ptr, objid, &objid_len, val_type, arg_len, arg, &len); /* Now variable size is known, fill in size */ @@ -325,7 +325,7 @@ smux_getresp_send (oid objid[], size_t objid_len, long reqid, long errstat, if (debug_smux) zlog_debug ("SMUX getresp send: %td", (ptr - buf)); - + ret = send (smux_sock, buf, (ptr - buf), 0); } @@ -345,17 +345,17 @@ smux_var (u_char *ptr, size_t len, oid objid[], size_t *objid_len, /* Parse header. */ ptr = asn_parse_header (ptr, &len, &type); - + if (debug_smux) { zlog_debug ("SMUX var parse: type %d len %zd", type, len); - zlog_debug ("SMUX var parse: type must be %d", + zlog_debug ("SMUX var parse: type must be %d", (ASN_SEQUENCE | ASN_CONSTRUCTOR)); } /* Parse var option. */ *objid_len = MAX_OID_LEN; - ptr = snmp_parse_var_op(ptr, objid, objid_len, &val_type, + ptr = snmp_parse_var_op(ptr, objid, objid_len, &val_type, &val_len, &val, &len); if (var_val_len) @@ -473,7 +473,7 @@ smux_set (oid *reqid, size_t *reqid_len, { if (debug_smux) zlog_debug ("SMUX function call index is %d", v->magic); - + statP = (*v->findVar) (v, suffix, &suffix_len, 1, &val_len, &write_method); @@ -499,7 +499,7 @@ smux_set (oid *reqid, size_t *reqid_len, } static int -smux_get (oid *reqid, size_t *reqid_len, int exact, +smux_get (oid *reqid, size_t *reqid_len, int exact, u_char *val_type,void **val, size_t *val_len) { int j; @@ -515,7 +515,7 @@ smux_get (oid *reqid, size_t *reqid_len, int exact, /* Check */ for (ALL_LIST_ELEMENTS (treelist, node, nnode,subtree)) { - subresult = oid_compare_part (reqid, *reqid_len, + subresult = oid_compare_part (reqid, *reqid_len, subtree->name, subtree->name_len); /* Subtree matched. */ @@ -565,7 +565,7 @@ smux_get (oid *reqid, size_t *reqid_len, int exact, } static int -smux_getnext (oid *reqid, size_t *reqid_len, int exact, +smux_getnext (oid *reqid, size_t *reqid_len, int exact, u_char *val_type,void **val, size_t *val_len) { int j; @@ -588,7 +588,7 @@ smux_getnext (oid *reqid, size_t *reqid_len, int exact, /* Check */ for (ALL_LIST_ELEMENTS (treelist, node, nnode, subtree)) { - subresult = oid_compare_part (reqid, *reqid_len, + subresult = oid_compare_part (reqid, *reqid_len, subtree->name, subtree->name_len); /* If request is in the tree. The agent has to make sure we @@ -722,10 +722,10 @@ smux_parse_get (u_char *ptr, size_t len, int exact) if (debug_smux) zlog_debug ("SMUX GET message parse: len %zd", len); - + /* Parse GET message header. */ ptr = smux_parse_get_header (ptr, &len, &reqid); - + /* Parse GET message object ID. We needn't the value come */ ptr = smux_var (ptr, len, oid, &oid_len, NULL, NULL, NULL); @@ -762,7 +762,7 @@ smux_parse_rrsp (u_char *ptr, size_t len) { u_char val; long errstat; - + ptr = asn_parse_int (ptr, &len, &val, &errstat, sizeof (errstat)); if (debug_smux) @@ -818,7 +818,7 @@ process_rest: /* see note below: YYY */ else zlog_warn ("SMUX_SOUT sout_save_len=%d - invalid", (int) sout_save_len); - if (len_income > 3) + if (len_income > 3) { /* YYY: this strange code has to solve the "slow peer" problem: When agent sends SMUX_SOUT message it doesn't @@ -903,7 +903,7 @@ smux_read (struct thread *t) if (len < 0) { - zlog_warn ("Can't read all SMUX packet: %s", safe_strerror (errno)); + zlog_warn ("Can't read all SMUX packet: %s", errtoa(errno, 0).str); close (sock); smux_sock = -1; smux_event (SMUX_CONNECT, 0); @@ -963,24 +963,24 @@ smux_open (int sock) /* SMUX Open. */ version = 0; - ptr = asn_build_int (ptr, &len, + ptr = asn_build_int (ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), &version, sizeof (version)); /* SMUX connection oid. */ ptr = asn_build_objid (ptr, &len, - (u_char) + (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID), smux_oid, smux_oid_len); /* SMUX connection description. */ - ptr = asn_build_string (ptr, &len, + ptr = asn_build_string (ptr, &len, (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OCTET_STR), progname, strlen (progname)); /* SMUX connection password. */ - ptr = asn_build_string (ptr, &len, + ptr = asn_build_string (ptr, &len, (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OCTET_STR), (u_char *)smux_passwd, strlen (smux_passwd)); @@ -1019,38 +1019,38 @@ smux_trap (const oid *name, size_t namelen, /* Sub agent enterprise oid. */ ptr = asn_build_objid (ptr, &len, - (u_char) + (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID), smux_oid, smux_oid_len); /* IP address. */ addr.s_addr = 0; - ptr = asn_build_string (ptr, &len, + ptr = asn_build_string (ptr, &len, (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_IPADDRESS), (u_char *)&addr, sizeof (addr)); /* Generic trap integer. */ val = SNMP_TRAP_ENTERPRISESPECIFIC; - ptr = asn_build_int (ptr, &len, + ptr = asn_build_int (ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), (long *)&val, sizeof (val)); /* Specific trap integer. */ val = sptrap; - ptr = asn_build_int (ptr, &len, + ptr = asn_build_int (ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), (long *)&val, sizeof (val)); /* Timeticks timestamp. */ val = 0; - ptr = asn_build_unsigned_int (ptr, &len, + ptr = asn_build_unsigned_int (ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_TIMETICKS), &val, sizeof (val)); - + /* Variables. */ h1 = ptr; - ptr = asn_build_sequence (ptr, &len, + ptr = asn_build_sequence (ptr, &len, (u_char) (ASN_SEQUENCE | ASN_CONSTRUCTOR), 0); @@ -1067,27 +1067,27 @@ smux_trap (const oid *name, size_t namelen, u_char val_type; /* Make OID. */ - if (trapobj[i].namelen > 0) + if (trapobj[i].namelen > 0) { oid_copy (oid, name, namelen); oid_copy (oid + namelen, trapobj[i].name, trapobj[i].namelen); oid_copy (oid + namelen + trapobj[i].namelen, iname, inamelen); oid_len = namelen + trapobj[i].namelen + inamelen; } - else + else { oid_copy (oid, name, namelen); oid_copy (oid + namelen, trapobj[i].name, trapobj[i].namelen * (-1)); oid_len = namelen + trapobj[i].namelen * (-1) ; } - if (debug_smux) + if (debug_smux) { smux_oid_dump ("Trap", name, namelen); if (trapobj[i].namelen < 0) - smux_oid_dump ("Trap", + smux_oid_dump ("Trap", trapobj[i].name, (- 1) * (trapobj[i].namelen)); - else + else { smux_oid_dump ("Trap", trapobj[i].name, (trapobj[i].namelen)); smux_oid_dump ("Trap", iname, inamelen); @@ -1148,13 +1148,13 @@ smux_register (int sock) /* Priority. */ priority = -1; - ptr = asn_build_int (ptr, &len, + ptr = asn_build_int (ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), &priority, sizeof (priority)); /* Operation. */ operation = 2; /* Register R/W */ - ptr = asn_build_int (ptr, &len, + ptr = asn_build_int (ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), &operation, sizeof (operation)); @@ -1199,7 +1199,7 @@ smux_connect (struct thread *t) ret = smux_open (smux_sock); if (ret < 0) { - zlog_warn ("SMUX open message send failed: %s", safe_strerror (errno)); + zlog_warn ("SMUX open message send failed: %s", errtoa(errno, 0).str); close (smux_sock); smux_sock = -1; if (++fail < SMUX_MAX_FAILURE) @@ -1211,7 +1211,7 @@ smux_connect (struct thread *t) ret = smux_register (smux_sock); if (ret < 0) { - zlog_warn ("SMUX register message send failed: %s", safe_strerror (errno)); + zlog_warn ("SMUX register message send failed: %s", errtoa(errno, 0).str); close (smux_sock); smux_sock = -1; if (++fail < SMUX_MAX_FAILURE) @@ -1247,7 +1247,7 @@ smux_stop (void) smux_sock = -1; } } - + void @@ -1268,7 +1268,7 @@ smux_event (enum smux_event event, int sock) break; } } - + static int smux_str2oid (const char *str, oid *oid, size_t *oid_len) { @@ -1395,7 +1395,7 @@ smux_peer_default (void) free (smux_oid); smux_oid = NULL; } - + /* careful, smux_passwd might be pointing at string constant */ if (smux_passwd) { @@ -1488,8 +1488,8 @@ config_write_smux (struct vty *vty) /* Register subtree to smux master tree. */ void -smux_register_mib (const char *descr, struct variable *var, - size_t width, int num, +smux_register_mib (const char *descr, struct variable *var, + size_t width, int num, oid name[], size_t namelen) { struct subtree *tree; @@ -1508,7 +1508,7 @@ smux_register_mib (const char *descr, struct variable *var, static int smux_tree_cmp(struct subtree *tree1, struct subtree *tree2) { - return oid_compare(tree1->name, tree1->name_len, + return oid_compare(tree1->name, tree1->name_len, tree2->name, tree2->name_len); } @@ -1518,7 +1518,7 @@ smux_init (struct thread_master *tm) { /* copy callers thread master */ master = tm; - + /* Make MIB tree. */ treelist = list_new(); treelist->cmp = (int (*)(void *, void *))smux_tree_cmp; diff --git a/lib/sockopt.c b/lib/sockopt.c index ad4af9af..966ba260 100644 --- a/lib/sockopt.c +++ b/lib/sockopt.c @@ -23,6 +23,7 @@ #include "log.h" #include "sockopt.h" #include "sockunion.h" +#include "pthread_safe.h" int setsockopt_so_recvbuf (int sock_fd, int size) @@ -34,7 +35,7 @@ setsockopt_so_recvbuf (int sock_fd, int size) { int err = errno ; zlog_err ("socket %d: cannot setsockopt SO_RCVBUF to %d: %s", - sock_fd, size, safe_strerror(err)) ; + sock_fd, size, errtoa(err, 0).str) ; errno = err ; } ; @@ -52,7 +53,7 @@ setsockopt_so_sendbuf (const int sock_fd, int size) { int err = errno ; zlog_err ("socket %d: cannot setsockopt SO_SNDBUF to %d: %s", - sock_fd, size, safe_strerror (err)); + sock_fd, size, errtoa(err, 0).str) ; errno = err ; } ; @@ -70,7 +71,7 @@ getsockopt_so_sendbuf (const int sock_fd) { int err = errno ; zlog_err ("socket %d: cannot getsockopt SO_SNDBUF: %s", - sock_fd, safe_strerror (err)); + sock_fd, errtoa(err, 0).str) ; errno = err ; return ret; } @@ -105,7 +106,7 @@ setsockopt_ipv6_pktinfo (int sock_fd, int val) if (ret < 0) { int err = errno ; - zlog_warn ("cannot setsockopt IPV6_RECVPKTINFO: %s", safe_strerror (err)); + zlog_warn ("cannot setsockopt IPV6_RECVPKTINFO: %s", errtoa(err, 0).str); errno = err ; } ; #else /*RFC2292*/ @@ -113,7 +114,7 @@ setsockopt_ipv6_pktinfo (int sock_fd, int val) if (ret < 0) { int err = errno ; - zlog_warn ("cannot setsockopt IPV6_PKTINFO: %s", safe_strerror (err)); + zlog_warn ("cannot setsockopt IPV6_PKTINFO: %s", errtoa(err, 0).str); errno = err ; } ; #endif /* INIA_IPV6 */ @@ -134,7 +135,7 @@ setsockopt_ipv6_checksum (int sock_fd, int val) if (ret < 0) { int err = errno ; - zlog_warn ("cannot setsockopt IPV6_CHECKSUM: %s", safe_strerror (err)); + zlog_warn ("cannot setsockopt IPV6_CHECKSUM: %s", errtoa(err, 0).str); errno = err ; } ; return ret; @@ -152,7 +153,7 @@ setsockopt_ipv6_multicast_hops (int sock_fd, int val) { int err = errno ; zlog_warn ("cannot setsockopt IPV6_MULTICAST_HOPS: %s", - safe_strerror (err)); + errtoa(err, 0).str); errno = err ; } ; return ret; @@ -168,7 +169,7 @@ setsockopt_ipv6_unicast_hops (int sock_fd, int val) if (ret < 0) { int err = errno ; - zlog_warn("cannot setsockopt IPV6_UNICAST_HOPS: %s", safe_strerror (err)); + zlog_warn("cannot setsockopt IPV6_UNICAST_HOPS: %s", errtoa(err, 0).str); errno = err ; } ; return ret; @@ -185,7 +186,7 @@ setsockopt_ipv6_hoplimit (int sock_fd, int val) if (ret < 0) { int err = errno ; - zlog_warn("cannot setsockopt IPV6_RECVHOPLIMIT: %s", safe_strerror (err)); + zlog_warn("cannot setsockopt IPV6_RECVHOPLIMIT: %s", errtoa(err, 0).str); errno = err ; } ; #else /*RFC2292*/ @@ -193,7 +194,7 @@ setsockopt_ipv6_hoplimit (int sock_fd, int val) if (ret < 0) { int err = errno ; - zlog_warn ("cannot setsockopt IPV6_HOPLIMIT: %s", safe_strerror (err)); + zlog_warn ("cannot setsockopt IPV6_HOPLIMIT: %s", errtoa(err, 0).str); errno = err ; } ; #endif @@ -212,7 +213,7 @@ setsockopt_ipv6_multicast_loop (int sock_fd, int val) { int err = errno ; zlog_warn ("cannot setsockopt IPV6_MULTICAST_LOOP: %s", - safe_strerror (err)); + errtoa(err, 0).str); errno = err ; } ; return ret; @@ -375,7 +376,7 @@ setsockopt_ipv4_ifindex (int sock_fd, int val) { int err = errno ; zlog_warn ("Can't set IP_PKTINFO option for fd %d to %d: %s", - sock_fd, val, safe_strerror(err)); + sock_fd, val, errtoa(err, 0).str); errno = err ; } ; #elif defined (IP_RECVIF) @@ -384,7 +385,7 @@ setsockopt_ipv4_ifindex (int sock_fd, int val) { int err = errno ; zlog_warn ("Can't set IP_RECVIF option for fd %d to %d: %s", - sock_fd, val, safe_strerror(err)); + sock_fd, val, errtoa(err, 0).str); errno = err ; } ; #else @@ -407,7 +408,7 @@ setsockopt_ipv4_tos(int sock_fd, int tos) { int err = errno ; zlog_warn ("Can't set IP_TOS option for fd %d to %#x: %s", - sock_fd, tos, safe_strerror(err)); + sock_fd, tos, errtoa(err, 0).str); errno = err ; } ; return ret; @@ -666,7 +667,7 @@ sockopt_tcp_signature (int sock_fd, union sockunion *su, const char *password) else { zlog_err ("sockopt_tcp_signature: setsockopt(%d): %s", - sock_fd, safe_strerror(err)); + sock_fd, errtoa(err, 0).str) ; errno = err ; } ; } @@ -728,7 +729,7 @@ sockopt_ttl (int sock_fd, int ttl) int err = errno ; zlog (NULL, LOG_WARNING, "cannot set sockopt %s %d to socket %d: %s", msg, ttl, sock_fd, - safe_strerror(err)) ; + errtoa(err, 0).str) ; errno = err ; return -1 ; } ; diff --git a/lib/sockunion.c b/lib/sockunion.c index 95626513..23287cd2 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -306,6 +306,18 @@ sockunion2str (union sockunion *su, char *buf, size_t size) } /*------------------------------------------------------------------------------ + * Fill in and return a sockunion_string + */ +extern sockunion_string_t +sutoa(sockunion su) +{ + sockunion_string_t sus ; + + sockunion2str(su, sus.str, sizeof(sus.str)) ; + return sus ; +} ; + +/*------------------------------------------------------------------------------ * From the given string, construct and fill in a sockunion. * * Returns: NULL => not a valid address (or not a known address family) @@ -335,9 +347,7 @@ sockunion_str2su (const char *str) extern char * sockunion_su2str (union sockunion *su, enum MTYPE type) { - char buf[SU_ADDRSTRLEN]; - - return XSTRDUP (type, sockunion2str(su, buf, sizeof(buf))) ; + return XSTRDUP (type, sutoa(su).str) ; } /*------------------------------------------------------------------------------ @@ -445,8 +455,8 @@ sockunion_socket(sa_family_t family, int type, int protocol) err = errno ; zlog (NULL, LOG_WARNING, - "Can't make socket family=%d, type=%d, protocol=%d : %s", - (int)family, type, protocol, safe_strerror(err)) ; + "Can't make socket family=%d, type=%d, protocol=%d: %s", + (int)family, type, protocol, errtoa(err, 0).str) ; errno = err ; return -1; } @@ -484,7 +494,6 @@ extern int sockunion_connect(int sock_fd, union sockunion* peer_su, unsigned short port, unsigned int ifindex) { - char buf[SU_ADDRSTRLEN] ; union sockunion su ; int ret, err ; int sa_len ; @@ -519,8 +528,8 @@ sockunion_connect(int sock_fd, union sockunion* peer_su, unsigned short port, if ((err == 0) || (err == EINPROGRESS)) return 0 ; /* instant success or EINPROGRESS as expected */ - zlog_info("cannot connect to %s port %d socket %d : %s", - sockunion2str(&su, buf, sizeof(buf)), port, sock_fd, safe_strerror(err)) ; + zlog_info("cannot connect to %s port %d socket %d: %s", + sutoa(&su).str, port, sock_fd, errtoa(err, 0).str) ; errno = err ; return ret ; @@ -545,8 +554,8 @@ sockunion_listen(int sock_fd, int backlog) return 0 ; err = errno ; - zlog (NULL, LOG_WARNING, "cannot listen on socket %d : %s", - sock_fd, safe_strerror(err)) ; + zlog (NULL, LOG_WARNING, "cannot listen on socket %d: %s", + sock_fd, errtoa(err, 0).str) ; errno = err ; return ret ; @@ -574,7 +583,6 @@ sockunion_bind (int sock_fd, union sockunion *su, unsigned short port, { int sa_len ; int ret ; - char buf[SU_ADDRSTRLEN] ; if (any == NULL) sockunion_set_addr_any(su) ; @@ -585,9 +593,8 @@ sockunion_bind (int sock_fd, union sockunion *su, unsigned short port, if (ret < 0) { int err = errno ; - zlog (NULL, LOG_WARNING, "cannot bind to %s port %d socket %d : %s", - sockunion2str(su, buf, sizeof(buf)), port, sock_fd, - safe_strerror(err)) ; + zlog (NULL, LOG_WARNING, "cannot bind to %s port %d socket %d: %s", + sutoa(su).str, port, sock_fd, errtoa(err, 0).str) ; errno = err ; } ; @@ -614,8 +621,8 @@ sockopt_reuseaddr (int sock_fd) { int err = errno ; zlog (NULL, LOG_WARNING, - "cannot set sockopt SO_REUSEADDR to socket %d %s", sock_fd, - safe_strerror(err)); + "cannot set sockopt SO_REUSEADDR to socket %d: %s", sock_fd, + errtoa(err, 0).str) ; errno = err ; } ; @@ -648,7 +655,7 @@ sockopt_reuseport (int sock_fd) int err = errno ; zlog (NULL, LOG_WARNING, "cannot set sockopt SO_REUSEPORT to socket %d: %s", sock_fd, - safe_strerror(err)); + errtoa(err, 0).str) ; errno = err ; } ; @@ -711,7 +718,7 @@ sockunion_getsockfamily(int sock_fd) { int err = errno ; zlog_warn ("Failed in getsockname for socket %d: %s", - sock_fd, safe_strerror(err)) ; + sock_fd, errtoa(err, 0).str) ; errno = err ; return -1 ; } ; @@ -758,7 +765,7 @@ sockunion_get_name(int sock_fd, union sockunion* su, int local) { int err = errno ; zlog_warn ("Cannot get %s address and port: %s", - local ? "local" : "remote", safe_strerror(err)) ; + local ? "local" : "remote", errtoa(err, 0).str) ; errno = err ; return ret ; } diff --git a/lib/sockunion.h b/lib/sockunion.h index 3f71cb55..3823c522 100644 --- a/lib/sockunion.h +++ b/lib/sockunion.h @@ -70,6 +70,13 @@ CONFIRM(SU_ADDRSTRLEN >= INET_ADDRSTRLEN) ; CONFIRM(SU_ADDRSTRLEN >= INET6_ADDRSTRLEN) ; #endif +/* Sockunion String Object */ +typedef struct sockunion_string sockunion_string_t ; +struct sockunion_string +{ + char str[SU_ADDRSTRLEN] ; +}; + /* Macro to set link local index to the IPv6 address. For KAME IPv6 stack. */ #ifdef KAME @@ -96,6 +103,7 @@ CONFIRM(SU_ADDRSTRLEN >= INET6_ADDRSTRLEN) ; extern sockunion sockunion_init_new(sockunion su, sa_family_t family) ; extern int str2sockunion (const char *, union sockunion *); extern const char *sockunion2str (union sockunion *, char *, size_t); +extern sockunion_string_t sutoa(sockunion su) ; extern int sockunion_cmp (union sockunion *, union sockunion *); extern int sockunion_same (union sockunion *, union sockunion *); diff --git a/lib/stream.c b/lib/stream.c index b4c16977..1fce7103 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -853,7 +853,7 @@ stream_read_try(struct stream *s, int fd, size_t size) /* Error: was it transient (return -2) or fatal (return -1)? */ if (ERRNO_IO_RETRY(errno)) return -2; - zlog_warn("%s: read failed on fd %d: %s", __func__, fd, safe_strerror(errno)); + zlog_warn("%s: read failed on fd %d: %s", __func__, fd, errtoa(errno, 0).str); return -1; } @@ -885,7 +885,7 @@ stream_recvfrom (struct stream *s, int fd, size_t size, int flags, /* Error: was it transient (return -2) or fatal (return -1)? */ if (ERRNO_IO_RETRY(errno)) return -2; - zlog_warn("%s: read failed on fd %d: %s", __func__, fd, safe_strerror(errno)); + zlog_warn("%s: read failed on fd %d: %s", __func__, fd, errtoa(errno, 0).str); return -1; } diff --git a/lib/thread.c b/lib/thread.c index 3df9acf7..7a9a3a60 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -1175,7 +1175,7 @@ thread_fetch (struct thread_master *m, struct thread *fetch) { if (errno == EINTR) continue; /* signal received - process it */ - zlog_warn ("select() error: %s", safe_strerror (errno)); + zlog_warn ("select() error: %s", errtoa(errno, 0).str); return NULL; } @@ -1157,7 +1157,7 @@ vty_read_config_first_cmd_special(char *config_file, if (confp == NULL) { fprintf (stderr, "%s: failed to open configuration file %s: %s\n", - __func__, fullpath, safe_strerror (errno)); + __func__, fullpath, errtostr(errno, 0).str); confp = vty_use_backup_config (fullpath); if (confp) diff --git a/lib/vty_io.c b/lib/vty_io.c index 7137fbdc..af61e97c 100644 --- a/lib/vty_io.c +++ b/lib/vty_io.c @@ -1248,7 +1248,7 @@ uty_sock_error(vty_io vio, const char* what) vio->sock.error_seen = errno ; uzlog(NULL, LOG_WARNING, "%s: %s failed on fd %d: %s", - type, what, vio->sock.fd, safe_strerror(vio->sock.error_seen)) ; + type, what, vio->sock.fd, errtoa(vio->sock.error_seen, 0).str) ; } ; return -1 ; @@ -2179,7 +2179,7 @@ uty_serv_vtysh(const char *path) if (sock < 0) { uzlog(NULL, LOG_ERR, "Cannot create unix stream socket: %s", - safe_strerror(errno)); + errtoa(errno, 0).str) ; return -1 ; } @@ -2198,7 +2198,7 @@ uty_serv_vtysh(const char *path) ret = bind (sock, (struct sockaddr *) &sa_un, sa_len) ; if (ret < 0) - uzlog(NULL, LOG_ERR, "Cannot bind path %s: %s", path, safe_strerror(errno)); + uzlog(NULL, LOG_ERR, "Cannot bind path %s: %s", path, errtoa(errno, 0).str); if (ret >= 0) ret = set_nonblocking(sock); @@ -2208,7 +2208,7 @@ uty_serv_vtysh(const char *path) ret = listen (sock, 5); if (ret < 0) uzlog(NULL, LOG_ERR, "listen(fd %d) failed: %s", sock, - safe_strerror(errno)); + errtoa(errno, 0).str) ; } ; zprivs_get_ids(&ids); @@ -2218,7 +2218,7 @@ uty_serv_vtysh(const char *path) /* set group of socket */ if ( chown (path, -1, ids.gid_vty) ) uzlog (NULL, LOG_ERR, "uty_serv_vtysh: could chown socket, %s", - safe_strerror (errno) ); + errtoa(errno, 0).str) ; } umask (old_mask); @@ -2322,33 +2322,32 @@ uty_accept(vty_listener listener, int listen_sock) static int uty_accept_term(vty_listener listener) { - int sock; + int sock_fd; union sockunion su; int ret; unsigned int on; struct prefix *p ; - char buf[SU_ADDRSTRLEN] ; VTY_ASSERT_LOCKED() ; /* We can handle IPv4 or IPv6 socket. */ sockunion_init_new(&su, AF_UNSPEC) ; - sock = sockunion_accept (listener->sock.fd, &su); + sock_fd = sockunion_accept (listener->sock.fd, &su); - if (sock < 0) + if (sock_fd < 0) { - if (sock == -1) + if (sock_fd == -1) uzlog (NULL, LOG_WARNING, "can't accept vty socket : %s", - safe_strerror (errno)); + errtoa(errno, 0).str) ; return -1; } /* Really MUST have non-blocking */ - ret = set_nonblocking(sock) ; /* issues WARNING if fails */ + ret = set_nonblocking(sock_fd) ; /* issues WARNING if fails */ if (ret < 0) { - close(sock) ; + close(sock_fd) ; return -1 ; } ; @@ -2382,26 +2381,25 @@ uty_accept_term(vty_listener listener) if (ret != 0) { - uzlog (NULL, LOG_INFO, "Vty connection refused from %s", - sockunion2str (&su, buf, sizeof(buf))); - close (sock); + uzlog (NULL, LOG_INFO, "Vty connection refused from %s", sutoa(&su).str) ; + close (sock_fd); return 0; } ; /* Final options (optional) */ on = 1 ; - ret = setsockopt (sock, IPPROTO_TCP, TCP_NODELAY, + ret = setsockopt (sock_fd, IPPROTO_TCP, TCP_NODELAY, (void*)&on, sizeof (on)); if (ret < 0) - uzlog (NULL, LOG_INFO, "can't set sockopt to sock %d: %s", - (int)sock, safe_strerror (errno)); + uzlog (NULL, LOG_INFO, "can't set sockopt to socket %d: %s", + sock_fd, errtoa(errno, 0).str) ; /* All set -- create the VTY_TERM */ - uty_new_term(sock, &su); + uty_new_term(sock_fd, &su); /* Log new VTY */ - uzlog (NULL, LOG_INFO, "Vty connection from %s (fd %d)", - sockunion2str (&su, buf, sizeof(buf)), sock); + uzlog (NULL, LOG_INFO, "Vty connection from %s (fd %d)", sutoa(&su).str, + sock_fd) ; return 0; } @@ -2412,7 +2410,7 @@ uty_accept_term(vty_listener listener) static int uty_accept_shell_serv (vty_listener listener) { - int sock ; + int sock_fd ; int ret ; int client_len ; struct sockaddr_un client ; @@ -2422,21 +2420,21 @@ uty_accept_shell_serv (vty_listener listener) client_len = sizeof(client); memset (&client, 0, client_len); - sock = accept(listener->sock.fd, (struct sockaddr *) &client, + sock_fd = accept(listener->sock.fd, (struct sockaddr *) &client, (socklen_t *) &client_len) ; - if (sock < 0) + if (sock_fd < 0) { uzlog (NULL, LOG_WARNING, "can't accept vty shell socket : %s", - safe_strerror (errno)); + errtoa(errno, 0).str) ; return -1; } /* Really MUST have non-blocking */ - ret = set_nonblocking(sock) ; /* issues WARNING if fails */ + ret = set_nonblocking(sock_fd) ; /* issues WARNING if fails */ if (ret < 0) { - close(sock) ; + close(sock_fd) ; return -1 ; } ; @@ -2444,10 +2442,10 @@ uty_accept_shell_serv (vty_listener listener) if (VTYSH_DEBUG) printf ("VTY shell accept\n"); - uty_new_shell_serv(sock) ; + uty_new_shell_serv(sock_fd) ; /* Log new VTY */ - uzlog (NULL, LOG_INFO, "Vty shell connection (fd %d)", sock); + uzlog (NULL, LOG_INFO, "Vty shell connection (fd %d)", sock_fd); return 0; } |