Restructured error,debug anf log API
Renamed functions clicon->clixon, replaced global variables w access functions Unified clicon_netconf_error with clixon_err()
This commit is contained in:
parent
261469be16
commit
24a4991ec8
199 changed files with 4668 additions and 4158 deletions
|
|
@ -41,8 +41,12 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_netns.h"
|
||||
|
||||
#ifdef HAVE_SETNS
|
||||
|
|
@ -70,7 +74,7 @@ send_sock(int usock,
|
|||
memcpy(fdptr,&fd,sizeof(fd));
|
||||
msg.msg_controllen=CMSG_SPACE(sizeof(fd));
|
||||
if (sendmsg(usock, &msg, 0) < 0){
|
||||
clicon_err(OE_UNIX, errno, "sendmsg");
|
||||
clixon_err(OE_UNIX, errno, "sendmsg");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -96,7 +100,7 @@ get_sock(int usock,
|
|||
msg.msg_controllen=sizeof(buf);
|
||||
/* Block here */
|
||||
if (recvmsg(usock, &msg, 0) < 0){
|
||||
clicon_err(OE_UNIX, errno, "recvmsg");
|
||||
clixon_err(OE_UNIX, errno, "recvmsg");
|
||||
goto done;
|
||||
}
|
||||
cmsg=CMSG_FIRSTHDR(&msg);
|
||||
|
|
@ -133,7 +137,7 @@ create_socket(struct sockaddr *sa,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (sock == NULL){
|
||||
clicon_err(OE_PROTO, EINVAL, "Requires socket output parameter");
|
||||
clixon_err(OE_PROTO, EINVAL, "Requires socket output parameter");
|
||||
goto done;
|
||||
}
|
||||
/* create inet socket */
|
||||
|
|
@ -146,39 +150,39 @@ create_socket(struct sockaddr *sa,
|
|||
|
||||
if ((s = socket(sa->sa_family, flags,
|
||||
0)) < 0) {
|
||||
clicon_err(OE_UNIX, errno, "socket");
|
||||
clixon_err(OE_UNIX, errno, "socket");
|
||||
goto done;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
if (fcntl(s, O_CLOEXEC)) {
|
||||
clicon_err(OE_UNIX, errno, "fcntl");
|
||||
clixon_err(OE_UNIX, errno, "fcntl");
|
||||
goto done;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on)) == -1) {
|
||||
clicon_err(OE_UNIX, errno, "setsockopt SO_KEEPALIVE");
|
||||
clixon_err(OE_UNIX, errno, "setsockopt SO_KEEPALIVE");
|
||||
goto done;
|
||||
}
|
||||
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)) == -1) {
|
||||
clicon_err(OE_UNIX, errno, "setsockopt SO_REUSEADDR");
|
||||
clixon_err(OE_UNIX, errno, "setsockopt SO_REUSEADDR");
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* only bind ipv6, otherwise it may bind to ipv4 as well which is strange but seems default */
|
||||
if (sa->sa_family == AF_INET6 &&
|
||||
setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) {
|
||||
clicon_err(OE_UNIX, errno, "setsockopt IPPROTO_IPV6");
|
||||
clixon_err(OE_UNIX, errno, "setsockopt IPPROTO_IPV6");
|
||||
goto done;
|
||||
}
|
||||
if (bind(s, sa, sin_len) == -1) {
|
||||
/* Note may be ignored in upper layer by checking for EADDRNOTAVAIL, see eg restconf_openssl_init */
|
||||
clicon_err(OE_UNIX, errno, "bind(%s)", addrstr);
|
||||
clixon_err(OE_UNIX, errno, "bind(%s)", addrstr);
|
||||
goto done;
|
||||
}
|
||||
if (listen(s, backlog ) < 0){
|
||||
clicon_err(OE_UNIX, errno, "listen");
|
||||
clixon_err(OE_UNIX, errno, "listen");
|
||||
goto done;
|
||||
}
|
||||
if (sock)
|
||||
|
|
@ -228,18 +232,18 @@ fork_netns_socket(const char *netns,
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s %s", __FUNCTION__, netns);
|
||||
if (socketpair(AF_UNIX, sock_flags, 0, sp) < 0){
|
||||
clicon_err(OE_UNIX, errno, "socketpair");
|
||||
clixon_err(OE_UNIX, errno, "socketpair");
|
||||
goto done;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
if (fcntl(sp[0], O_CLOEXEC)) {
|
||||
clicon_err(OE_UNIX, errno, "fcntl, sp[0]");
|
||||
clixon_err(OE_UNIX, errno, "fcntl, sp[0]");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (fcntl(sp[1], O_CLOEXEC)) {
|
||||
clicon_err(OE_UNIX, errno, "fcntl, sp[1]");
|
||||
clixon_err(OE_UNIX, errno, "fcntl, sp[1]");
|
||||
goto done;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -247,11 +251,11 @@ fork_netns_socket(const char *netns,
|
|||
/* Check namespace exists */
|
||||
sprintf(nspath,"/var/run/netns/%s", netns);
|
||||
if (stat(nspath, &st) < 0){
|
||||
clicon_err(OE_UNIX, errno, ": stat(%s)", nspath);
|
||||
clixon_err(OE_UNIX, errno, ": stat(%s)", nspath);
|
||||
goto done;
|
||||
}
|
||||
if ((child = fork()) < 0) {
|
||||
clicon_err(OE_UNIX, errno, "fork");
|
||||
clixon_err(OE_UNIX, errno, "fork");
|
||||
goto done;
|
||||
}
|
||||
if (child == 0) { /* Child */
|
||||
|
|
@ -261,13 +265,13 @@ fork_netns_socket(const char *netns,
|
|||
close(sp[0]);
|
||||
/* Switch to namespace */
|
||||
if ((fd=open(nspath, O_RDONLY)) < 0) {
|
||||
clicon_err(OE_UNIX, errno, "open(%s)", nspath);
|
||||
clixon_err(OE_UNIX, errno, "open(%s)", nspath);
|
||||
send_sock(sp[1], sp[1]); /* Dummy to wake parent */
|
||||
exit(1); /* Dont do return here, need to exit child */
|
||||
}
|
||||
#ifdef HAVE_SETNS
|
||||
if (setns(fd, CLONE_NEWNET) < 0){
|
||||
clicon_err(OE_UNIX, errno, "setns(%s)", netns);
|
||||
clixon_err(OE_UNIX, errno, "setns(%s)", netns);
|
||||
send_sock(sp[1], sp[1]); /* Dummy to wake parent */
|
||||
exit(1); /* Dont do return here, need to exit child */
|
||||
}
|
||||
|
|
@ -295,7 +299,7 @@ fork_netns_socket(const char *netns,
|
|||
if (WEXITSTATUS(wstatus)){
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s wstatus:%d", __FUNCTION__, WEXITSTATUS(wstatus));
|
||||
*sock = -1;
|
||||
clicon_err(OE_UNIX, EADDRNOTAVAIL, "bind(%s)", addrstr);
|
||||
clixon_err(OE_UNIX, EADDRNOTAVAIL, "bind(%s)", addrstr);
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -339,7 +343,7 @@ clixon_netns_socket(const char *netns,
|
|||
if (fork_netns_socket(netns, sa, sin_len, backlog, flags, addrstr, sock) < 0)
|
||||
goto done;
|
||||
#else
|
||||
clicon_err(OE_UNIX, errno, "No namespace support on platform: %s", netns);
|
||||
clixon_err(OE_UNIX, errno, "No namespace support on platform: %s", netns);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue