From 742d01a4f9a32f17561104ee7da8971c1bcdd703 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 8 Feb 2017 17:09:55 +0100 Subject: lib: Log to the logging system This removes the logfile and outputs log messages to the logging system. The creation of the logfiles (as well as the ap_init() call) were moved into ipcp_init() to simplify the IPCP creation and shutdown. Fixes #25 Fixes #27 --- src/ipcpd/ipcp.c | 137 ++++++------- src/ipcpd/ipcp.h | 4 +- src/ipcpd/local/main.c | 72 +++---- src/ipcpd/normal/addr_auth.c | 6 +- src/ipcpd/normal/enroll.c | 56 +++--- src/ipcpd/normal/fmgr.c | 42 ++-- src/ipcpd/normal/frct.c | 18 +- src/ipcpd/normal/gam.c | 22 +-- src/ipcpd/normal/main.c | 141 +++++++------- src/ipcpd/normal/pol/flat.c | 14 +- src/ipcpd/normal/ribmgr.c | 10 +- src/ipcpd/shim-eth-llc/main.c | 127 ++++++------ src/ipcpd/shim-udp/main.c | 165 ++++++++-------- src/ipcpd/shim-udp/tests/shim_udp_test.c | 14 +- src/ipcpd/timerwheel.c | 10 +- src/irmd/ipcp.c | 39 ++-- src/irmd/irm_flow.c | 6 +- src/irmd/main.c | 322 +++++++++++++++---------------- src/irmd/registry.c | 14 +- src/lib/bitmap.c | 3 - src/lib/irm.c | 8 +- src/lib/logs.c | 20 +- src/nsmd/main.c | 2 +- 23 files changed, 599 insertions(+), 653 deletions(-) (limited to 'src') diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index 53213c39..42720867 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -85,11 +85,11 @@ static void * ipcp_main_loop(void * o) if (setsockopt(lsockfd, SOL_SOCKET, SO_RCVTIMEO, (void *) <v, sizeof(ltv))) - LOG_WARN("Failed to set timeout on socket."); + log_warn("Failed to set timeout on socket."); count = read(lsockfd, buf, IPCP_MSG_BUF_SIZE); if (count <= 0) { - LOG_ERR("Failed to read from socket"); + log_err("Failed to read from socket"); close(lsockfd); continue; } @@ -103,7 +103,7 @@ static void * ipcp_main_loop(void * o) switch (msg->code) { case IPCP_MSG_CODE__IPCP_BOOTSTRAP: if (ipcpi.ops->ipcp_bootstrap == NULL) { - LOG_ERR("Bootstrap unsupported."); + log_err("Bootstrap unsupported."); break; } conf_msg = msg->conf; @@ -140,7 +140,7 @@ static void * ipcp_main_loop(void * o) break; case IPCP_MSG_CODE__IPCP_ENROLL: if (ipcpi.ops->ipcp_enroll == NULL) { - LOG_ERR("Enroll unsupported."); + log_err("Enroll unsupported."); break; } ret_msg.has_result = true; @@ -149,7 +149,7 @@ static void * ipcp_main_loop(void * o) break; case IPCP_MSG_CODE__IPCP_NAME_REG: if (ipcpi.ops->ipcp_name_reg == NULL) { - LOG_ERR("Ap_reg unsupported."); + log_err("Ap_reg unsupported."); break; } ret_msg.has_result = true; @@ -158,7 +158,7 @@ static void * ipcp_main_loop(void * o) break; case IPCP_MSG_CODE__IPCP_NAME_UNREG: if (ipcpi.ops->ipcp_name_unreg == NULL) { - LOG_ERR("Ap_unreg unsupported."); + log_err("Ap_unreg unsupported."); break; } ret_msg.has_result = true; @@ -167,7 +167,7 @@ static void * ipcp_main_loop(void * o) break; case IPCP_MSG_CODE__IPCP_NAME_QUERY: if (ipcpi.ops->ipcp_name_query == NULL) { - LOG_ERR("Ap_query unsupported."); + log_err("Ap_query unsupported."); break; } ret_msg.has_result = true; @@ -176,12 +176,12 @@ static void * ipcp_main_loop(void * o) break; case IPCP_MSG_CODE__IPCP_FLOW_ALLOC: if (ipcpi.ops->ipcp_flow_alloc == NULL) { - LOG_ERR("Flow_alloc unsupported."); + log_err("Flow_alloc unsupported."); break; } fd = np1_flow_alloc(msg->api, msg->port_id); if (fd < 0) { - LOG_ERR("Failed allocating fd on port_id %d.", + log_err("Failed allocating fd on port_id %d.", msg->port_id); ret_msg.has_result = true; ret_msg.result = -1; @@ -197,14 +197,14 @@ static void * ipcp_main_loop(void * o) break; case IPCP_MSG_CODE__IPCP_FLOW_ALLOC_RESP: if (ipcpi.ops->ipcp_flow_alloc_resp == NULL) { - LOG_ERR("Flow_alloc_resp unsupported."); + log_err("Flow_alloc_resp unsupported."); break; } if (!msg->response) { fd = np1_flow_resp(msg->port_id); if (fd < 0) { - LOG_WARN("Port_id %d is not known.", + log_warn("Port_id %d is not known.", msg->port_id); ret_msg.has_result = true; ret_msg.result = -1; @@ -218,13 +218,13 @@ static void * ipcp_main_loop(void * o) break; case IPCP_MSG_CODE__IPCP_FLOW_DEALLOC: if (ipcpi.ops->ipcp_flow_dealloc == NULL) { - LOG_ERR("Flow_dealloc unsupported."); + log_err("Flow_dealloc unsupported."); break; } fd = np1_flow_dealloc(msg->port_id); if (fd < 0) { - LOG_WARN("Could not deallocate port_id %d.", + log_warn("Could not deallocate port_id %d.", msg->port_id); ret_msg.has_result = true; ret_msg.result = -1; @@ -236,7 +236,7 @@ static void * ipcp_main_loop(void * o) ipcpi.ops->ipcp_flow_dealloc(fd); break; default: - LOG_ERR("Don't know that message code"); + log_err("Don't know that message code"); break; } @@ -244,7 +244,7 @@ static void * ipcp_main_loop(void * o) buffer.len = ipcp_msg__get_packed_size(&ret_msg); if (buffer.len == 0) { - LOG_ERR("Failed to send reply message"); + log_err("Failed to send reply message"); close(lsockfd); continue; } @@ -270,14 +270,61 @@ static void * ipcp_main_loop(void * o) return (void *) 0; } -int ipcp_init(enum ipcp_type type, +static int parse_args(int argc, + char * argv[], + bool * log) +{ + *log = false; + + if (!(argc == 4 || argc == 3)) + return -1; + + /* argument 1: api of irmd */ + if (atoi(argv[1]) == 0) + return -1; + + ipcpi.irmd_api = atoi(argv[1]); + + /* argument 2: IPCP name */ + ipcpi.name = argv[2]; + + /* argument 3: syslog */ + if (argv[3] != NULL) + *log = true; + + return 0; +} + +int ipcp_init(int argc, + char ** argv, + enum ipcp_type type, struct ipcp_ops * ops) { + bool log; pthread_condattr_t cattr; struct timeval tv = {(IPCP_ACCEPT_TIMEOUT / 1000), (IPCP_ACCEPT_TIMEOUT % 1000) * 1000}; + if (parse_args(argc, argv, &log)) { + log_err("Failed to parse arguments."); + return -1; + } + + log_init(log); + + if (type == IPCP_NORMAL) { + if (ap_init(argv[0])) { + log_err("Failed to init normal IPCP."); + return -1; + } + } else { + if (ap_init(NULL)) { + log_err("Failed to init shim IPCP."); + return -1; + } + } + ipcpi.irmd_fd = -1; ipcpi.state = IPCP_NULL; ipcpi.shim_data = NULL; @@ -295,7 +342,7 @@ int ipcp_init(enum ipcp_type type, ipcpi.sockfd = server_socket_open(ipcpi.sock_path); if (ipcpi.sockfd < 0) { - LOG_ERR("Could not open server socket."); + log_err("Could not open server socket."); free(ipcpi.threadpool); free(ipcpi.sock_path); return -1; @@ -303,7 +350,7 @@ int ipcp_init(enum ipcp_type type, if (setsockopt(ipcpi.sockfd, SOL_SOCKET, SO_RCVTIMEO, (void *) &tv, sizeof(tv))) - LOG_WARN("Failed to set timeout on socket."); + log_warn("Failed to set timeout on socket."); ipcpi.ops = ops; @@ -338,7 +385,7 @@ int ipcp_boot() if (pthread_create(&ipcpi.threadpool[t], NULL, ipcp_main_loop, NULL)) { int i; - LOG_ERR("Failed to create main thread."); + log_err("Failed to create main thread."); ipcp_set_state(IPCP_NULL); for (i = 0; i < t; ++i) pthread_join(ipcpi.threadpool[i], NULL); @@ -355,14 +402,14 @@ void ipcp_shutdown() for (t = 0; t < IPCPD_THREADPOOL_SIZE; ++t) pthread_join(ipcpi.threadpool[t], NULL); - LOG_DBG("IPCP %d shutting down. Bye.", getpid()); + log_info("IPCP %d shutting down. Bye.", getpid()); } void ipcp_fini() { close(ipcpi.sockfd); if (unlink(ipcpi.sock_path)) - LOG_DBG("Could not unlink %s.", ipcpi.sock_path); + log_warn("Could not unlink %s.", ipcpi.sock_path); free(ipcpi.sock_path); free(ipcpi.threadpool); @@ -372,6 +419,10 @@ void ipcp_fini() pthread_cond_destroy(&ipcpi.state_cond); pthread_mutex_destroy(&ipcpi.state_mtx); pthread_rwlock_destroy(&ipcpi.state_lock); + + log_fini(); + + ap_fini(); } void ipcp_set_state(enum ipcp_state state) @@ -424,47 +475,3 @@ int ipcp_wait_state(enum ipcp_state state, return ret; } - -int ipcp_parse_arg(int argc, - char * argv[]) -{ - char * log_file; - size_t len = 0; - - if (!(argc == 3 || argc == 2)) - return -1; - - /* argument 1: api of irmd */ - if (atoi(argv[1]) == 0) - return -1; - - ipcpi.irmd_api = atoi(argv[1]); - - /* argument 2: IPCP name */ - ipcpi.name = argv[2]; - - /* argument 3: logfile name (if any) */ - if (argv[3] == NULL) - return 0; - - len += strlen(INSTALL_PREFIX); - len += strlen(LOG_DIR); - len += strlen(argv[3]); - - log_file = malloc(len + 1); - if (log_file == NULL) - return -1; - - strcpy(log_file, INSTALL_PREFIX); - strcat(log_file, LOG_DIR); - strcat(log_file, argv[3]); - log_file[len] = '\0'; - - if (set_logfile(log_file)) - LOG_ERR("Cannot open %s, falling back to stdout for logs.", - log_file); - - free(log_file); - - return 0; -} diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h index 9a4d272a..de7d72b0 100644 --- a/src/ipcpd/ipcp.h +++ b/src/ipcpd/ipcp.h @@ -83,7 +83,9 @@ struct ipcp { pthread_t * threadpool; } ipcpi; -int ipcp_init(enum ipcp_type type, +int ipcp_init(int argc, + char ** argv, + enum ipcp_type type, struct ipcp_ops * ops); int ipcp_boot(void); diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index 2cba053a..b49e1612 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -19,7 +19,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define OUROBOROS_PREFIX "ipcpd/local" +#define OUROBOROS_PREFIX "ipcpd-local" #include #include @@ -153,7 +153,7 @@ static int ipcp_local_bootstrap(struct dif_config * conf) if (ipcp_get_state() != IPCP_INIT) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("IPCP in wrong state."); + log_err("IPCP in wrong state."); return -1; } @@ -163,7 +163,7 @@ static int ipcp_local_bootstrap(struct dif_config * conf) pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_INFO("Bootstrapped local IPCP with api %d.", getpid()); + log_info("Bootstrapped local IPCP with api %d.", getpid()); return 0; } @@ -172,7 +172,7 @@ static int ipcp_local_name_reg(char * name) { char * name_dup = strdup(name); if (name_dup == NULL) { - LOG_ERR("Failed to duplicate name."); + log_err("Failed to duplicate name."); return -ENOMEM; } @@ -180,14 +180,14 @@ static int ipcp_local_name_reg(char * name) if (shim_data_reg_add_entry(ipcpi.shim_data, name_dup)) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Failed to add %s to local registry.", name); + log_dbg("Failed to add %s to local registry.", name); free(name_dup); return -1; } pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_INFO("Registered %s.", name); + log_info("Registered %s.", name); return 0; } @@ -200,7 +200,7 @@ static int ipcp_local_name_unreg(char * name) pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_INFO("Unregistered %s.", name); + log_info("Unregistered %s.", name); return 0; } @@ -225,7 +225,7 @@ static int ipcp_local_flow_alloc(int fd, { int out_fd = -1; - LOG_DBG("Allocating flow to %s on fd %d.", dst_name, fd); + log_dbg("Allocating flow to %s on fd %d.", dst_name, fd); assert(dst_name); assert(src_ae_name); @@ -234,7 +234,7 @@ static int ipcp_local_flow_alloc(int fd, if (ipcp_get_state() != IPCP_OPERATIONAL) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Won't register with non-enrolled IPCP."); + log_dbg("Won't register with non-enrolled IPCP."); return -1; /* -ENOTENROLLED */ } @@ -250,7 +250,7 @@ static int ipcp_local_flow_alloc(int fd, pthread_rwlock_unlock(&local_data.lock); pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_INFO("Pending local allocation request on fd %d.", fd); + log_info("Pending local allocation request on fd %d.", fd); return 0; } @@ -282,7 +282,7 @@ static int ipcp_local_flow_alloc_resp(int fd, if ((ret = ipcp_flow_alloc_reply(out_fd, response)) < 0) return -1; - LOG_INFO("Flow allocation completed, fds (%d, %d).", out_fd, fd); + log_info("Flow allocation completed, fds (%d, %d).", out_fd, fd); return ret; } @@ -297,7 +297,7 @@ static int ipcp_local_flow_dealloc(int fd) if (ipcp_get_state() != IPCP_OPERATIONAL) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Won't register with non-enrolled IPCP."); + log_dbg("Won't register with non-enrolled IPCP."); return -1; /* -ENOTENROLLED */ } @@ -312,7 +312,7 @@ static int ipcp_local_flow_dealloc(int fd) pthread_rwlock_unlock(&local_data.lock); pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_INFO("Flow with fd %d deallocated.", fd); + log_info("Flow with fd %d deallocated.", fd); return 0; } @@ -339,23 +339,6 @@ int main(int argc, sigaddset(&sigset, SIGHUP); sigaddset(&sigset, SIGPIPE); - if (ipcp_parse_arg(argc, argv)) { - LOG_ERR("Failed to parse arguments."); - exit(EXIT_FAILURE); - } - - if (ap_init(NULL) < 0) { - LOG_ERR("Failed to init application."); - close_logfile(); - exit(EXIT_FAILURE); - } - - if (local_data_init() < 0) { - LOG_ERR("Failed to init local data."); - close_logfile(); - exit(EXIT_FAILURE); - } - /* init sig_act */ memset(&sig_act, 0, sizeof(sig_act)); @@ -368,25 +351,34 @@ int main(int argc, sigaction(SIGHUP, &sig_act, NULL); sigaction(SIGPIPE, &sig_act, NULL); - if (ipcp_init(THIS_TYPE, &local_ops) < 0) { - LOG_ERR("Failed to init IPCP."); - close_logfile(); + if (ipcp_init(argc, argv, THIS_TYPE, &local_ops) < 0) { + log_err("Failed to init IPCP."); + exit(EXIT_FAILURE); + } + + if (local_data_init() < 0) { + log_err("Failed to init local data."); + ipcp_fini(); exit(EXIT_FAILURE); } pthread_sigmask(SIG_BLOCK, &sigset, NULL); if (ipcp_boot() < 0) { - LOG_ERR("Failed to boot IPCP."); - close_logfile(); + log_err("Failed to boot IPCP."); + local_data_fini(); + ipcp_fini(); exit(EXIT_FAILURE); } pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); if (ipcp_create_r(getpid())) { - LOG_ERR("Failed to notify IRMd we are initialized."); - close_logfile(); + log_err("Failed to notify IRMd we are initialized."); + ipcp_set_state(IPCP_NULL); + ipcp_shutdown(); + local_data_fini(); + ipcp_fini(); exit(EXIT_FAILURE); } @@ -397,13 +389,9 @@ int main(int argc, pthread_join(local_data.sduloop, NULL); } - ipcp_fini(); - local_data_fini(); - ap_fini(); - - close_logfile(); + ipcp_fini(); exit(EXIT_SUCCESS); } diff --git a/src/ipcpd/normal/addr_auth.c b/src/ipcpd/normal/addr_auth.c index c41ffcd2..210744af 100644 --- a/src/ipcpd/normal/addr_auth.c +++ b/src/ipcpd/normal/addr_auth.c @@ -36,7 +36,7 @@ struct addr_auth * addr_auth_create(enum pol_addr_auth type) tmp = malloc(sizeof(*tmp)); if (tmp == NULL) { - LOG_ERR("Failed to malloc addr auth."); + log_err("Failed to malloc addr auth."); return NULL; } @@ -46,7 +46,7 @@ struct addr_auth * addr_auth_create(enum pol_addr_auth type) tmp->type = type; break; default: - LOG_ERR("Unknown address authority type."); + log_err("Unknown address authority type."); free(tmp); return NULL; } @@ -62,7 +62,7 @@ int addr_auth_destroy(struct addr_auth * instance) case FLAT_RANDOM: break; default: - LOG_ERR("Unknown address authority type."); + log_err("Unknown address authority type."); } free(instance); diff --git a/src/ipcpd/normal/enroll.c b/src/ipcpd/normal/enroll.c index 695ceb1d..fb4ff3c3 100644 --- a/src/ipcpd/normal/enroll.c +++ b/src/ipcpd/normal/enroll.c @@ -58,14 +58,14 @@ int enroll_handle(int fd) if (flow_alloc_resp(fd, 0) < 0) { flow_dealloc(fd); - LOG_ERR("Could not respond to request."); + log_err("Could not respond to request."); return -1; } ci = cdap_create(fd); if (ci == NULL) { flow_dealloc(fd); - LOG_ERR("Failed to create CDAP instance."); + log_err("Failed to create CDAP instance."); return -1; } @@ -78,11 +78,11 @@ int enroll_handle(int fd) if (data != NULL) { free(data); - LOG_WARN("Received data with enrollment request."); + log_warn("Received data with enrollment request."); } if (oc != CDAP_READ) { - LOG_WARN("Invalid request."); + log_warn("Invalid request."); cdap_reply_send(ci, key, -1, NULL, 0); cdap_destroy(ci); flow_dealloc(fd); @@ -97,7 +97,7 @@ int enroll_handle(int fd) } else if (strcmp(name, dif_ro) == 0) { dif_name_r = true; } else { - LOG_WARN("Illegal read: %s.", name); + log_warn("Illegal read: %s.", name); cdap_reply_send(ci, key, -1, NULL, 0); cdap_destroy(ci); flow_dealloc(fd); @@ -107,7 +107,7 @@ int enroll_handle(int fd) len = rib_pack(name, &buf, PACK_HASH_ROOT); if (len < 0) { - LOG_ERR("Failed to pack %s.", name); + log_err("Failed to pack %s.", name); cdap_reply_send(ci, key, -1, NULL, 0); cdap_destroy(ci); flow_dealloc(fd); @@ -115,12 +115,12 @@ int enroll_handle(int fd) return -1; } - LOG_DBG("Packed %s (%lu bytes).", name, len); + log_dbg("Packed %s (%lu bytes).", name, len); free(name); if (cdap_reply_send(ci, key, 0, buf, len)) { - LOG_ERR("Failed to send CDAP reply."); + log_err("Failed to send CDAP reply."); cdap_destroy(ci); flow_dealloc(fd); return -1; @@ -129,7 +129,7 @@ int enroll_handle(int fd) free(buf); } - LOG_DBG("Sent boot info to new member."); + log_dbg("Sent boot info to new member."); cdap_destroy(ci); @@ -152,44 +152,44 @@ int enroll_boot(char * dst_name) fd = flow_alloc(dst_name, ENROLL_AE, NULL); if (fd < 0) { - LOG_ERR("Failed to allocate flow."); + log_err("Failed to allocate flow."); return -1; } if (flow_alloc_res(fd)) { - LOG_ERR("Flow allocation failed."); + log_err("Flow allocation failed."); flow_dealloc(fd); return -1; } ci = cdap_create(fd); if (ci == NULL) { - LOG_ERR("Failed to create CDAP instance."); + log_err("Failed to create CDAP instance."); flow_dealloc(fd); return -1; } - LOG_DBG("Getting boot information from %s.", dst_name); + log_dbg("Getting boot information from %s.", dst_name); key = cdap_request_send(ci, CDAP_READ, boot_ro, NULL, 0, 0); if (key < 0) { - LOG_ERR("Failed to send CDAP request."); + log_err("Failed to send CDAP request."); cdap_destroy(ci); flow_dealloc(fd); return -1; } if (cdap_reply_wait(ci, key, &data, &len)) { - LOG_ERR("Failed to get CDAP reply."); + log_err("Failed to get CDAP reply."); cdap_destroy(ci); flow_dealloc(fd); return -1; } - LOG_DBG("Packed information received (%lu bytes).", len); + log_dbg("Packed information received (%lu bytes).", len); if (rib_unpack(data, len, UNPACK_CREATE)) { - LOG_WARN("Error unpacking RIB data."); + log_warn("Error unpacking RIB data."); rib_del(boot_ro); free(data); cdap_destroy(ci); @@ -197,27 +197,27 @@ int enroll_boot(char * dst_name) return -1; } - LOG_DBG("Packed information inserted into RIB."); + log_dbg("Packed information inserted into RIB."); key = cdap_request_send(ci, CDAP_READ, members_ro, NULL, 0, 0); if (key < 0) { - LOG_ERR("Failed to send CDAP request."); + log_err("Failed to send CDAP request."); cdap_destroy(ci); flow_dealloc(fd); return -1; } if (cdap_reply_wait(ci, key, &data, &len)) { - LOG_ERR("Failed to get CDAP reply."); + log_err("Failed to get CDAP reply."); cdap_destroy(ci); flow_dealloc(fd); return -1; } - LOG_DBG("Packed information received (%lu bytes).", len); + log_dbg("Packed information received (%lu bytes).", len); if (rib_unpack(data, len, UNPACK_CREATE)) { - LOG_WARN("Error unpacking RIB data."); + log_warn("Error unpacking RIB data."); rib_del(boot_ro); free(data); cdap_destroy(ci); @@ -225,27 +225,27 @@ int enroll_boot(char * dst_name) return -1; } - LOG_DBG("Packed information inserted into RIB."); + log_dbg("Packed information inserted into RIB."); key = cdap_request_send(ci, CDAP_READ, dif_ro, NULL, 0, 0); if (key < 0) { - LOG_ERR("Failed to send CDAP request."); + log_err("Failed to send CDAP request."); cdap_destroy(ci); flow_dealloc(fd); return -1; } if (cdap_reply_wait(ci, key, &data, &len)) { - LOG_ERR("Failed to get CDAP reply."); + log_err("Failed to get CDAP reply."); cdap_destroy(ci); flow_dealloc(fd); return -1; } - LOG_DBG("Packed information received (%lu bytes).", len); + log_dbg("Packed information received (%lu bytes).", len); if (rib_unpack(data, len, UNPACK_CREATE)) { - LOG_WARN("Error unpacking RIB data."); + log_warn("Error unpacking RIB data."); rib_del(boot_ro); free(data); cdap_destroy(ci); @@ -253,7 +253,7 @@ int enroll_boot(char * dst_name) return -1; } - LOG_DBG("Packed information inserted into RIB."); + log_dbg("Packed information inserted into RIB."); cdap_destroy(ci); diff --git a/src/ipcpd/normal/fmgr.c b/src/ipcpd/normal/fmgr.c index b79d20b4..b958abfa 100644 --- a/src/ipcpd/normal/fmgr.c +++ b/src/ipcpd/normal/fmgr.c @@ -98,13 +98,13 @@ static void * fmgr_np1_sdu_reader(void * o) continue; if (ret < 0) { - LOG_WARN("Event error: %d.", ret); + log_warn("Event error: %d.", ret); continue; } while ((fd = fqueue_next(fmgr.np1_fqs[i])) >= 0) { if (ipcp_flow_read(fd, &sdb)) { - LOG_WARN("Failed to read SDU from fd %d.", fd); + log_warn("Failed to read SDU from fd %d.", fd); continue; } @@ -113,7 +113,7 @@ static void * fmgr_np1_sdu_reader(void * o) if (frct_i_write_sdu(fmgr.np1_fd_to_cep_id[fd], sdb)) { pthread_rwlock_unlock(&fmgr.np1_flows_lock); ipcp_flow_del(sdb); - LOG_WARN("Failed to hand SDU to FRCT."); + log_warn("Failed to hand SDU to FRCT."); continue; } @@ -149,23 +149,23 @@ void * fmgr_nm1_sdu_reader(void * o) continue; if (ret < 0) { - LOG_ERR("Event error: %d.", ret); + log_err("Event error: %d.", ret); continue; } while ((fd = fqueue_next(fmgr.nm1_fqs[i])) >= 0) { if (ipcp_flow_read(fd, &sdb)) { - LOG_ERR("Failed to read SDU from fd %d.", fd); + log_err("Failed to read SDU from fd %d.", fd); continue; } shm_pci_des(sdb, &pci); if (pci.dst_addr != ipcpi.address) { - LOG_DBG("PDU needs to be forwarded."); + log_dbg("PDU needs to be forwarded."); if (pci.ttl == 0) { - LOG_DBG("TTL was zero."); + log_dbg("TTL was zero."); ipcp_flow_del(sdb); continue; } @@ -181,7 +181,7 @@ void * fmgr_nm1_sdu_reader(void * o) shm_pci_shrink(sdb); if (frct_nm1_post_sdu(&pci, sdb)) { - LOG_ERR("Failed to hand PDU to FRCT."); + log_err("Failed to hand PDU to FRCT."); ipcp_flow_del(sdb); continue; } @@ -203,7 +203,7 @@ static void * fmgr_nm1_flow_wait(void * o) while (true) { if (gam_flow_wait(fmgr.gam, &fd, &info, &qs)) { - LOG_ERR("Failed to get next flow descriptor."); + log_err("Failed to get next flow descriptor."); continue; } @@ -287,13 +287,13 @@ int fmgr_init(void) if (rib_read("/" BOOT_NAME "/dt/gam/type", &pg, sizeof(pg)) != sizeof(pg)) { - LOG_ERR("Failed to read policy for ribmgr gam."); + log_err("Failed to read policy for ribmgr gam."); return -1; } if (rib_read("/" BOOT_NAME "/dt/gam/cacep", &pc, sizeof(pc)) != sizeof(pc)) { - LOG_ERR("Failed to read CACEP policy for ribmgr gam."); + log_err("Failed to read CACEP policy for ribmgr gam."); return -1; } @@ -302,7 +302,7 @@ int fmgr_init(void) fmgr.gam = gam_create(pg, DT_AE); if (fmgr.gam == NULL) { - LOG_ERR("Failed to create graph adjacency manager."); + log_err("Failed to create graph adjacency manager."); fmgr_destroy_flows(); return -1; } @@ -536,7 +536,7 @@ int fmgr_np1_post_buf(cep_id_t cep_id, msg = flow_alloc_msg__unpack(NULL, buf->len, buf->data); if (msg == NULL) { - LOG_ERR("Failed to unpack flow alloc message"); + log_err("Failed to unpack flow alloc message"); return -1; } @@ -548,7 +548,7 @@ int fmgr_np1_post_buf(cep_id_t cep_id, msg->qoscube); if (fd < 0) { flow_alloc_msg__free_unpacked(msg, NULL); - LOG_ERR("Failed to get fd for flow."); + log_err("Failed to get fd for flow."); return -1; } @@ -584,7 +584,7 @@ int fmgr_np1_post_buf(cep_id_t cep_id, ret = flow_dealloc(fd); break; default: - LOG_ERR("Got an unknown flow allocation message."); + log_err("Got an unknown flow allocation message."); ret = -1; break; } @@ -604,7 +604,7 @@ int fmgr_np1_post_sdu(cep_id_t cep_id, fd = fmgr.np1_cep_id_to_fd[cep_id]; if (ipcp_flow_write(fd, sdb)) { pthread_rwlock_unlock(&fmgr.np1_flows_lock); - LOG_ERR("Failed to hand SDU to N flow."); + log_err("Failed to hand SDU to N flow."); return -1; } @@ -619,7 +619,7 @@ int fmgr_nm1_flow_arr(int fd, assert(fmgr.gam); if (gam_flow_arr(fmgr.gam, fd, qs)) { - LOG_ERR("Failed to hand to graph adjacency manager."); + log_err("Failed to hand to graph adjacency manager."); return -1; } @@ -633,13 +633,13 @@ int fmgr_nm1_write_sdu(struct pci * pci, return -1; if (shm_pci_ser(sdb, pci)) { - LOG_ERR("Failed to serialize PDU."); + log_err("Failed to serialize PDU."); ipcp_flow_del(sdb); return -1; } if (ipcp_flow_write(fmgr.fd, sdb)) { - LOG_ERR("Failed to write SDU to fd %d.", fmgr.fd); + log_err("Failed to write SDU to fd %d.", fmgr.fd); ipcp_flow_del(sdb); return -1; } @@ -657,13 +657,13 @@ int fmgr_nm1_write_buf(struct pci * pci, buffer = shm_pci_ser_buf(buf, pci); if (buffer == NULL) { - LOG_ERR("Failed to serialize buffer."); + log_err("Failed to serialize buffer."); free(buf->data); return -1; } if (flow_write(fmgr.fd, buffer->data, buffer->len) == -1) { - LOG_ERR("Failed to write buffer to fd."); + log_err("Failed to write buffer to fd."); free(buffer); return -1; } diff --git a/src/ipcpd/normal/frct.c b/src/ipcpd/normal/frct.c index ce316ca2..915feaf8 100644 --- a/src/ipcpd/normal/frct.c +++ b/src/ipcpd/normal/frct.c @@ -225,7 +225,7 @@ int frct_nm1_post_sdu(struct pci * pci, buf.data = shm_du_buff_head(sdb); if (fmgr_np1_post_buf(id, &buf)) { - LOG_ERR("Failed to hand buffer to FMGR."); + log_err("Failed to hand buffer to FMGR."); free(pci); return -1; } @@ -244,14 +244,14 @@ int frct_nm1_post_sdu(struct pci * pci, buf.data = shm_du_buff_head(sdb); if (fmgr_np1_post_buf(pci->dst_cep_id, &buf)) { - LOG_ERR("Failed to hand buffer to Flow Manager."); + log_err("Failed to hand buffer to Flow Manager."); free(pci); return -1; } } else { /* FIXME: Known cep-ids are delivered to FMGR (minimal DTP) */ if (fmgr_np1_post_sdu(pci->dst_cep_id, sdb)) { - LOG_ERR("Failed to hand SDU to FMGR."); + log_err("Failed to hand SDU to FMGR."); free(pci); return -1; } @@ -293,7 +293,7 @@ cep_id_t frct_i_create(uint64_t address, if (fmgr_nm1_write_buf(&pci, buf)) { free(instance); - LOG_ERR("Failed to hand PDU to FMGR."); + log_err("Failed to hand PDU to FMGR."); return INVALID_CEP_ID; } @@ -315,7 +315,7 @@ int frct_i_accept(cep_id_t id, instance = frct.instances[id]; if (instance == NULL) { pthread_mutex_unlock(&frct.instances_lock); - LOG_ERR("Invalid instance."); + log_err("Invalid instance."); return -1; } @@ -355,7 +355,7 @@ int frct_i_destroy(cep_id_t id, instance = frct.instances[id]; if (instance == NULL) { pthread_mutex_unlock(&frct.instances_lock); - LOG_ERR("Invalid instance."); + log_err("Invalid instance."); return -1; } @@ -401,13 +401,13 @@ int frct_i_write_sdu(cep_id_t id, instance = frct.instances[id]; if (instance == NULL) { pthread_mutex_unlock(&frct.instances_lock); - LOG_ERR("Invalid instance."); + log_err("Invalid instance."); return -1; } if (instance->state != CONN_ESTABLISHED) { pthread_mutex_unlock(&frct.instances_lock); - LOG_ERR("Connection is not established."); + log_err("Connection is not established."); return -1; } @@ -421,7 +421,7 @@ int frct_i_write_sdu(cep_id_t id, if (fmgr_nm1_write_sdu(&pci, sdb)) { pthread_mutex_unlock(&frct.instances_lock); - LOG_ERR("Failed to hand SDU to FMGR."); + log_err("Failed to hand SDU to FMGR."); return -1; } diff --git a/src/ipcpd/normal/gam.c b/src/ipcpd/normal/gam.c index c337afd0..fae34dfe 100644 --- a/src/ipcpd/normal/gam.c +++ b/src/ipcpd/normal/gam.c @@ -72,7 +72,7 @@ struct gam * gam_create(enum pol_gam gam_type, tmp->ops = &complete_ops; break; default: - LOG_ERR("Unknown gam policy: %d.", gam_type); + log_err("Unknown gam policy: %d.", gam_type); free(tmp); return NULL; } @@ -169,7 +169,7 @@ static int add_ga(struct gam * instance, pthread_cond_signal(&instance->gas_cond); pthread_mutex_unlock(&instance->gas_lock); - LOG_INFO("Added %s flow to %s.", instance->ae_name, info->name); + log_info("Added %s flow to %s.", instance->ae_name, info->name); return 0; } @@ -183,19 +183,19 @@ int gam_flow_arr(struct gam * instance, if (flow_alloc_resp(fd, instance->ops->accept_new_flow(instance->ops_o)) < 0) { - LOG_ERR("Could not respond to new flow."); + log_err("Could not respond to new flow."); return -1; } cacep = cacep_create(fd, ipcpi.name, ipcpi.address); if (cacep == NULL) { - LOG_ERR("Failed to create CACEP instance."); + log_err("Failed to create CACEP instance."); return -1; } info = cacep_auth_wait(cacep); if (info == NULL) { - LOG_ERR("Other side failed to authenticate."); + log_err("Other side failed to authenticate."); cacep_destroy(cacep); return -1; } @@ -210,7 +210,7 @@ int gam_flow_arr(struct gam * instance, } if (add_ga(instance, fd, qs, info)) { - LOG_ERR("Failed to add ga to graph adjacency manager list."); + log_err("Failed to add ga to graph adjacency manager list."); free(info->name); free(info); return -1; @@ -230,25 +230,25 @@ int gam_flow_alloc(struct gam * instance, fd = flow_alloc(dst_name, instance->ae_name, NULL); if (fd < 0) { - LOG_ERR("Failed to allocate flow to %s.", dst_name); + log_err("Failed to allocate flow to %s.", dst_name); return -1; } if (flow_alloc_res(fd)) { - LOG_ERR("Flow allocation to %s failed.", dst_name); + log_err("Flow allocation to %s failed.", dst_name); flow_dealloc(fd); return -1; } cacep = cacep_create(fd, ipcpi.name, ipcpi.address); if (cacep == NULL) { - LOG_ERR("Failed to create CACEP instance."); + log_err("Failed to create CACEP instance."); return -1; } info = cacep_auth(cacep); if (info == NULL) { - LOG_ERR("Failed to authenticate."); + log_err("Failed to authenticate."); cacep_destroy(cacep); return -1; } @@ -262,7 +262,7 @@ int gam_flow_alloc(struct gam * instance, } if (add_ga(instance, fd, qs, info)) { - LOG_ERR("Failed to add GA to graph adjacency manager list."); + log_err("Failed to add GA to graph adjacency manager list."); free(info); return -1; } diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c index 97484958..5d8af688 100644 --- a/src/ipcpd/normal/main.c +++ b/src/ipcpd/normal/main.c @@ -99,7 +99,7 @@ static void * flow_acceptor(void * o) if (ipcp_get_state() != IPCP_OPERATIONAL) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_INFO("Shutting down flow acceptor."); + log_info("Shutting down flow acceptor."); return 0; } @@ -107,11 +107,11 @@ static void * flow_acceptor(void * o) fd = flow_accept(&ae_name, &qs); if (fd < 0) { - LOG_WARN("Flow accept failed."); + log_warn("Flow accept failed."); continue; } - LOG_DBG("New flow allocation request for AE %s.", ae_name); + log_dbg("New flow allocation request for AE %s.", ae_name); if (strcmp(ae_name, ENROLL_AE) == 0) { enroll_handle(fd); @@ -120,10 +120,10 @@ static void * flow_acceptor(void * o) } else if (strcmp(ae_name, DT_AE) == 0) { fmgr_nm1_flow_arr(fd, qs); } else { - LOG_DBG("Flow allocation request for unknown AE %s.", + log_dbg("Flow allocation request for unknown AE %s.", ae_name); if (flow_alloc_resp(fd, -1)) - LOG_WARN("Failed to reply to flow allocation."); + log_warn("Failed to reply to flow allocation."); flow_dealloc(fd); } @@ -146,66 +146,66 @@ static int boot_components(void) len = rib_read(DIF_PATH, &buf, 256); if (len < 0) { - LOG_ERR("Failed to read DIF name: %ld.", len); + log_err("Failed to read DIF name: %ld.", len); return -1; } ipcpi.dif_name = strdup(buf); if (ipcpi.dif_name == NULL) { - LOG_ERR("Failed to set DIF name."); + log_err("Failed to set DIF name."); return -1; } if (rib_add(MEMBERS_PATH, ipcpi.name)) { - LOG_WARN("Failed to add name to " MEMBERS_PATH); + log_warn("Failed to add name to " MEMBERS_PATH); return -1; } - LOG_DBG("Starting components."); + log_dbg("Starting components."); if (rib_read(BOOT_PATH "/addr_auth/type", &pa, sizeof(pa)) != sizeof(pa)) { - LOG_ERR("Failed to read policy for address authority."); + log_err("Failed to read policy for address authority."); return -1; } normal.auth = addr_auth_create(pa); if (normal.auth == NULL) { - LOG_ERR("Failed to init address authority."); + log_err("Failed to init address authority."); return -1; } ipcpi.address = normal.auth->address(); if (ipcpi.address == 0) { - LOG_ERR("Failed to get a valid address."); + log_err("Failed to get a valid address."); addr_auth_destroy(normal.auth); return -1; } - LOG_DBG("IPCP got address %lu.", ipcpi.address); + log_dbg("IPCP got address %lu.", ipcpi.address); - LOG_DBG("Starting ribmgr."); + log_dbg("Starting ribmgr."); if (ribmgr_init()) { - LOG_ERR("Failed to initialize RIB manager."); + log_err("Failed to initialize RIB manager."); addr_auth_destroy(normal.auth); return -1; } if (dir_init()) { - LOG_ERR("Failed to initialize directory."); + log_err("Failed to initialize directory."); ribmgr_fini(); addr_auth_destroy(normal.auth); return -1; } - LOG_DBG("Ribmgr started."); + log_dbg("Ribmgr started."); if (fmgr_init()) { dir_fini(); ribmgr_fini(); addr_auth_destroy(normal.auth); - LOG_ERR("Failed to start flow manager."); + log_err("Failed to start flow manager."); return -1; } @@ -214,7 +214,7 @@ static int boot_components(void) dir_fini(); ribmgr_fini(); addr_auth_destroy(normal.auth); - LOG_ERR("Failed to initialize FRCT."); + log_err("Failed to initialize FRCT."); return -1; } @@ -226,45 +226,61 @@ static int boot_components(void) dir_fini(); ribmgr_fini(); addr_auth_destroy(normal.auth); - LOG_ERR("Failed to create acceptor thread."); + log_err("Failed to create acceptor thread."); return -1; } return 0; } +void shutdown_components(void) +{ + pthread_cancel(normal.acceptor); + pthread_join(normal.acceptor, NULL); + + frct_fini(); + + fmgr_fini(); + + dir_fini(); + + ribmgr_fini(); + + addr_auth_destroy(normal.auth); +} + static int normal_ipcp_enroll(char * dst_name) { pthread_rwlock_wrlock(&ipcpi.state_lock); if (ipcp_get_state() != IPCP_INIT) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("IPCP in wrong state."); + log_err("IPCP in wrong state."); return -1; /* -ENOTINIT */ } if (rib_add(RIB_ROOT, MEMBERS_NAME)) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("Failed to create members."); + log_err("Failed to create members."); return -1; } /* Get boot state from peer */ if (enroll_boot(dst_name)) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("Failed to boot IPCP components."); + log_err("Failed to boot IPCP components."); return -1; } if (boot_components()) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("Failed to boot IPCP components."); + log_err("Failed to boot IPCP components."); return -1; } pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Enrolled with %s.", dst_name); + log_dbg("Enrolled with %s.", dst_name); return 0; } @@ -314,7 +330,7 @@ int normal_rib_init(void) for (r = (struct ros *) ros; r->parent; ++r) { if (rib_add(r->parent, r->child)) { - LOG_ERR("Failed to create %s/%s", + log_err("Failed to create %s/%s", r->parent, r->child); return -1; } @@ -331,7 +347,7 @@ static int normal_ipcp_bootstrap(struct dif_config * conf) (void) pol; if (conf == NULL || conf->type != THIS_TYPE) { - LOG_ERR("Bad DIF configuration."); + log_err("Bad DIF configuration."); return -EINVAL; } @@ -339,13 +355,13 @@ static int normal_ipcp_bootstrap(struct dif_config * conf) if (ipcp_get_state() != IPCP_INIT) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("IPCP in wrong state."); + log_err("IPCP in wrong state."); return -1; /* -ENOTINIT */ } if (normal_rib_init()) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("Failed to write initial structure to the RIB."); + log_err("Failed to write initial structure to the RIB."); return -1; } @@ -388,20 +404,20 @@ static int normal_ipcp_bootstrap(struct dif_config * conf) rib_write(BOOT_PATH "/addr_auth/type", &conf->addr_auth_type, sizeof(conf->addr_auth_type))) { - LOG_ERR("Failed to write boot info to RIB."); + log_err("Failed to write boot info to RIB."); pthread_rwlock_unlock(&ipcpi.state_lock); return -1; } if (boot_components()) { - LOG_ERR("Failed to boot IPCP components."); + log_err("Failed to boot IPCP components."); pthread_rwlock_unlock(&ipcpi.state_lock); return -1; } pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Bootstrapped in DIF %s.", conf->dif_name); + log_dbg("Bootstrapped in DIF %s.", conf->dif_name); return 0; } @@ -423,28 +439,12 @@ int main(int argc, struct sigaction sig_act; sigset_t sigset; - if (ap_init(argv[0])) { - LOG_ERR("Failed to init AP"); - exit(EXIT_FAILURE); - } - sigemptyset(&sigset); sigaddset(&sigset, SIGINT); sigaddset(&sigset, SIGQUIT); sigaddset(&sigset, SIGHUP); sigaddset(&sigset, SIGPIPE); - if (ipcp_parse_arg(argc, argv)) { - LOG_ERR("Failed to parse arguments."); - exit(EXIT_FAILURE); - } - - if (irm_bind_api(getpid(), ipcpi.name)) { - LOG_ERR("Failed to bind AP name."); - close_logfile(); - exit(EXIT_FAILURE); - } - /* init sig_act */ memset(&sig_act, 0, sizeof(sig_act)); @@ -457,59 +457,50 @@ int main(int argc, sigaction(SIGHUP, &sig_act, NULL); sigaction(SIGPIPE, &sig_act, NULL); - if (rib_init()) { - LOG_ERR("Failed to initialize RIB."); - close_logfile(); + if (irm_bind_api(getpid(), ipcpi.name)) { + log_err("Failed to bind AP name."); exit(EXIT_FAILURE); } - if (ipcp_init(THIS_TYPE, &normal_ops) < 0) { - LOG_ERR("Failed to create instance."); - rib_fini(); - close_logfile(); + if (ipcp_init(argc, argv, THIS_TYPE, &normal_ops) < 0) { + log_err("Failed to create instance."); + exit(EXIT_FAILURE); + } + + if (rib_init()) { + log_err("Failed to initialize RIB."); + ipcp_fini(); exit(EXIT_FAILURE); } pthread_sigmask(SIG_BLOCK, &sigset, NULL); if (ipcp_boot() < 0) { - LOG_ERR("Failed to boot IPCP."); - ipcp_fini(); + log_err("Failed to boot IPCP."); rib_fini(); - close_logfile(); + ipcp_fini(); exit(EXIT_FAILURE); } pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); if (ipcp_create_r(getpid())) { - LOG_ERR("Failed to notify IRMd we are initialized."); - ipcp_fini(); + log_err("Failed to notify IRMd we are initialized."); + ipcp_set_state(IPCP_NULL); + ipcp_shutdown(); rib_fini(); - close_logfile(); + ipcp_fini(); exit(EXIT_FAILURE); } ipcp_shutdown(); - if (ipcp_get_state() == IPCP_SHUTDOWN) { - pthread_cancel(normal.acceptor); - pthread_join(normal.acceptor, NULL); - } - - ribmgr_fini(); - - dir_fini(); - - addr_auth_destroy(normal.auth); + if (ipcp_get_state() == IPCP_SHUTDOWN) + shutdown_components(); rib_fini(); ipcp_fini(); - close_logfile(); - - ap_fini(); - exit(EXIT_SUCCESS); } diff --git a/src/ipcpd/normal/pol/flat.c b/src/ipcpd/normal/pol/flat.c index 31fcd4e8..9ffeb5c7 100644 --- a/src/ipcpd/normal/pol/flat.c +++ b/src/ipcpd/normal/pol/flat.c @@ -102,29 +102,29 @@ uint64_t flat_address(void) strcpy(path, "/" MEMBERS_NAME); if (!rib_has(path)) { - LOG_ERR("Could not read members from RIB."); + log_err("Could not read members from RIB."); return INVALID_ADDRESS; } if (rib_read("/" BOOT_NAME "/dt/const/addr_size", &addr_size, sizeof(addr_size)) != sizeof(addr_size)) { - LOG_ERR("Failed to read address size."); + log_err("Failed to read address size."); return INVALID_ADDRESS; } if (addr_size != 4) { - LOG_ERR("Flat address policy mandates 4 byte addresses."); + log_err("Flat address policy mandates 4 byte addresses."); return INVALID_ADDRESS; } n_members = rib_children(path, &members); if (n_members > REC_DIF_SIZE) - LOG_WARN("DIF exceeding recommended size for flat addresses."); + log_warn("DIF exceeding recommended size for flat addresses."); rib_path_append(path, ipcpi.name); if (!rib_has(path)) { - LOG_ERR("This ipcp is not a member."); + log_err("This ipcp is not a member."); freepp(char, members, n_members); return INVALID_ADDRESS; } @@ -142,12 +142,12 @@ uint64_t flat_address(void) freepp(char, members, n_members); if (rib_add(path, name)) { - LOG_ERR("Failed to add address to RIB."); + log_err("Failed to add address to RIB."); return INVALID_ADDRESS; } if (rib_write(path, &addr, sizeof(addr))) { - LOG_ERR("Failed to write address in RIB."); + log_err("Failed to write address in RIB."); return INVALID_ADDRESS; } diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c index 4ff316dc..05d881ea 100644 --- a/src/ipcpd/normal/ribmgr.c +++ b/src/ipcpd/normal/ribmgr.c @@ -60,13 +60,13 @@ int ribmgr_init(void) if (rib_read(BOOT_PATH "/rm/gam/type", &pg, sizeof(pg)) != sizeof(pg)) { - LOG_ERR("Failed to read policy for ribmgr gam."); + log_err("Failed to read policy for ribmgr gam."); return -1; } if (rib_read(BOOT_PATH "/rm/gam/cacep", &pc, sizeof(pc)) != sizeof(pc)) { - LOG_ERR("Failed to read CACEP policy for ribmgr gam."); + log_err("Failed to read CACEP policy for ribmgr gam."); return -1; } @@ -75,20 +75,20 @@ int ribmgr_init(void) ribmgr.gam = gam_create(pg, MGMT_AE); if (ribmgr.gam == NULL) { - LOG_ERR("Failed to create gam."); + log_err("Failed to create gam."); return -1; } ribmgr.fs = flow_set_create(); if (ribmgr.fs == NULL) { - LOG_ERR("Failed to create flow set."); + log_err("Failed to create flow set."); gam_destroy(ribmgr.gam); return -1; } ribmgr.fq = fqueue_create(); if (ribmgr.fq == NULL) { - LOG_ERR("Failed to create fq."); + log_err("Failed to create fq."); flow_set_destroy(ribmgr.fs); gam_destroy(ribmgr.gam); return -1; diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c index fba4f5f3..35ec0297 100644 --- a/src/ipcpd/shim-eth-llc/main.c +++ b/src/ipcpd/shim-eth-llc/main.c @@ -207,7 +207,7 @@ static int eth_llc_ipcp_send_frame(uint8_t * dst_addr, struct eth_llc_frame * llc_frame; if (payload == NULL) { - LOG_ERR("Payload was NULL."); + log_err("Payload was NULL."); return -1; } @@ -224,7 +224,7 @@ static int eth_llc_ipcp_send_frame(uint8_t * dst_addr, pfd.events = POLLIN | POLLRDNORM | POLLERR; if (poll(&pfd, 1, -1) <= 0) { - LOG_ERR("Failed to poll."); + log_err("Failed to poll."); continue; } @@ -261,7 +261,7 @@ static int eth_llc_ipcp_send_frame(uint8_t * dst_addr, header->tp_status = TP_STATUS_SEND_REQUEST; if (send(eth_llc_data.s_fd, NULL, 0, MSG_DONTWAIT) < 0) { - LOG_ERR("Failed to write frame into TX_RING."); + log_err("Failed to write frame into TX_RING."); return -1; } @@ -274,7 +274,7 @@ static int eth_llc_ipcp_send_frame(uint8_t * dst_addr, 0, (struct sockaddr *) ð_llc_data.device, sizeof(eth_llc_data.device)) <= 0) { - LOG_ERR("Failed to send message."); + log_err("Failed to send message."); return -1; } #endif @@ -299,7 +299,7 @@ static int eth_llc_ipcp_send_mgmt_frame(shim_eth_llc_msg_t * msg, if (eth_llc_ipcp_send_frame(dst_addr, reverse_bits(MGMT_SAP), reverse_bits(MGMT_SAP), buf, len)) { - LOG_ERR("Failed to send management frame."); + log_err("Failed to send management frame."); free(buf); return -1; } @@ -362,7 +362,7 @@ static int eth_llc_ipcp_sap_req(uint8_t r_sap, if (fd < 0) { pthread_rwlock_unlock(ð_llc_data.flows_lock); pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("Could not get new flow from IRMd."); + log_err("Could not get new flow from IRMd."); return -1; } @@ -372,7 +372,7 @@ static int eth_llc_ipcp_sap_req(uint8_t r_sap, pthread_rwlock_unlock(ð_llc_data.flows_lock); pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("New flow request, fd %d, remote SAP %d.", fd, r_sap); + log_dbg("New flow request, fd %d, remote SAP %d.", fd, r_sap); return 0; } @@ -392,7 +392,7 @@ static int eth_llc_ipcp_sap_alloc_reply(uint8_t ssap, if (fd < 0) { pthread_rwlock_unlock(& eth_llc_data.flows_lock); pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("No flow found with that SAP."); + log_err("No flow found with that SAP."); return -1; /* -EFLOWNOTFOUND */ } @@ -406,7 +406,7 @@ static int eth_llc_ipcp_sap_alloc_reply(uint8_t ssap, pthread_rwlock_unlock(ð_llc_data.flows_lock); pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Flow reply, fd %d, SSAP %d, DSAP %d.", fd, ssap, dsap); + log_dbg("Flow reply, fd %d, SSAP %d, DSAP %d.", fd, ssap, dsap); if ((ret = ipcp_flow_alloc_reply(fd, response)) < 0) return -1; @@ -459,7 +459,7 @@ static int eth_llc_ipcp_mgmt_frame(uint8_t * buf, { shim_eth_llc_msg_t * msg = shim_eth_llc_msg__unpack(NULL, len, buf); if (msg == NULL) { - LOG_ERR("Failed to unpack."); + log_err("Failed to unpack."); return -1; } @@ -486,7 +486,7 @@ static int eth_llc_ipcp_mgmt_frame(uint8_t * buf, eth_llc_ipcp_name_query_reply(msg->dst_name, r_addr); break; default: - LOG_ERR("Unknown message received %d.", msg->code); + log_err("Unknown message received %d.", msg->code); shim_eth_llc_msg__free_unpacked(msg, NULL); return -1; } @@ -527,7 +527,7 @@ static void * eth_llc_ipcp_sdu_reader(void * o) pfd.events = POLLIN | POLLRDNORM | POLLERR; if (poll(&pfd, 1, -1) <= 0) { - LOG_ERR("Failed to poll."); + log_err("Failed to poll."); continue; } @@ -540,7 +540,7 @@ static void * eth_llc_ipcp_sdu_reader(void * o) frame_len = recv(eth_llc_data.s_fd, buf, SHIM_ETH_LLC_MAX_SDU_SIZE, 0); if (frame_len < 0) { - LOG_ERR("Failed to receive frame."); + log_err("Failed to receive frame."); continue; } #endif @@ -641,7 +641,7 @@ static void * eth_llc_ipcp_sdu_writer(void * o) while ((fd = fqueue_next(eth_llc_data.fq)) >= 0) { if (ipcp_flow_read(fd, &sdb)) { - LOG_ERR("Bad read from fd %d.", fd); + log_err("Bad read from fd %d.", fd); continue; } @@ -715,7 +715,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) assert(conf->type == THIS_TYPE); if (conf->if_name == NULL) { - LOG_ERR("Interface name is NULL."); + log_err("Interface name is NULL."); return -1; } @@ -725,20 +725,20 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) #ifdef __FreeBSD__ if (getifaddrs(&ifaddr) < 0) { - LOG_ERR("Could not get interfaces."); + log_err("Could not get interfaces."); return -1; } for (ifa = ifaddr, idx = 0; ifa != NULL; ifa = ifa->ifa_next, ++idx) { if (strcmp(ifa->ifa_name, conf->if_name)) continue; - LOG_DBG("Interface %s found.", conf->if_name); + log_dbg("Interface %s found.", conf->if_name); memcpy(&ifr.ifr_addr, ifa->ifa_addr, sizeof(*ifa->ifa_addr)); break; } if (ifa == NULL) { - LOG_ERR("Interface not found."); + log_err("Interface not found."); freeifaddrs(ifaddr); return -1; } @@ -747,12 +747,12 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) #else skfd = socket(AF_UNIX, SOCK_STREAM, 0); if (skfd < 0) { - LOG_ERR("Failed to open socket."); + log_err("Failed to open socket."); return -1; } if (ioctl(skfd, SIOCGIFHWADDR, &ifr)) { - LOG_ERR("Failed to ioctl."); + log_err("Failed to ioctl."); close(skfd); return -1; } @@ -761,7 +761,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) idx = if_nametoindex(conf->if_name); if (idx == 0) { - LOG_ERR("Failed to retrieve interface index."); + log_err("Failed to retrieve interface index."); close(skfd); return -1; } @@ -785,13 +785,13 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) skfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_802_2)); #endif if (skfd < 0) { - LOG_ERR("Failed to create socket."); + log_err("Failed to create socket."); return -1; } #if defined(PACKET_RX_RING) && defined(PACKET_TX_RING) if (SHIM_ETH_LLC_MAX_SDU_SIZE > SHM_RDRB_BLOCK_SIZE) { - LOG_ERR("Max SDU size is bigger than DU map block size."); + log_err("Max SDU size is bigger than DU map block size."); close(skfd); return -1; } @@ -803,20 +803,20 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) if (setsockopt(skfd, SOL_PACKET, PACKET_RX_RING, (void *) &req, sizeof(req))) { - LOG_ERR("Failed to set sockopt PACKET_RX_RING"); + log_err("Failed to set sockopt PACKET_RX_RING"); close(skfd); return -1; } if (setsockopt(skfd, SOL_PACKET, PACKET_TX_RING, (void *) &req, sizeof(req))) { - LOG_ERR("Failed to set sockopt PACKET_TX_RING"); + log_err("Failed to set sockopt PACKET_TX_RING"); close(skfd); return -1; } #endif if (bind(skfd, (struct sockaddr *) &device, sizeof(device))) { - LOG_ERR("Failed to bind socket to interface"); + log_err("Failed to bind socket to interface"); close(skfd); return -1; } @@ -827,7 +827,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) PROT_READ | PROT_WRITE, MAP_SHARED, skfd, 0); if (eth_llc_data.rx_ring == NULL) { - LOG_ERR("Failed to mmap"); + log_err("Failed to mmap"); close(skfd); return -1; } @@ -839,7 +839,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) if (ipcp_get_state() != IPCP_INIT) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("IPCP in wrong state."); + log_err("IPCP in wrong state."); return -1; } @@ -863,7 +863,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Bootstrapped shim IPCP over Ethernet with LLC with api %d.", + log_dbg("Bootstrapped shim IPCP over Ethernet with LLC with api %d.", getpid()); return 0; @@ -873,7 +873,7 @@ static int eth_llc_ipcp_name_reg(char * name) { char * name_dup = strdup(name); if (name_dup == NULL) { - LOG_ERR("Failed to duplicate name."); + log_err("Failed to duplicate name."); return -ENOMEM; } @@ -881,14 +881,14 @@ static int eth_llc_ipcp_name_reg(char * name) if (shim_data_reg_add_entry(ipcpi.shim_data, name_dup)) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("Failed to add %s to local registry.", name); + log_err("Failed to add %s to local registry.", name); free(name_dup); return -1; } pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Registered %s.", name); + log_dbg("Registered %s.", name); return 0; } @@ -949,13 +949,13 @@ static int eth_llc_ipcp_flow_alloc(int fd, uint8_t r_addr[MAC_SIZE]; uint64_t addr = 0; - LOG_DBG("Allocating flow to %s.", dst_name); + log_dbg("Allocating flow to %s.", dst_name); if (dst_name == NULL || src_ae_name == NULL) return -1; if (cube != QOS_CUBE_BE && cube != QOS_CUBE_FRC) { - LOG_DBG("Unsupported QoS requested."); + log_dbg("Unsupported QoS requested."); return -1; } @@ -963,13 +963,13 @@ static int eth_llc_ipcp_flow_alloc(int fd, if (ipcp_get_state() != IPCP_OPERATIONAL) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Won't allocate flow with non-enrolled IPCP."); + log_dbg("Won't allocate flow with non-enrolled IPCP."); return -1; /* -ENOTENROLLED */ } if (!shim_data_dir_has(ipcpi.shim_data, dst_name)) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("Destination unreachable."); + log_err("Destination unreachable."); return -1; } addr = shim_data_dir_get_addr(ipcpi.shim_data, dst_name); @@ -1008,7 +1008,7 @@ static int eth_llc_ipcp_flow_alloc(int fd, flow_set_add(eth_llc_data.np1_flows, fd); - LOG_DBG("Pending flow with fd %d on SAP %d.", fd, ssap); + log_dbg("Pending flow with fd %d on SAP %d.", fd, ssap); return 0; } @@ -1049,7 +1049,7 @@ static int eth_llc_ipcp_flow_alloc_resp(int fd, flow_set_add(eth_llc_data.np1_flows, fd); - LOG_DBG("Accepted flow, fd %d, SAP %d.", fd, (uint8_t)ssap); + log_dbg("Accepted flow, fd %d, SAP %d.", fd, (uint8_t)ssap); return 0; } @@ -1065,7 +1065,7 @@ static int eth_llc_ipcp_flow_dealloc(int fd) if (ipcp_get_state() != IPCP_OPERATIONAL) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Won't register with non-enrolled IPCP."); + log_dbg("Won't register with non-enrolled IPCP."); return -1; /* -ENOTENROLLED */ } @@ -1087,7 +1087,7 @@ static int eth_llc_ipcp_flow_dealloc(int fd) pthread_rwlock_unlock(ð_llc_data.flows_lock); pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Flow with fd %d deallocated.", fd); + log_dbg("Flow with fd %d deallocated.", fd); return 0; } @@ -1115,23 +1115,6 @@ int main(int argc, sigaddset(&sigset, SIGHUP); sigaddset(&sigset, SIGPIPE); - if (ipcp_parse_arg(argc, argv)) { - LOG_ERR("Failed to parse arguments."); - exit(EXIT_FAILURE); - } - - if (ap_init(NULL) < 0) { - LOG_ERR("Failed to init application."); - close_logfile(); - exit(EXIT_FAILURE); - } - - if (eth_llc_data_init() < 0) { - LOG_ERR("Failed to init shim-eth-llc data."); - close_logfile(); - exit(EXIT_FAILURE); - } - /* init sig_act */ memset(&sig_act, 0, sizeof(sig_act)); @@ -1144,25 +1127,35 @@ int main(int argc, sigaction(SIGHUP, &sig_act, NULL); sigaction(SIGPIPE, &sig_act, NULL); - if (ipcp_init(THIS_TYPE, ð_llc_ops) < 0) { - LOG_ERR("Failed to init IPCP."); - close_logfile(); + if (ipcp_init(argc, argv, THIS_TYPE, ð_llc_ops) < 0) { + log_err("Failed to init IPCP."); exit(EXIT_FAILURE); } + if (eth_llc_data_init() < 0) { + log_err("Failed to init shim-eth-llc data."); + ipcp_fini(); + exit(EXIT_FAILURE); + } + + pthread_sigmask(SIG_BLOCK, &sigset, NULL); if (ipcp_boot() < 0) { - LOG_ERR("Failed to boot IPCP."); - close_logfile(); + log_err("Failed to boot IPCP."); + eth_llc_data_fini(); + ipcp_fini(); exit(EXIT_FAILURE); } pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); if (ipcp_create_r(getpid())) { - LOG_ERR("Failed to notify IRMd we are initialized."); - close_logfile(); + log_err("Failed to notify IRMd we are initialized."); + ipcp_set_state(IPCP_NULL); + ipcp_shutdown(); + eth_llc_data_fini(); + ipcp_fini(); exit(EXIT_FAILURE); } @@ -1175,13 +1168,9 @@ int main(int argc, pthread_join(eth_llc_data.sdu_reader, NULL); } - ipcp_fini(); - eth_llc_data_fini(); - ap_fini(); - - close_logfile(); + ipcp_fini(); exit(EXIT_SUCCESS); } diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c index a7c4254a..2a73077c 100644 --- a/src/ipcpd/shim-udp/main.c +++ b/src/ipcpd/shim-udp/main.c @@ -184,7 +184,7 @@ static int send_shim_udp_msg(shim_udp_msg_t * msg, 0, (struct sockaddr *) &r_saddr, sizeof(r_saddr)) == -1) { - LOG_ERR("Failed to send message."); + log_err("Failed to send message."); free(buf.data); return -1; } @@ -240,11 +240,11 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr, struct sockaddr_in f_saddr; socklen_t f_saddr_len = sizeof(f_saddr); - LOG_DBG("Port request arrived from UDP port %d", + log_dbg("Port request arrived from UDP port %d", ntohs(c_saddr->sin_port)); if ((skfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { - LOG_ERR("Could not create UDP socket."); + log_err("Could not create UDP socket."); return -1; } @@ -254,19 +254,19 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr, f_saddr.sin_port = 0; if (bind(skfd, (struct sockaddr *) &f_saddr, sizeof(f_saddr)) < 0) { - LOG_ERR("Could not bind to socket."); + log_err("Could not bind to socket."); close(skfd); return -1; } if (getsockname(skfd, (struct sockaddr *) &f_saddr, &f_saddr_len) < 0) { - LOG_ERR("Could not get address from fd."); + log_err("Could not get address from fd."); return -1; } /* connect stores the remote address in the file descriptor */ if (connect(skfd, (struct sockaddr *) c_saddr, sizeof(*c_saddr)) < 0) { - LOG_ERR("Could not connect to remote UDP client."); + log_err("Could not connect to remote UDP client."); close(skfd); return -1; } @@ -279,7 +279,7 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr, if (fd < 0) { pthread_rwlock_unlock(&udp_data.flows_lock); pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("Could not get new flow from IRMd."); + log_err("Could not get new flow from IRMd."); close(skfd); return -1; } @@ -291,7 +291,7 @@ static int ipcp_udp_port_req(struct sockaddr_in * c_saddr, pthread_rwlock_unlock(&udp_data.flows_lock); pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Pending allocation request, fd %d, UDP port (%d, %d).", + log_dbg("Pending allocation request, fd %d, UDP port (%d, %d).", fd, ntohs(f_saddr.sin_port), ntohs(c_saddr->sin_port)); return 0; @@ -320,7 +320,7 @@ static int ipcp_udp_port_alloc_reply(uint16_t src_udp_port, struct sockaddr_in t_saddr; socklen_t t_saddr_len = sizeof(t_saddr); - LOG_DBG("Received reply for flow on udp port %d.", + log_dbg("Received reply for flow on udp port %d.", ntohs(dst_udp_port)); pthread_rwlock_rdlock(&ipcpi.state_lock); @@ -334,7 +334,7 @@ static int ipcp_udp_port_alloc_reply(uint16_t src_udp_port, /* get the original address with the LISTEN PORT */ if (getpeername(skfd, (struct sockaddr *) &t_saddr, &t_saddr_len) < 0) { - LOG_DBG("Flow with fd %d has no peer.", fd); + log_dbg("Flow with fd %d has no peer.", fd); return -1; } @@ -357,7 +357,7 @@ static int ipcp_udp_port_alloc_reply(uint16_t src_udp_port, if (ipcp_flow_alloc_reply(fd, response) < 0) return -1; - LOG_DBG("Flow allocation completed, UDP ports: (%d, %d).", + log_dbg("Flow allocation completed, UDP ports: (%d, %d).", ntohs(dst_udp_port), ntohs(src_udp_port)); return ret; @@ -406,7 +406,7 @@ static void * ipcp_udp_listener(void * o) msg->response); break; default: - LOG_ERR("Unknown message received %d.", msg->code); + log_err("Unknown message received %d.", msg->code); shim_udp_msg__free_unpacked(msg, NULL); continue; } @@ -498,7 +498,7 @@ static void * ipcp_udp_sdu_loop(void * o) while ((fd = fqueue_next(udp_data.fq)) >= 0) { if (ipcp_flow_read(fd, &sdb)) { - LOG_ERR("Bad read from fd %d.", fd); + log_err("Bad read from fd %d.", fd); continue; } @@ -506,7 +506,7 @@ static void * ipcp_udp_sdu_loop(void * o) shm_du_buff_head(sdb), shm_du_buff_tail(sdb) - shm_du_buff_head(sdb), 0) < 0) - LOG_ERR("Failed to send SDU."); + log_err("Failed to send SDU."); ipcp_flow_del(sdb); } @@ -560,7 +560,7 @@ static int ipcp_udp_bootstrap(struct dif_config * conf) &conf->ip_addr, ipstr, INET_ADDRSTRLEN) == NULL) { - LOG_ERR("Failed to convert IP address"); + log_err("Failed to convert IP address"); return -1; } @@ -569,11 +569,11 @@ static int ipcp_udp_bootstrap(struct dif_config * conf) &conf->dns_addr, dnsstr, INET_ADDRSTRLEN) == NULL) { - LOG_ERR("Failed to convert DNS address"); + log_err("Failed to convert DNS address"); return -1; } #ifndef CONFIG_OUROBOROS_ENABLE_DNS - LOG_WARN("DNS disabled at compile time, address ignored"); + log_warn("DNS disabled at compile time, address ignored"); #endif } else { strcpy(dnsstr, "not set"); @@ -581,7 +581,7 @@ static int ipcp_udp_bootstrap(struct dif_config * conf) /* UDP listen server */ if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { - LOG_ERR("Can't create socket."); + log_err("Can't create socket."); return -1; } @@ -590,7 +590,7 @@ static int ipcp_udp_bootstrap(struct dif_config * conf) SO_REUSEADDR, &enable, sizeof(int)) < 0) - LOG_WARN("Failed to set SO_REUSEADDR."); + log_warn("Failed to set SO_REUSEADDR."); memset((char *) &s_saddr, 0, sizeof(s_saddr)); udp_data.s_saddr.sin_family = AF_INET; @@ -600,7 +600,7 @@ static int ipcp_udp_bootstrap(struct dif_config * conf) if (bind(fd, (struct sockaddr *) &udp_data.s_saddr, sizeof(udp_data.s_saddr)) < 0) { - LOG_ERR("Couldn't bind to %s.", ipstr); + log_err("Couldn't bind to %s.", ipstr); close(fd); return -1; } @@ -609,7 +609,7 @@ static int ipcp_udp_bootstrap(struct dif_config * conf) if (ipcp_get_state() != IPCP_INIT) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("IPCP in wrong state."); + log_err("IPCP in wrong state."); close(fd); return -1; } @@ -638,9 +638,9 @@ static int ipcp_udp_bootstrap(struct dif_config * conf) pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Bootstrapped shim IPCP over UDP with api %d.", getpid()); - LOG_DBG("Bound to IP address %s.", ipstr); - LOG_DBG("DNS server address is %s.", dnsstr); + log_dbg("Bootstrapped shim IPCP over UDP with api %d.", getpid()); + log_dbg("Bound to IP address %s.", ipstr); + log_dbg("DNS server address is %s.", dnsstr); return 0; } @@ -657,13 +657,13 @@ static int ddns_send(char * cmd) char * envp[] = {0}; if (pipe(pipe_fd)) { - LOG_ERR("Failed to create pipe."); + log_err("Failed to create pipe."); return -1; } api = fork(); if (api == -1) { - LOG_ERR("Failed to fork."); + log_err("Failed to fork."); return -1; } @@ -676,7 +676,7 @@ static int ddns_send(char * cmd) close(pipe_fd[0]); if (write(pipe_fd[1], cmd, strlen(cmd)) == -1) { - LOG_ERR("Failed to communicate with nsupdate."); + log_err("Failed to communicate with nsupdate."); close(pipe_fd[1]); return -1; } @@ -684,9 +684,9 @@ static int ddns_send(char * cmd) waitpid(api, &wstatus, 0); if (WIFEXITED(wstatus) == true && WEXITSTATUS(wstatus) == 0) - LOG_DBG("Succesfully communicated with DNS server."); + log_dbg("Succesfully communicated with DNS server."); else - LOG_ERR("Failed to register with DNS server."); + log_err("Failed to register with DNS server."); close(pipe_fd[1]); return 0; @@ -712,13 +712,13 @@ static uint32_t ddns_resolve(char * name, if (pipe(pipe_fd)) { - LOG_ERR("Failed to create pipe."); + log_err("Failed to create pipe."); return 0; } api = fork(); if (api == -1) { - LOG_ERR("Failed to fork."); + log_err("Failed to fork."); return 0; } @@ -735,7 +735,7 @@ static uint32_t ddns_resolve(char * name, count = read(pipe_fd[0], buf, SHIM_UDP_BUF_SIZE); if (count <= 0) { - LOG_ERR("Failed to communicate with nslookup."); + log_err("Failed to communicate with nslookup."); close(pipe_fd[0]); return 0; } @@ -745,9 +745,9 @@ static uint32_t ddns_resolve(char * name, waitpid(api, &wstatus, 0); if (WIFEXITED(wstatus) == true && WEXITSTATUS(wstatus) == 0) - LOG_DBG("Succesfully communicated with nslookup."); + log_dbg("Succesfully communicated with nslookup."); else - LOG_ERR("Failed to resolve DNS address."); + log_err("Failed to resolve DNS address."); buf[count] = '\0'; substr = strtok(buf, "\n"); @@ -757,12 +757,12 @@ static uint32_t ddns_resolve(char * name, } if (strstr(substr2, addr_str) == NULL) { - LOG_ERR("Failed to resolve DNS address."); + log_err("Failed to resolve DNS address."); return 0; } if (inet_pton(AF_INET, substr2 + strlen(addr_str) + 1, &ip_addr) != 1) { - LOG_ERR("Failed to resolve DNS address."); + log_err("Failed to resolve DNS address."); return 0; } @@ -783,13 +783,13 @@ static int ipcp_udp_name_reg(char * name) char * name_dup; if (strlen(name) > 24) { - LOG_ERR("DNS names cannot be longer than 24 chars."); + log_err("DNS names cannot be longer than 24 chars."); return -1; } name_dup = strdup(name); if (name_dup == NULL) { - LOG_ERR("Failed to duplicate name."); + log_err("Failed to duplicate name."); return -ENOMEM; } @@ -797,7 +797,7 @@ static int ipcp_udp_name_reg(char * name) if (shim_data_reg_add_entry(ipcpi.shim_data, name_dup)) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("Failed to add %s to local registry.", name); + log_err("Failed to add %s to local registry.", name); free(name_dup); return -1; } @@ -835,7 +835,7 @@ static int ipcp_udp_name_reg(char * name) #else pthread_rwlock_unlock(&ipcpi.state_lock); #endif - LOG_DBG("Registered %s.", name); + log_dbg("Registered %s.", name); return 0; } @@ -849,7 +849,7 @@ static int ipcp_udp_name_unreg(char * name) uint32_t dns_addr; #endif if (strlen(name) > 24) { - LOG_ERR("DNS names cannot be longer than 24 chars."); + log_err("DNS names cannot be longer than 24 chars."); return -1; } @@ -894,7 +894,7 @@ static int ipcp_udp_name_query(char * name) assert(name); if (strlen(name) > 24) { - LOG_ERR("DNS names cannot be longer than 24 chars."); + log_err("DNS names cannot be longer than 24 chars."); return -1; } @@ -902,7 +902,7 @@ static int ipcp_udp_name_query(char * name) if (ipcp_get_state() != IPCP_OPERATIONAL) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Won't query a name on a non-enrolled IPCP."); + log_dbg("Won't query a name on a non-enrolled IPCP."); return -1; /* -ENOTENROLLED */ } @@ -919,7 +919,7 @@ static int ipcp_udp_name_query(char * name) ip_addr = ddns_resolve(name, dns_addr); if (ip_addr == 0) { - LOG_DBG("Could not resolve %s.", name); + log_dbg("Could not resolve %s.", name); return -1; } @@ -927,7 +927,7 @@ static int ipcp_udp_name_query(char * name) if (ipcp_get_state() != IPCP_OPERATIONAL) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Won't add name to the directory."); + log_dbg("Won't add name to the directory."); return -1; /* -ENOTENROLLED */ } } else { @@ -935,7 +935,7 @@ static int ipcp_udp_name_query(char * name) h = gethostbyname(name); if (h == NULL) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Could not resolve %s.", name); + log_dbg("Could not resolve %s.", name); return -1; } @@ -946,7 +946,7 @@ static int ipcp_udp_name_query(char * name) if (shim_data_dir_add_entry(ipcpi.shim_data, name, ip_addr)) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_ERR("Failed to add directory entry."); + log_err("Failed to add directory entry."); return -1; } @@ -966,19 +966,19 @@ static int ipcp_udp_flow_alloc(int fd, int skfd; uint32_t ip_addr = 0; - LOG_DBG("Allocating flow to %s.", dst_name); + log_dbg("Allocating flow to %s.", dst_name); assert(dst_name); assert(src_ae_name); if (strlen(dst_name) > 255 || strlen(src_ae_name) > 255) { - LOG_ERR("Name too long for this shim."); + log_err("Name too long for this shim."); return -1; } if (cube != QOS_CUBE_BE && cube != QOS_CUBE_FRC) { - LOG_DBG("Unsupported QoS requested."); + log_dbg("Unsupported QoS requested."); return -1; } @@ -996,7 +996,7 @@ static int ipcp_udp_flow_alloc(int fd, } if (getsockname(skfd, (struct sockaddr *) &f_saddr, &f_saddr_len) < 0) { - LOG_ERR("Could not get address from fd."); + log_err("Could not get address from fd."); close(skfd); return -1; } @@ -1005,14 +1005,14 @@ static int ipcp_udp_flow_alloc(int fd, if (ipcp_get_state() != IPCP_OPERATIONAL) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Won't allocate flow with non-enrolled IPCP."); + log_dbg("Won't allocate flow with non-enrolled IPCP."); close(skfd); return -1; /* -ENOTENROLLED */ } if (!shim_data_dir_has(ipcpi.shim_data, dst_name)) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Could not resolve destination."); + log_dbg("Could not resolve destination."); close(skfd); return -1; } @@ -1058,7 +1058,7 @@ static int ipcp_udp_flow_alloc(int fd, return -1; } - LOG_DBG("Flow pending on fd %d, UDP port %d.", + log_dbg("Flow pending on fd %d, UDP port %d.", fd, ntohs(f_saddr.sin_port)); return fd; @@ -1081,12 +1081,12 @@ static int ipcp_udp_flow_alloc_resp(int fd, skfd = udp_data.fd_to_uf[fd].skfd; if (getsockname(skfd, (struct sockaddr *) &f_saddr, &len) < 0) { - LOG_DBG("Socket with fd %d has no address.", skfd); + log_dbg("Socket with fd %d has no address.", skfd); return -1; } if (getpeername(skfd, (struct sockaddr *) &r_saddr, &len) < 0) { - LOG_DBG("Socket with fd %d has no peer.", skfd); + log_dbg("Socket with fd %d has no peer.", skfd); return -1; } @@ -1113,7 +1113,7 @@ static int ipcp_udp_flow_alloc_resp(int fd, return -1; } - LOG_DBG("Accepted flow, fd %d on UDP port %d.", + log_dbg("Accepted flow, fd %d on UDP port %d.", fd, ntohs(f_saddr.sin_port)); return 0; @@ -1129,7 +1129,7 @@ static int ipcp_udp_flow_dealloc(int fd) if (ipcp_get_state() != IPCP_OPERATIONAL) { pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Won't register with non-enrolled IPCP."); + log_dbg("Won't register with non-enrolled IPCP."); return -1; /* -ENOTENROLLED */ } @@ -1155,7 +1155,7 @@ static int ipcp_udp_flow_dealloc(int fd) pthread_rwlock_unlock(&udp_data.flows_lock); pthread_rwlock_unlock(&ipcpi.state_lock); - LOG_DBG("Flow with fd %d deallocated.", fd); + log_dbg("Flow with fd %d deallocated.", fd); return 0; } @@ -1182,23 +1182,6 @@ int main(int argc, sigaddset(&sigset, SIGHUP); sigaddset(&sigset, SIGPIPE); - if (ipcp_parse_arg(argc, argv)) { - LOG_ERR("Failed to parse arguments."); - exit(EXIT_FAILURE); - } - - if (ap_init(NULL) < 0) { - LOG_ERR("Failed to init application."); - close_logfile(); - exit(EXIT_FAILURE); - } - - if (udp_data_init() < 0) { - LOG_ERR("Failed to init shim-udp data."); - close_logfile(); - exit(EXIT_FAILURE); - } - /* init sig_act */ memset(&sig_act, 0, sizeof(sig_act)); @@ -1211,25 +1194,35 @@ int main(int argc, sigaction(SIGHUP, &sig_act, NULL); sigaction(SIGPIPE, &sig_act, NULL); - if (ipcp_init(THIS_TYPE, &udp_ops) < 0) { - LOG_ERR("Failed to init IPCP."); - close_logfile(); + if (ipcp_init(argc, argv, THIS_TYPE, &udp_ops) < 0) { + log_err("Failed to init IPCP."); exit(EXIT_FAILURE); } + if (udp_data_init() < 0) { + log_err("Failed to init shim-udp data."); + ipcp_fini(); + exit(EXIT_FAILURE); + } + + pthread_sigmask(SIG_BLOCK, &sigset, NULL); if (ipcp_boot() < 0) { - LOG_ERR("Failed to boot IPCP."); - close_logfile(); + log_err("Failed to boot IPCP."); + udp_data_fini(); + ipcp_fini(); exit(EXIT_FAILURE); } pthread_sigmask(SIG_UNBLOCK, &sigset, NULL); if (ipcp_create_r(getpid())) { - LOG_ERR("Failed to notify IRMd we are initialized."); - close_logfile(); + log_err("Failed to notify IRMd we are initialized."); + ipcp_set_state(IPCP_NULL); + ipcp_shutdown(); + udp_data_fini(); + ipcp_fini(); exit(EXIT_FAILURE); } @@ -1244,13 +1237,9 @@ int main(int argc, pthread_join(udp_data.sdu_reader, NULL); } - ipcp_fini(); - udp_data_fini(); - ap_fini(); - - close_logfile(); + ipcp_fini(); exit(EXIT_SUCCESS); } diff --git a/src/ipcpd/shim-udp/tests/shim_udp_test.c b/src/ipcpd/shim-udp/tests/shim_udp_test.c index a342712e..d4a5d8ed 100644 --- a/src/ipcpd/shim-udp/tests/shim_udp_test.c +++ b/src/ipcpd/shim-udp/tests/shim_udp_test.c @@ -48,29 +48,29 @@ int shim_udp_test(int argc, char ** argv) dum = shm_du_map_create(); if (dum == NULL) { - LOG_ERR("Failed to create shared memory."); + log_err("Failed to create shared memory."); exit(1); } _ipcp = ipcp_udp_create(ipcp_name); if (_ipcp == NULL) { - LOG_ERR("Could not instantiate shim IPCP."); + log_err("Could not instantiate shim IPCP."); shm_du_map_destroy(dum); exit(1); } if (ipcp_udp_bootstrap(&conf)) { - LOG_ERR("Could not bootstrap."); + log_err("Could not bootstrap."); } if (ipcp_udp_name_reg("bogus name")) { - LOG_ERR("Failed to register application."); + log_err("Failed to register application."); shm_du_map_destroy(dum); exit(1); } if (ipcp_udp_name_unreg("bogus name")) { - LOG_ERR("Failed to unregister application."); + log_err("Failed to unregister application."); shm_du_map_destroy(dum); exit(1); } @@ -78,7 +78,7 @@ int shim_udp_test(int argc, char ** argv) for (i = 0; i < 1000; ++i) { sprintf(bogus, "bogus name %4d", i); if (ipcp_udp_name_reg(bogus)) { - LOG_ERR("Failed to register application %s.", bogus); + log_err("Failed to register application %s.", bogus); shm_du_map_destroy(dum); exit(1); } @@ -87,7 +87,7 @@ int shim_udp_test(int argc, char ** argv) for (i = 0; i < 1000; ++i) { sprintf(bogus, "bogus name %4d", i); if(ipcp_udp_name_unreg(bogus)) { - LOG_ERR("Failed to unregister application %s.", bogus); + log_err("Failed to unregister application %s.", bogus); shm_du_map_destroy(dum); exit(1); } diff --git a/src/ipcpd/timerwheel.c b/src/ipcpd/timerwheel.c index bb61bd91..6e5b7da9 100644 --- a/src/ipcpd/timerwheel.c +++ b/src/ipcpd/timerwheel.c @@ -235,14 +235,14 @@ struct timerwheel * timerwheel_create(unsigned int resolution, list_head_init(&tw->wq); if (pthread_mutex_init(&tw->lock, NULL)) { - LOG_DBG("Could not init mutex."); + log_dbg("Could not init mutex."); free(tw->wheel); free(tw); return NULL; } if (pthread_mutex_init(&tw->s_lock, NULL)) { - LOG_DBG("Could not init mutex."); + log_dbg("Could not init mutex."); pthread_mutex_destroy(&tw->lock); free(tw->wheel); free(tw); @@ -250,7 +250,7 @@ struct timerwheel * timerwheel_create(unsigned int resolution, } if (pthread_cond_init(&tw->work, NULL)) { - LOG_DBG("Could not init cond."); + log_dbg("Could not init cond."); pthread_mutex_destroy(&tw->s_lock); pthread_mutex_destroy(&tw->lock); free(tw->wheel); @@ -271,7 +271,7 @@ struct timerwheel * timerwheel_create(unsigned int resolution, } if (pthread_create(&tw->worker, NULL, worker, (void *) tw)) { - LOG_DBG("Could not create worker."); + log_dbg("Could not create worker."); pthread_cond_destroy(&tw->work); pthread_mutex_destroy(&tw->s_lock); pthread_mutex_destroy(&tw->lock); @@ -281,7 +281,7 @@ struct timerwheel * timerwheel_create(unsigned int resolution, } if (pthread_create(&tw->ticker, NULL, movement, (void *) tw)) { - LOG_DBG("Could not create timer."); + log_dbg("Could not create timer."); tw_set_state(tw, TW_DESTROY); pthread_join(tw->worker, NULL); pthread_cond_destroy(&tw->work); diff --git a/src/irmd/ipcp.c b/src/irmd/ipcp.c index f16587e1..dcf77eec 100644 --- a/src/irmd/ipcp.c +++ b/src/irmd/ipcp.c @@ -44,7 +44,8 @@ static void close_ptr(void * o) close(*(int *) o); } -ipcp_msg_t * send_recv_ipcp_msg(pid_t api, ipcp_msg_t * msg) +ipcp_msg_t * send_recv_ipcp_msg(pid_t api, + ipcp_msg_t * msg) { int sockfd = 0; buffer_t buf; @@ -67,7 +68,7 @@ ipcp_msg_t * send_recv_ipcp_msg(pid_t api, ipcp_msg_t * msg) if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (void *) &tv, sizeof(tv))) - LOG_WARN("Failed to set timeout on socket."); + log_warn("Failed to set timeout on socket."); free(sock_path); @@ -100,7 +101,8 @@ ipcp_msg_t * send_recv_ipcp_msg(pid_t api, ipcp_msg_t * msg) return recv_msg; } -pid_t ipcp_create(char * name, enum ipcp_type ipcp_type) +pid_t ipcp_create(char * name, + enum ipcp_type ipcp_type) { pid_t api = -1; char irmd_api[10]; @@ -108,14 +110,13 @@ pid_t ipcp_create(char * name, enum ipcp_type ipcp_type) char * ipcp_dir = "/sbin/"; char * full_name = NULL; char * exec_name = NULL; - char * log_file = NULL; char * argv[5]; sprintf(irmd_api, "%u", getpid()); api = fork(); if (api == -1) { - LOG_ERR("Failed to fork"); + log_err("Failed to fork"); return api; } @@ -140,7 +141,7 @@ pid_t ipcp_create(char * name, enum ipcp_type ipcp_type) full_name = malloc(len + 1); if (full_name == NULL) { - LOG_ERR("Failed to malloc"); + log_err("Failed to malloc"); exit(EXIT_FAILURE); } @@ -149,27 +150,25 @@ pid_t ipcp_create(char * name, enum ipcp_type ipcp_type) strcat(full_name, exec_name); full_name[len] = '\0'; - if (logfile != NULL) { - log_file = malloc(20); - if (log_file == NULL) { - LOG_ERR("Failed to malloc."); - exit(EXIT_FAILURE); - } - sprintf(log_file, "ipcpd-%u.log", getpid()); - } /* log_file to be placed at the end */ argv[0] = full_name; argv[1] = irmd_api; argv[2] = name; - argv[3] = log_file; + if (log_syslog) { + argv[3] = "1"; + argv[4] = NULL; + } else { + argv[3] = NULL; + } + argv[4] = NULL; execv(argv[0], &argv[0]); - LOG_DBG("%s", strerror(errno)); - LOG_ERR("Failed to load IPCP daemon"); - LOG_ERR("Make sure to run the installed version"); + log_dbg("%s", strerror(errno)); + log_err("Failed to load IPCP daemon"); + log_err("Make sure to run the installed version"); free(full_name); exit(EXIT_FAILURE); } @@ -179,12 +178,12 @@ int ipcp_destroy(pid_t api) int status; if (kill(api, SIGTERM)) { - LOG_ERR("Failed to destroy IPCP"); + log_err("Failed to destroy IPCP"); return -1; } if (waitpid(api, &status, 0) < 0) { - LOG_ERR("Failed to destroy IPCP"); + log_err("Failed to destroy IPCP"); return -1; } diff --git a/src/irmd/irm_flow.c b/src/irmd/irm_flow.c index 86252a03..d2482391 100644 --- a/src/irmd/irm_flow.c +++ b/src/irmd/irm_flow.c @@ -53,14 +53,14 @@ struct irm_flow * irm_flow_create(pid_t n_api, pid_t n_1_api, int port_id) f->n_rb = shm_rbuff_create(n_api, port_id); if (f->n_rb == NULL) { - LOG_ERR("Could not create ringbuffer for AP-I %d.", n_api); + log_err("Could not create ringbuffer for AP-I %d.", n_api); free(f); return NULL; } f->n_1_rb = shm_rbuff_create(n_1_api, port_id); if (f->n_1_rb == NULL) { - LOG_ERR("Could not create ringbuffer for AP-I %d.", n_1_api); + log_err("Could not create ringbuffer for AP-I %d.", n_1_api); free(f); return NULL; } @@ -68,7 +68,7 @@ struct irm_flow * irm_flow_create(pid_t n_api, pid_t n_1_api, int port_id) f->state = FLOW_ALLOC_PENDING; if (clock_gettime(CLOCK_MONOTONIC, &f->t0) < 0) - LOG_WARN("Failed to set timestamp."); + log_warn("Failed to set timestamp."); return f; } diff --git a/src/irmd/main.c b/src/irmd/main.c index 98e79aa8..c029b4cf 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -51,7 +51,6 @@ #include #include #include -#include #include #define IRMD_CLEANUP_TIMER ((IRMD_FLOW_TIMEOUT / 20) * MILLION) /* ns */ @@ -226,7 +225,8 @@ static pid_t get_ipcp_by_dst_name(char * dst_name) return -1; } -static pid_t create_ipcp(char * name, enum ipcp_type ipcp_type) +static pid_t create_ipcp(char * name, + enum ipcp_type ipcp_type) { struct pid_el * api = NULL; struct ipcp_entry * tmp = NULL; @@ -249,7 +249,7 @@ static pid_t create_ipcp(char * name, enum ipcp_type ipcp_type) if (api->pid == -1) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Failed to create IPCP."); + log_err("Failed to create IPCP."); return -1; } @@ -298,7 +298,7 @@ static pid_t create_ipcp(char * name, enum ipcp_type ipcp_type) pthread_mutex_unlock(&tmp->init_lock); - LOG_INFO("Created IPCP %d.", api->pid); + log_info("Created IPCP %d.", api->pid); return api->pid; } @@ -357,11 +357,11 @@ static int destroy_ipcp(pid_t api) if (api == tmp->api) { clear_spawned_api(api); if (ipcp_destroy(api)) - LOG_ERR("Could not destroy IPCP."); + log_err("Could not destroy IPCP."); list_del(&tmp->next); ipcp_entry_destroy(tmp); - LOG_INFO("Destroyed IPCP %d.", api); + log_info("Destroyed IPCP %d.", api); } } @@ -371,7 +371,8 @@ static int destroy_ipcp(pid_t api) return 0; } -static int bootstrap_ipcp(pid_t api, dif_config_msg_t * conf) +static int bootstrap_ipcp(pid_t api, + dif_config_msg_t * conf) { struct ipcp_entry * entry = NULL; @@ -388,14 +389,14 @@ static int bootstrap_ipcp(pid_t api, dif_config_msg_t * conf) if (entry == NULL) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("No such IPCP."); + log_err("No such IPCP."); return -1; } if (ipcp_bootstrap(entry->api, conf)) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Could not bootstrap IPCP."); + log_err("Could not bootstrap IPCP."); return -1; } @@ -403,20 +404,21 @@ static int bootstrap_ipcp(pid_t api, dif_config_msg_t * conf) if (entry->dif_name == NULL) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_WARN("Failed to set name of DIF."); + log_warn("Failed to set name of DIF."); return -ENOMEM; } pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_INFO("Bootstrapped IPCP %d in DIF %s.", + log_info("Bootstrapped IPCP %d in DIF %s.", entry->api, conf->dif_name); return 0; } -static int enroll_ipcp(pid_t api, char * dif_name) +static int enroll_ipcp(pid_t api, + char * dif_name) { struct ipcp_entry * entry = NULL; @@ -433,14 +435,14 @@ static int enroll_ipcp(pid_t api, char * dif_name) if (entry == NULL) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("No such IPCP."); + log_err("No such IPCP."); return -1; } if (entry->dif_name != NULL) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("IPCP in wrong state"); + log_err("IPCP in wrong state"); return -1; } @@ -448,7 +450,7 @@ static int enroll_ipcp(pid_t api, char * dif_name) if (entry->dif_name == NULL) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Failed to strdup."); + log_err("Failed to strdup."); return -1; } @@ -462,18 +464,21 @@ static int enroll_ipcp(pid_t api, char * dif_name) entry->dif_name = NULL; pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Could not enroll IPCP."); + log_err("Could not enroll IPCP."); return -1; } - LOG_INFO("Enrolled IPCP %d in DIF %s.", + log_info("Enrolled IPCP %d in DIF %s.", api, dif_name); return 0; } -static int bind_ap(char * ap, char * name, uint16_t flags, - int argc, char ** argv) +static int bind_ap(char * ap, + char * name, + uint16_t flags, + int argc, + char ** argv) { char * aps; char * apn; @@ -524,7 +529,7 @@ static int bind_ap(char * ap, char * name, uint16_t flags, pthread_rwlock_unlock( &irmd->state_lock); argvfree(argv_dup); - LOG_ERR("Failed to bind ap %s to %s.", + log_err("Failed to bind ap %s to %s.", ap, name); free(aps); free(apn); @@ -554,7 +559,7 @@ static int bind_ap(char * ap, char * name, uint16_t flags, } if (apn_entry_add_name(e, name_dup)) { - LOG_ERR("Failed adding name."); + log_err("Failed adding name."); pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); free(name_dup); @@ -563,17 +568,18 @@ static int bind_ap(char * ap, char * name, uint16_t flags, re = registry_get_entry(&irmd->registry, name); if (re != NULL && reg_entry_add_apn(re, e) < 0) - LOG_ERR("Failed adding AP %s for name %s.", ap, name); + log_err("Failed adding AP %s for name %s.", ap, name); pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_INFO("Bound AP %s to name %s.", ap, name); + log_info("Bound AP %s to name %s.", ap, name); return 0; } -static int bind_api(pid_t api, char * name) +static int bind_api(pid_t api, + char * name) { char * name_dup = NULL; struct api_entry * e = NULL; @@ -593,7 +599,7 @@ static int bind_api(pid_t api, char * name) e = api_table_get(&irmd->api_table, api); if (e == NULL) { - LOG_ERR("AP-I %d does not exist.", api); + log_err("AP-I %d does not exist.", api); pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); return -1; @@ -609,24 +615,25 @@ static int bind_api(pid_t api, char * name) if (api_entry_add_name(e, name_dup)) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Failed to add name %s to api %d.", name, api); + log_err("Failed to add name %s to api %d.", name, api); free(name_dup); return -1; } re = registry_get_entry(&irmd->registry, name); if (re != NULL && reg_entry_add_api(re, api) < 0) - LOG_ERR("Failed adding AP-I %d for name %s.", api, name); + log_err("Failed adding AP-I %d for name %s.", api, name); pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_INFO("Bound AP-I %d to name %s.", api, name); + log_info("Bound AP-I %d to name %s.", api, name); return 0; } -static int unbind_ap(char * ap, char * name) +static int unbind_ap(char * ap, + char * name) { if (ap == NULL) return -EINVAL; @@ -651,14 +658,15 @@ static int unbind_ap(char * ap, char * name) pthread_rwlock_unlock(&irmd->state_lock); if (name == NULL) - LOG_INFO("AP %s removed.", ap); + log_info("AP %s removed.", ap); else - LOG_INFO("All names matching %s cleared for %s.", name, ap); + log_info("All names matching %s cleared for %s.", name, ap); return 0; } -static int unbind_api(pid_t api, char * name) +static int unbind_api(pid_t api, + char * name) { pthread_rwlock_rdlock(&irmd->state_lock); @@ -680,14 +688,15 @@ static int unbind_api(pid_t api, char * name) pthread_rwlock_unlock(&irmd->state_lock); if (name == NULL) - LOG_INFO("AP-I %d removed.", api); + log_info("AP-I %d removed.", api); else - LOG_INFO("All names matching %s cleared for %d.", name, api); + log_info("All names matching %s cleared for %d.", name, api); return 0; } -static ssize_t list_ipcps(char * name, pid_t ** apis) +static ssize_t list_ipcps(char * name, + pid_t ** apis) { struct list_head * pos = NULL; size_t count = 0; @@ -723,7 +732,9 @@ static ssize_t list_ipcps(char * name, pid_t ** apis) return count; } -static int name_reg(char * name, char ** difs, size_t len) +static int name_reg(char * name, + char ** difs, + size_t len) { size_t i; int ret = 0; @@ -751,7 +762,7 @@ static int name_reg(char * name, char ** difs, size_t len) struct reg_entry * re = registry_add_name(&irmd->registry, strdup(name)); if (re == NULL) { - LOG_ERR("Failed creating registry entry for %s.", name); + log_err("Failed creating registry entry for %s.", name); pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); return -1; @@ -793,17 +804,17 @@ static int name_reg(char * name, char ** difs, size_t len) continue; if (ipcp_name_reg(e->api, name)) { - LOG_ERR("Could not register %s in DIF %s.", + log_err("Could not register %s in DIF %s.", name, e->dif_name); } else { if (registry_add_name_to_dif(&irmd->registry, name, e->dif_name, e->type) < 0) - LOG_WARN("Registered unbound name %s. " + log_warn("Registered unbound name %s. " "Registry may be corrupt.", name); - LOG_INFO("Registered %s in %s as %s.", + log_info("Registered %s in %s as %s.", name, e->dif_name, name); ++ret; } @@ -816,7 +827,9 @@ static int name_reg(char * name, char ** difs, size_t len) return (ret > 0 ? 0 : -1); } -static int name_unreg(char * name, char ** difs, size_t len) +static int name_unreg(char * name, + char ** difs, + size_t len) { size_t i; int ret = 0; @@ -846,13 +859,13 @@ static int name_unreg(char * name, char ** difs, size_t len) continue; if (ipcp_name_unreg(e->api, name)) { - LOG_ERR("Could not unregister %s in DIF %s.", + log_err("Could not unregister %s in DIF %s.", name, e->dif_name); } else { registry_del_name_from_dif(&irmd->registry, name, e->dif_name); - LOG_INFO("Unregistered %s from %s.", + log_info("Unregistered %s from %s.", name, e->dif_name); ++ret; } @@ -865,7 +878,8 @@ static int name_unreg(char * name, char ** difs, size_t len) return (ret > 0 ? 0 : -1); } -static int api_announce(pid_t api, char * apn) +static int api_announce(pid_t api, + char * apn) { struct api_entry * e = NULL; struct apn_entry * a = NULL; @@ -917,7 +931,7 @@ static int api_announce(pid_t api, char * apn) } list_add(&n->next, &e->names); - LOG_DBG("AP-I %d inherits listen name %s from AP %s.", + log_dbg("AP-I %d inherits listen name %s from AP %s.", api, n->str, e->apn); } } @@ -928,7 +942,8 @@ static int api_announce(pid_t api, char * apn) return 0; } -static struct irm_flow * flow_accept(pid_t api, char ** dst_ae_name, +static struct irm_flow * flow_accept(pid_t api, + char ** dst_ae_name, qoscube_t * cube) { struct irm_flow * f = NULL; @@ -948,15 +963,15 @@ static struct irm_flow * flow_accept(pid_t api, char ** dst_ae_name, e = api_table_get(&irmd->api_table, api); if (e == NULL) { /* Can only happen if server called ap_init(NULL); */ - LOG_ERR("Unknown instance %d calling accept.", api); + log_err("Unknown instance %d calling accept.", api); return NULL; } - LOG_DBG("New instance (%d) of %s added.", api, e->apn); - LOG_DBG("This instance accepts flows for:"); + log_dbg("New instance (%d) of %s added.", api, e->apn); + log_dbg("This instance accepts flows for:"); list_for_each(p, &e->names) { struct str_el * s = list_entry(p, struct str_el, next); - LOG_DBG(" %s", s->str); + log_dbg(" %s", s->str); re = registry_get_entry(&irmd->registry, s->str); if (re != NULL) reg_entry_add_api(re, api); @@ -987,7 +1002,7 @@ static struct irm_flow * flow_accept(pid_t api, char ** dst_ae_name, if (e == NULL) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_DBG("Process gone while accepting flow."); + log_dbg("Process gone while accepting flow."); return NULL; } @@ -1000,7 +1015,7 @@ static struct irm_flow * flow_accept(pid_t api, char ** dst_ae_name, if (reg_entry_get_state(re) != REG_NAME_FLOW_ARRIVED) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Entry in wrong state."); + log_err("Entry in wrong state."); return NULL; } pthread_rwlock_unlock(&irmd->reg_lock); @@ -1010,7 +1025,7 @@ static struct irm_flow * flow_accept(pid_t api, char ** dst_ae_name, if (f == NULL) { pthread_rwlock_unlock(&irmd->flows_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Port_id was not created yet."); + log_err("Port_id was not created yet."); return NULL; } @@ -1019,7 +1034,7 @@ static struct irm_flow * flow_accept(pid_t api, char ** dst_ae_name, if (dst_ae_name != NULL) *dst_ae_name = re->req_ae_name; - LOG_INFO("Flow on port_id %d allocated.", f->port_id); + log_info("Flow on port_id %d allocated.", f->port_id); pthread_rwlock_unlock(&irmd->flows_lock); pthread_rwlock_unlock(&irmd->state_lock); @@ -1027,7 +1042,9 @@ static struct irm_flow * flow_accept(pid_t api, char ** dst_ae_name, return f; } -static int flow_alloc_resp(pid_t n_api, int port_id, int response) +static int flow_alloc_resp(pid_t n_api, + int port_id, + int response) { struct irm_flow * f = NULL; struct reg_entry * re = NULL; @@ -1050,7 +1067,7 @@ static int flow_alloc_resp(pid_t n_api, int port_id, int response) if (e == NULL) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Unknown AP-I %d responding for port_id %d.", + log_err("Unknown AP-I %d responding for port_id %d.", n_api, port_id); return -1; } @@ -1059,14 +1076,14 @@ static int flow_alloc_resp(pid_t n_api, int port_id, int response) if (re == NULL) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("AP-I %d is not handling a flow request.", n_api); + log_err("AP-I %d is not handling a flow request.", n_api); return -1; } if (reg_entry_get_state(re) != REG_NAME_FLOW_ARRIVED) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Name %s has no pending flow request.", re->name); + log_err("Name %s has no pending flow request.", re->name); return -1; } @@ -1096,8 +1113,10 @@ static int flow_alloc_resp(pid_t n_api, int port_id, int response) return ret; } -static struct irm_flow * flow_alloc(pid_t api, char * dst_name, - char * src_ae_name, qoscube_t cube) +static struct irm_flow * flow_alloc(pid_t api, + char * dst_name, + char * src_ae_name, + qoscube_t cube) { struct irm_flow * f; pid_t ipcp; @@ -1116,7 +1135,7 @@ static struct irm_flow * flow_alloc(pid_t api, char * dst_name, if (ipcp == -1) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_INFO("Destination unreachable."); + log_info("Destination unreachable."); return NULL; } @@ -1126,7 +1145,7 @@ static struct irm_flow * flow_alloc(pid_t api, char * dst_name, if (!bmp_is_id_valid(irmd->port_ids, port_id)) { pthread_rwlock_unlock(&irmd->flows_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Could not allocate port_id."); + log_err("Could not allocate port_id."); return NULL; } @@ -1135,7 +1154,7 @@ static struct irm_flow * flow_alloc(pid_t api, char * dst_name, bmp_release(irmd->port_ids, port_id); pthread_rwlock_unlock(&irmd->flows_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Could not allocate port_id."); + log_err("Could not allocate port_id."); return NULL; } @@ -1176,19 +1195,19 @@ static int flow_alloc_res(int port_id) if (f == NULL) { pthread_rwlock_unlock(&irmd->flows_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Could not find port %d.", port_id); + log_err("Could not find port %d.", port_id); return -1; } if (irm_flow_get_state(f) == FLOW_NULL) { pthread_rwlock_unlock(&irmd->flows_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_INFO("Port %d is deprecated.", port_id); + log_info("Port %d is deprecated.", port_id); return -1; } if (irm_flow_get_state(f) == FLOW_ALLOCATED) { - LOG_INFO("Flow on port_id %d allocated.", port_id); + log_info("Flow on port_id %d allocated.", port_id); pthread_rwlock_unlock(&irmd->flows_lock); pthread_rwlock_unlock(&irmd->state_lock); return 0; @@ -1198,16 +1217,17 @@ static int flow_alloc_res(int port_id) pthread_rwlock_unlock(&irmd->state_lock); if (irm_flow_wait_state(f, FLOW_ALLOCATED) == FLOW_ALLOCATED) { - LOG_INFO("Flow on port_id %d allocated.", port_id); + log_info("Flow on port_id %d allocated.", port_id); return 0; } - LOG_INFO("Pending flow on port_id %d torn down.", port_id); + log_info("Pending flow on port_id %d torn down.", port_id); return -1; } -static int flow_dealloc(pid_t api, int port_id) +static int flow_dealloc(pid_t api, + int port_id) { pid_t n_1_api = -1; int ret = 0; @@ -1221,7 +1241,7 @@ static int flow_dealloc(pid_t api, int port_id) if (f == NULL) { pthread_rwlock_unlock(&irmd->flows_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_DBG("Deallocate unknown port %d by %d.", port_id, api); + log_dbg("Deallocate unknown port %d by %d.", port_id, api); return 0; } @@ -1233,7 +1253,7 @@ static int flow_dealloc(pid_t api, int port_id) } else { pthread_rwlock_unlock(&irmd->flows_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_DBG("Dealloc called by wrong AP-I."); + log_dbg("Dealloc called by wrong AP-I."); return -EPERM; } @@ -1242,11 +1262,11 @@ static int flow_dealloc(pid_t api, int port_id) clear_irm_flow(f); irm_flow_destroy(f); bmp_release(irmd->port_ids, port_id); - LOG_INFO("Completed deallocation of port_id %d by AP-I %d.", + log_info("Completed deallocation of port_id %d by AP-I %d.", port_id, api); } else { irm_flow_set_state(f, FLOW_DEALLOC_PENDING); - LOG_DBG("Partial deallocation of port_id %d by AP-I %d.", + log_dbg("Partial deallocation of port_id %d by AP-I %d.", port_id, api); } @@ -1266,35 +1286,37 @@ static pid_t auto_execute(char ** argv) struct stat s; if (stat(argv[0], &s) != 0) { - LOG_WARN("Application %s does not exist.", argv[0]); + log_warn("Application %s does not exist.", argv[0]); return -1; } if (!(s.st_mode & S_IXUSR)) { - LOG_WARN("Application %s is not executable.", argv[0]); + log_warn("Application %s is not executable.", argv[0]); return -1; } api = fork(); if (api == -1) { - LOG_ERR("Failed to fork"); + log_err("Failed to fork"); return api; } if (api != 0) { - LOG_INFO("Instantiated %s as AP-I %d.", argv[0], api); + log_info("Instantiated %s as AP-I %d.", argv[0], api); return api; } execv(argv[0], argv); - LOG_ERR("Failed to execute %s.", argv[0]); + log_err("Failed to execute %s.", argv[0]); exit(EXIT_FAILURE); } -static struct irm_flow * flow_req_arr(pid_t api, char * dst_name, - char * ae_name, qoscube_t cube) +static struct irm_flow * flow_req_arr(pid_t api, + char * dst_name, + char * ae_name, + qoscube_t cube) { struct reg_entry * re = NULL; struct apn_entry * a = NULL; @@ -1305,8 +1327,8 @@ static struct irm_flow * flow_req_arr(pid_t api, char * dst_name, pid_t h_api = -1; int port_id = -1; - LOG_DBGF("Flow req arrived from IPCP %d for %s on AE %s.", - api, dst_name, ae_name); + log_dbg("Flow req arrived from IPCP %d for %s on AE %s.", + api, dst_name, ae_name); pthread_rwlock_rdlock(&irmd->state_lock); pthread_rwlock_wrlock(&irmd->reg_lock); @@ -1315,7 +1337,7 @@ static struct irm_flow * flow_req_arr(pid_t api, char * dst_name, if (re == NULL) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Unknown name: %s.", dst_name); + log_err("Unknown name: %s.", dst_name); return NULL; } @@ -1323,7 +1345,7 @@ static struct irm_flow * flow_req_arr(pid_t api, char * dst_name, case REG_NAME_IDLE: pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("No APs for %s.", dst_name); + log_err("No APs for %s.", dst_name); return NULL; case REG_NAME_AUTO_ACCEPT: c_api = malloc(sizeof(*c_api)); @@ -1341,7 +1363,7 @@ static struct irm_flow * flow_req_arr(pid_t api, char * dst_name, reg_entry_set_state(re, REG_NAME_AUTO_ACCEPT); pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Could not get start apn for reg_entry %s.", + log_err("Could not get start apn for reg_entry %s.", re->name); free(c_api); return NULL; @@ -1368,7 +1390,7 @@ static struct irm_flow * flow_req_arr(pid_t api, char * dst_name, if (h_api == -1) { pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Invalid api returned."); + log_err("Invalid api returned."); return NULL; } @@ -1376,7 +1398,7 @@ static struct irm_flow * flow_req_arr(pid_t api, char * dst_name, default: pthread_rwlock_unlock(&irmd->reg_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("IRMd in wrong state."); + log_err("IRMd in wrong state."); return NULL; } @@ -1395,7 +1417,7 @@ static struct irm_flow * flow_req_arr(pid_t api, char * dst_name, bmp_release(irmd->port_ids, port_id); pthread_rwlock_unlock(&irmd->flows_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Could not allocate port_id."); + log_err("Could not allocate port_id."); return NULL; } @@ -1417,7 +1439,7 @@ static struct irm_flow * flow_req_arr(pid_t api, char * dst_name, list_del(&f->next); pthread_rwlock_unlock(&irmd->flows_lock); pthread_rwlock_unlock(&irmd->state_lock); - LOG_ERR("Could not get api table entry for %d.", h_api); + log_err("Could not get api table entry for %d.", h_api); irm_flow_destroy(f); return NULL; } @@ -1432,7 +1454,8 @@ static struct irm_flow * flow_req_arr(pid_t api, char * dst_name, return f; } -static int flow_alloc_reply(int port_id, int response) +static int flow_alloc_reply(int port_id, + int response) { struct irm_flow * f; @@ -1465,7 +1488,7 @@ static void irm_destroy(void) pthread_rwlock_rdlock(&irmd->state_lock); if (irmd->state != IRMD_NULL) - LOG_WARN("Unsafe destroy."); + log_warn("Unsafe destroy."); if (irmd->threadpool != NULL) free(irmd->threadpool); @@ -1482,7 +1505,7 @@ static void irm_destroy(void) close(irmd->sockfd); if (unlink(IRM_SOCK_PATH)) - LOG_DBG("Failed to unlink %s.", IRM_SOCK_PATH); + log_dbg("Failed to unlink %s.", IRM_SOCK_PATH); pthread_rwlock_wrlock(&irmd->reg_lock); /* Clear the lists. */ @@ -1500,9 +1523,9 @@ static void irm_destroy(void) struct pid_el * e = list_entry(p, struct pid_el, next); int status; if (kill(e->pid, SIGTERM)) - LOG_DBG("Could not send kill signal to %d.", e->pid); + log_dbg("Could not send kill signal to %d.", e->pid); else if (waitpid(e->pid, &status, 0) < 0) - LOG_DBG("Error waiting for %d to exit.", e->pid); + log_dbg("Error waiting for %d to exit.", e->pid); list_del(&e->next); free(e); } @@ -1540,7 +1563,9 @@ static void irm_destroy(void) free(irmd); } -void irmd_sig_handler(int sig, siginfo_t * info, void * c) +void irmd_sig_handler(int sig, + siginfo_t * info, + void * c) { (void) info; (void) c; @@ -1549,7 +1574,7 @@ void irmd_sig_handler(int sig, siginfo_t * info, void * c) case SIGINT: case SIGTERM: case SIGHUP: - LOG_INFO("IRMd shutting down..."); + log_info("IRMd shutting down..."); pthread_rwlock_wrlock(&irmd->state_lock); @@ -1558,7 +1583,7 @@ void irmd_sig_handler(int sig, siginfo_t * info, void * c) pthread_rwlock_unlock(&irmd->state_lock); break; case SIGPIPE: - LOG_DBG("Ignored SIGPIPE."); + log_dbg("Ignored SIGPIPE."); default: return; } @@ -1618,7 +1643,7 @@ void * irm_sanitize(void * o) while (true) { if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) - LOG_WARN("Failed to get time."); + log_warn("Failed to get time."); /* Cleanup stale PENDING flows. */ pthread_rwlock_rdlock(&irmd->state_lock); @@ -1635,7 +1660,7 @@ void * irm_sanitize(void * o) waitpid(e->pid, &s, WNOHANG); if (kill(e->pid, 0) >= 0) continue; - LOG_DBG("Child process %d died, error %d.", e->pid, s); + log_dbg("Child process %d died, error %d.", e->pid, s); list_del(&e->next); free(e); } @@ -1645,7 +1670,7 @@ void * irm_sanitize(void * o) list_entry(p, struct api_entry, next); if (kill(e->api, 0) >= 0) continue; - LOG_DBG("Dead AP-I removed: %d.", e->api); + log_dbg("Dead AP-I removed: %d.", e->api); list_del(&e->next); api_entry_destroy(e); } @@ -1655,7 +1680,7 @@ void * irm_sanitize(void * o) list_entry(p, struct ipcp_entry, next); if (kill(e->api, 0) >= 0) continue; - LOG_DBG("Dead IPCP removed: %d.", e->api); + log_dbg("Dead IPCP removed: %d.", e->api); list_del(&e->next); ipcp_entry_destroy(e); } @@ -1670,7 +1695,7 @@ void * irm_sanitize(void * o) list_entry(p2, struct pid_el, next); if (kill(a->pid, 0) >= 0) continue; - LOG_DBG("Dead AP-I removed from: %d %s.", + log_dbg("Dead AP-I removed from: %d %s.", a->pid, e->name); reg_entry_del_pid_el(e, a); } @@ -1686,7 +1711,7 @@ void * irm_sanitize(void * o) if (irm_flow_get_state(f) == FLOW_ALLOC_PENDING && ts_diff_ms(&f->t0, &now) > IRMD_FLOW_TIMEOUT) { list_del(&f->next); - LOG_DBG("Pending port_id %d timed out.", + log_dbg("Pending port_id %d timed out.", f->port_id); clear_irm_flow(f); ipcp_flow_dealloc(f->n_1_api, f->port_id); @@ -1697,7 +1722,7 @@ void * irm_sanitize(void * o) if (kill(f->n_api, 0) < 0) { struct shm_flow_set * set; - LOG_DBG("AP-I %d gone, flow %d deallocated.", + log_dbg("AP-I %d gone, flow %d deallocated.", f->n_api, f->port_id); set = shm_flow_set_open(f->n_api); if (set != NULL) @@ -1712,7 +1737,7 @@ void * irm_sanitize(void * o) if (kill(f->n_1_api, 0) < 0) { struct shm_flow_set * set; list_del(&f->next); - LOG_ERR("IPCP %d gone, flow %d removed.", + log_err("IPCP %d gone, flow %d removed.", f->n_1_api, f->port_id); set = shm_flow_set_open(f->n_api); if (set != NULL) @@ -1773,11 +1798,11 @@ void * mainloop(void * o) if (setsockopt(cli_sockfd, SOL_SOCKET, SO_RCVTIMEO, (void *) &tv, sizeof(tv))) - LOG_WARN("Failed to set timeout on socket."); + log_warn("Failed to set timeout on socket."); count = read(cli_sockfd, buf, IRM_MSG_BUF_SIZE); if (count <= 0) { - LOG_ERR("Failed to read from socket."); + log_err("Failed to read from socket."); close(cli_sockfd); continue; } @@ -1917,7 +1942,7 @@ void * mainloop(void * o) msg->response); break; default: - LOG_ERR("Don't know that message code."); + log_err("Don't know that message code."); break; } @@ -1925,7 +1950,7 @@ void * mainloop(void * o) buffer.len = irm_msg__get_packed_size(&ret_msg); if (buffer.len == 0) { - LOG_ERR("Failed to calculate length of reply message."); + log_err("Failed to calculate length of reply message."); if (apis != NULL) free(apis); close(cli_sockfd); @@ -1946,7 +1971,7 @@ void * mainloop(void * o) free(apis); if (write(cli_sockfd, buffer.data, buffer.len) == -1) - LOG_WARN("Failed to send reply message."); + log_warn("Failed to send reply message."); free(buffer.data); close(cli_sockfd); @@ -1970,19 +1995,19 @@ static int irm_create(void) irmd->state = IRMD_NULL; if (pthread_rwlock_init(&irmd->state_lock, NULL)) { - LOG_ERR("Failed to initialize rwlock."); + log_err("Failed to initialize rwlock."); free(irmd); return -1; } if (pthread_rwlock_init(&irmd->reg_lock, NULL)) { - LOG_ERR("Failed to initialize rwlock."); + log_err("Failed to initialize rwlock."); free(irmd); return -1; } if (pthread_rwlock_init(&irmd->flows_lock, NULL)) { - LOG_ERR("Failed to initialize rwlock."); + log_err("Failed to initialize rwlock."); free(irmd); return -1; } @@ -2008,7 +2033,7 @@ static int irm_create(void) if (stat(SOCK_PATH, &st) == -1) { if (mkdir(SOCK_PATH, 0777)) { - LOG_ERR("Failed to create sockets directory."); + log_err("Failed to create sockets directory."); irm_destroy(); return -1; } @@ -2022,32 +2047,32 @@ static int irm_create(void) if (setsockopt(irmd->sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *) &timeout, sizeof(timeout)) < 0) { - LOG_ERR("Failed setting socket option."); + log_err("Failed setting socket option."); irm_destroy(); return -1; } if (chmod(IRM_SOCK_PATH, 0666)) { - LOG_ERR("Failed to chmod socket."); + log_err("Failed to chmod socket."); irm_destroy(); return -1; } if ((irmd->lf = lockfile_create()) == NULL) { if ((irmd->lf = lockfile_open()) == NULL) { - LOG_ERR("Lockfile error."); + log_err("Lockfile error."); irm_destroy(); return -1; } if (kill(lockfile_owner(irmd->lf), 0) < 0) { - LOG_INFO("IRMd didn't properly shut down last time."); + log_info("IRMd didn't properly shut down last time."); shm_rdrbuff_destroy(shm_rdrbuff_open()); - LOG_INFO("Stale resources cleaned."); + log_info("Stale resources cleaned."); lockfile_destroy(irmd->lf); irmd->lf = lockfile_create(); } else { - LOG_INFO("IRMd already running (%d), exiting.", + log_info("IRMd already running (%d), exiting.", lockfile_owner(irmd->lf)); lockfile_close(irmd->lf); free(irmd); @@ -2067,33 +2092,28 @@ static int irm_create(void) irmd->state = IRMD_RUNNING; - LOG_INFO("Ouroboros IPC Resource Manager daemon started..."); + log_info("Ouroboros IPC Resource Manager daemon started..."); return 0; } static void usage(void) { - LOG_ERR("Usage: irmd \n\n" + log_err("Usage: irmd \n\n" " [--stdout (Print to stdout instead of logs)]\n"); } -int main(int argc, char ** argv) +int main(int argc, + char ** argv) { struct sigaction sig_act; int t = 0; - char * log_file = INSTALL_PREFIX LOG_DIR "irmd.log"; - DIR * log_dir; - struct dirent * ent; - char * point; - char * log_path; - size_t len = 0; bool use_stdout = false; if (geteuid() != 0) { - LOG_ERR("IPC Resource Manager must be run as root."); + log_err("IPC Resource Manager must be run as root."); exit(EXIT_FAILURE); } @@ -2110,40 +2130,6 @@ int main(int argc, char ** argv) } } - if (!use_stdout && - (log_dir = opendir(INSTALL_PREFIX LOG_DIR)) != NULL) { - while ((ent = readdir(log_dir)) != NULL) { - point = strrchr(ent->d_name,'.'); - if (point == NULL || - strcmp(point, ".log") != 0) - continue; - - len += strlen(INSTALL_PREFIX); - len += strlen(LOG_DIR); - len += strlen(ent->d_name); - - log_path = malloc(len + 1); - if (log_path == NULL) { - LOG_ERR("Failed to malloc."); - exit(EXIT_FAILURE); - } - - strcpy(log_path, INSTALL_PREFIX); - strcat(log_path, LOG_DIR); - strcat(log_path, ent->d_name); - - unlink(log_path); - - free(log_path); - len = 0; - } - closedir(log_dir); - } - - if (!use_stdout && (set_logfile(log_file) < 0)) - LOG_ERR("Cannot open %s, falling back to stdout for logs.", - log_file); - /* Init sig_act. */ memset(&sig_act, 0, sizeof sig_act); @@ -2160,8 +2146,10 @@ int main(int argc, char ** argv) if (sigaction(SIGPIPE, &sig_act, NULL) < 0) exit(EXIT_FAILURE); + log_init(!use_stdout); + if (irm_create() < 0) { - close_logfile(); + log_fini(); exit(EXIT_FAILURE); } @@ -2183,9 +2171,9 @@ int main(int argc, char ** argv) irm_destroy(); - close_logfile(); + log_fini(); - LOG_INFO("Bye."); + log_info("Bye."); exit(EXIT_SUCCESS); } diff --git a/src/irmd/registry.c b/src/irmd/registry.c index fec69cfa..d22c1be3 100644 --- a/src/irmd/registry.c +++ b/src/irmd/registry.c @@ -189,13 +189,13 @@ int reg_entry_add_apn(struct reg_entry * e, struct apn_entry * a) struct str_el * n; if (reg_entry_has_apn(e, a->apn)) { - LOG_WARN("AP %s already accepting flows for %s.", + log_warn("AP %s already accepting flows for %s.", a->apn, e->name); return 0; } if (!(a->flags & BIND_AP_AUTO)) { - LOG_DBG("AP %s cannot be auto-instantiated.", a->apn); + log_dbg("AP %s cannot be auto-instantiated.", a->apn); return -EINVAL; } @@ -265,12 +265,12 @@ int reg_entry_add_api(struct reg_entry * e, pid_t api) return -EINVAL; if (reg_entry_has_api(e, api)) { - LOG_DBG("Instance already registered with this name."); + log_dbg("Instance already registered with this name."); return -EPERM; } if (e->state == REG_NAME_NULL) { - LOG_DBG("Tried to add instance in NULL state."); + log_dbg("Tried to add instance in NULL state."); return -EPERM; } @@ -418,19 +418,19 @@ struct reg_entry * registry_add_name(struct list_head * registry, return NULL; if (registry_has_name(registry, name)) { - LOG_DBG("Name %s already registered.", name); + log_dbg("Name %s already registered.", name); return NULL; } e = reg_entry_create(); if (e == NULL) { - LOG_DBG("Could not create registry entry."); + log_dbg("Could not create registry entry."); return NULL; } e = reg_entry_init(e, name); if (e == NULL) { - LOG_DBG("Could not initialize registry entry."); + log_dbg("Could not initialize registry entry."); reg_entry_destroy(e); return NULL; } diff --git a/src/lib/bitmap.c b/src/lib/bitmap.c index 5905dfee..255f2b4d 100644 --- a/src/lib/bitmap.c +++ b/src/lib/bitmap.c @@ -21,10 +21,7 @@ * 02110-1301 USA */ -#define OUROBOROS_PREFIX "bitmap" - #include -#include #include #include #include diff --git a/src/lib/irm.c b/src/lib/irm.c index 8b312833..477547a2 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -20,13 +20,10 @@ * 02110-1301 USA */ -#define OUROBOROS_PREFIX "libouroboros-irm" - #include #include #include #include -#include #include #include @@ -220,10 +217,9 @@ int irm_enroll_ipcp(pid_t api, msg.api = api; msg.n_dif_name = 1; msg.dif_name = malloc(sizeof(*(msg.dif_name))); - if (msg.dif_name == NULL) { - LOG_ERR("Failed to malloc"); + if (msg.dif_name == NULL) return -ENOMEM; - } + msg.dif_name[0] = dif_name; recv_msg = send_recv_irm_msg(&msg); diff --git a/src/lib/logs.c b/src/lib/logs.c index 449ee191..3184773f 100644 --- a/src/lib/logs.c +++ b/src/lib/logs.c @@ -3,7 +3,8 @@ * * Logging facilities * - * Sander Vrijders + * Sander Vrijders + * Dimitri Staessens * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -24,19 +25,18 @@ #include -FILE * logfile = NULL; +bool log_syslog; -int set_logfile(char * filename) +void log_init(bool sysout) { - logfile = fopen(filename, "w"); - if (logfile == NULL) - return -1; + log_syslog = sysout; - return 0; + if (log_syslog) + openlog(NULL, LOG_PID, LOG_DAEMON); } -void close_logfile() +void log_fini(void) { - if (logfile != NULL) - fclose(logfile); + if (log_syslog) + closelog(); } diff --git a/src/nsmd/main.c b/src/nsmd/main.c index b30b9dd9..f3b87330 100644 --- a/src/nsmd/main.c +++ b/src/nsmd/main.c @@ -4,7 +4,7 @@ int main(void) { - LOG_DBG("Test of the DA"); + log_dbg("Test of the DA"); return 0; } -- cgit v1.2.3