The sa_log_*() routines are generic logging facilities, whereas the SA_LOG_*() macros are application specific.
This patch moves all of the SA_LOG_*() macros to fcoemon.h and renames them to FCM_LOG_*(). Signed-off-by: Robert Love <[email protected]> --- fcoemon.c | 99 +++++++++++++++++++++++++++---------------------------- fcoemon.h | 13 +++++++ fcoemon_utils.h | 13 ------- 3 files changed, 62 insertions(+), 63 deletions(-) diff --git a/fcoemon.c b/fcoemon.c index ec4e058..2bf2335 100644 --- a/fcoemon.c +++ b/fcoemon.c @@ -249,9 +249,9 @@ fcm_read_config_variable(char *file, char *val_buf, size_t len, *s = '\0'; n = snprintf(val_buf, len, "%s", val); if (fcm_remove_quotes(val_buf, n) < 0) { - SA_LOG("Invalid format in config file" - " %s: %s=%s\n", - file, var_name, val); + FCM_LOG("Invalid format in config file" + " %s: %s=%s\n", + file, var_name, val); /* error */ return -1; } @@ -279,7 +279,7 @@ fcm_read_config_files(void) strncpy(file, CONFIG_DIR "/" "config", sizeof(file)); fp = fopen(file, "r"); if (!fp) { - SA_LOG_ERR(errno, "Failed reading %s\n", file); + FCM_LOG_ERR(errno, "Failed reading %s\n", file); exit(1); } @@ -306,8 +306,7 @@ fcm_read_config_files(void) dir = opendir(CONFIG_DIR); if (dir == NULL) { - SA_LOG_ERR(errno, - "Failed reading directory %s\n", CONFIG_DIR); + FCM_LOG_ERR(errno, "Failed reading directory %s\n", CONFIG_DIR); return -1; } for (;;) { @@ -335,7 +334,7 @@ fcm_read_config_files(void) strncat(file, dp->d_name, sizeof(file) - strlen(file)); fp = fopen(file, "r"); if (!fp) { - SA_LOG_ERR(errno, "Failed reading %s\n", file); + FCM_LOG_ERR(errno, "Failed reading %s\n", file); exit(1); } @@ -408,7 +407,7 @@ fcm_link_init(void) fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); if (fd < 0) { - SA_LOG_ERR(errno, "socket error"); + FCM_LOG_ERR(errno, "socket error"); return fd; } memset(&l_local, 0, sizeof(l_local)); @@ -417,7 +416,7 @@ fcm_link_init(void) l_local.nl_pid = 0; rc = bind(fd, (struct sockaddr *)&l_local, sizeof(l_local)); if (rc == -1) { - SA_LOG_ERR(errno, "bind error"); + FCM_LOG_ERR(errno, "bind error"); return rc; } fcm_link_socket = fd; @@ -448,7 +447,7 @@ fcm_link_recv(void *arg) rc = read(fcm_link_socket, buf, fcm_link_buf_size); if (rc <= 0) { if (rc < 0) - SA_LOG_ERR(errno, "read error"); + FCM_LOG_ERR(errno, "read error"); return; } hp = (struct nlmsghdr *)buf; @@ -459,13 +458,13 @@ fcm_link_recv(void *arg) if (hp->nlmsg_type == NLMSG_DONE) break; if (hp->nlmsg_type == NLMSG_ERROR) { - SA_LOG("nlmsg error"); + FCM_LOG("nlmsg error"); break; } plen = NLMSG_PAYLOAD(hp, 0); ip = (struct ifinfomsg *)NLMSG_DATA(hp); if (plen < sizeof(*ip)) { - SA_LOG("too short (%d) to be a LINK message", rc); + FCM_LOG("too short (%d) to be a LINK message", rc); break; } switch (type) { @@ -544,7 +543,7 @@ fcm_link_getlink(void) msg.ifi.ifi_type = ARPHRD_ETHER; rc = write(fcm_link_socket, &msg, sizeof(msg)); if (rc < 0) - SA_LOG_ERR(errno, "write error"); + FCM_LOG_ERR(errno, "write error"); } /* @@ -745,7 +744,7 @@ fcm_dcbd_connect(void) ASSERT(fcm_clif->cl_fd < 0); fd = socket(PF_UNIX, SOCK_DGRAM, 0); if (fd < 0) { - SA_LOG_ERR(errno, "clif socket open failed"); /* XXX */ + FCM_LOG_ERR(errno, "clif socket open failed"); /* XXX */ return 0; } @@ -755,7 +754,7 @@ fcm_dcbd_connect(void) CLIF_LOCAL_SUN_PATH, getpid()); rc = bind(fd, (struct sockaddr *)lp, sizeof(*lp)); if (rc < 0) { - SA_LOG_ERR(errno, "clif bind failed"); + FCM_LOG_ERR(errno, "clif bind failed"); close(fd); return 0; } @@ -766,7 +765,7 @@ fcm_dcbd_connect(void) CLIF_NAME_PATH); rc = connect(fd, (struct sockaddr *)&dest, sizeof(dest)); if (rc < 0) { - SA_LOG_ERR(errno, "clif connect failed"); + FCM_LOG_ERR(errno, "clif connect failed"); unlink(lp->sun_path); close(fd); return 0; @@ -909,7 +908,7 @@ fcm_dcbd_rx(void *arg) len = sizeof(buf); rc = read(clif->cl_fd, buf, sizeof(buf) - 1); if (rc < 0) - SA_LOG_ERR(errno, "read"); + FCM_LOG_ERR(errno, "read"); else if ((rc > 0) && (rc < sizeof(buf))) { ASSERT(rc < sizeof(buf)); buf[rc] = '\0'; @@ -923,13 +922,13 @@ fcm_dcbd_rx(void *arg) st = fcm_get_hex(buf + CLIF_STAT_OFF, CLIF_STAT_LEN, &ep); if (ep != NULL) - SA_LOG("unexpected response code from dcbd: " - "len %d buf %s rc %d", len, buf, rc); + FCM_LOG("unexpected response code from dcbd: " + "len %d buf %s rc %d", len, buf, rc); else if (st != cmd_success && st != cmd_device_not_found) { - SA_LOG("error response from dcbd: " - "error %d len %d %s", - st, len, buf); + FCM_LOG("error response from dcbd: " + "error %d len %d %s", + st, len, buf); } fcm_clif->cl_busy = 0; @@ -948,9 +947,9 @@ fcm_dcbd_rx(void *arg) case LEVEL_CMD: break; default: - SA_LOG("Unexpected cmd in response " - "from dcbd: len %d %s", - len, buf); + FCM_LOG("Unexpected cmd in response " + "from dcbd: len %d %s", + len, buf); break; } fcm_dcbd_next(); /* advance ports if possible */ @@ -960,8 +959,8 @@ fcm_dcbd_rx(void *arg) fcm_dcbd_event(buf, len); break; default: - SA_LOG("Unexpected message from dcbd: len %d buf %s", - len, buf); + FCM_LOG("Unexpected message from dcbd: len %d buf %s", + len, buf); break; } } @@ -986,7 +985,7 @@ fcm_dcbd_request(char *req) fcm_clif->cl_busy = 1; rc = write(fcm_clif->cl_fd, req, len); if (rc < 0) { - SA_LOG_ERR(errno, "Failed write req %s len %d", req, len); + FCM_LOG_ERR(errno, "Failed write req %s len %d", req, len); fcm_clif->cl_busy = 0; fcm_dcbd_disconnect(); fcm_dcbd_connect(); @@ -1020,12 +1019,12 @@ fcm_dcbd_get_port(char **msgp, size_t len_off, size_t len_len, size_t len) if_len = fcm_get_hex(msg + len_off, len_len, &ep); if (ep != NULL) { - SA_LOG("Parse error on port len: msg %s", msg); + FCM_LOG("Parse error on port len: msg %s", msg); return NULL; } if (len_off + len_len + if_len > len) { - SA_LOG("Invalid port len %d msg %s", if_len, msg); + FCM_LOG("Invalid port len %d msg %s", if_len, msg); return NULL; } msg += len_off + len_len; @@ -1033,7 +1032,7 @@ fcm_dcbd_get_port(char **msgp, size_t len_off, size_t len_len, size_t len) *msgp = msg + if_len; ff = fcm_fcoe_lookup_name(ifname); if (ff == NULL) { - SA_LOG("ifname '%s' not found", ifname); + FCM_LOG("ifname '%s' not found", ifname); exit(1); /* XXX */ } return ff; @@ -1370,31 +1369,31 @@ fcm_dcbd_cmd_resp(char *resp, cmd_status st) len = strlen(resp); ver = fcm_get_hex(resp + DCB_VER_OFF, DCB_VER_LEN, &ep); if (ep != NULL) { - SA_LOG("parse error: resp %s", orig_resp); + FCM_LOG("parse error: resp %s", orig_resp); return; } else if (ver != CLIF_RSP_VERSION) { - SA_LOG("unexpected version %d resp %s", ver, orig_resp); + FCM_LOG("unexpected version %d resp %s", ver, orig_resp); return; } cmd = fcm_get_hex(resp + DCB_CMD_OFF, DCB_CMD_LEN, &ep); if (ep != NULL) { - SA_LOG("parse error on resp cmd: resp %s", orig_resp); + FCM_LOG("parse error on resp cmd: resp %s", orig_resp); return; } feature = fcm_get_hex(resp + DCB_FEATURE_OFF, DCB_FEATURE_LEN, &ep); if (ep != NULL) { - SA_LOG("parse error on resp feature: resp %s", orig_resp); + FCM_LOG("parse error on resp feature: resp %s", orig_resp); return; } subtype = fcm_get_hex(resp + DCB_SUBTYPE_OFF, DCB_SUBTYPE_LEN, &ep); if (ep != NULL) { - SA_LOG("parse error on resp subtype: resp %s", orig_resp); + FCM_LOG("parse error on resp subtype: resp %s", orig_resp); return; } cp = resp; ff = fcm_dcbd_get_port(&cp, DCB_PORTLEN_OFF, DCB_PORTLEN_LEN, len); if (ff == NULL) { - SA_LOG("port not found. resp %s", orig_resp); + FCM_LOG("port not found. resp %s", orig_resp); return; } @@ -1666,7 +1665,7 @@ fcm_dcbd_event(char *msg, size_t len) if (msg[EV_LEVEL_OFF] != MSG_DCB + '0' || len <= EV_PORT_ID_OFF) return; if (msg[EV_VERSION_OFF] != CLIF_EV_VERSION + '0') { - SA_LOG("Unexpected version in event msg %s", msg); + FCM_LOG("Unexpected version in event msg %s", msg); return; } cp = msg; @@ -1770,7 +1769,7 @@ fcm_dcbd_setup(struct fcm_fcoe *ff, enum fcoeadm_action action) rc = fork(); if (rc < 0) { - SA_LOG_ERR(errno, "fork error"); + FCM_LOG_ERR(errno, "fork error"); } else if (rc == 0) { /* child process */ for (fd = ulimit(4 /* __UL_GETOPENMAX */ , 0); fd > 2; fd--) close(fd); @@ -1806,7 +1805,7 @@ fcm_dcbd_setup(struct fcm_fcoe *ff, enum fcoeadm_action action) execlp(fcm_dcbd_cmd, fcm_dcbd_cmd, ff->ff_name, op, qos_arg, qos, (char *)NULL); - SA_LOG_ERR(errno, "exec '%s' failed", fcm_dcbd_cmd); + FCM_LOG_ERR(errno, "exec '%s' failed", fcm_dcbd_cmd); exit(1); } } @@ -1973,9 +1972,9 @@ fcm_pidfile_create(void) pid = atoi(sp); rc = kill(pid, 0); if (sp && (pid > 0) && !rc) { - SA_LOG("Another instance" - " (pid %d) is running - exiting\n", - pid); + FCM_LOG("Another instance" + " (pid %d) is running - exiting\n", + pid); exit(1); } fclose(fp); @@ -2027,7 +2026,7 @@ int main(int argc, char **argv) pid = fork(); if (pid < 0) { - SA_LOG("Starting daemon failed"); + FCM_LOG("Starting daemon failed"); exit(EXIT_FAILURE); } else if (pid) exit(EXIT_SUCCESS); @@ -2051,17 +2050,17 @@ int main(int argc, char **argv) sig.sa_handler = fcm_sig; rc = sigaction(SIGINT, &sig, NULL); if (rc < 0) { - SA_LOG_ERR(errno, "sigaction failed"); + FCM_LOG_ERR(errno, "sigaction failed"); exit(1); } rc = sigaction(SIGTERM, &sig, NULL); if (rc < 0) { - SA_LOG_ERR(errno, "sigaction failed"); + FCM_LOG_ERR(errno, "sigaction failed"); exit(1); } rc = sigaction(SIGHUP, &sig, NULL); if (rc < 0) { - SA_LOG_ERR(errno, "sigaction failed"); + FCM_LOG_ERR(errno, "sigaction failed"); exit(1); } fcm_pidfile_create(); @@ -2071,7 +2070,7 @@ int main(int argc, char **argv) rc = sa_select_loop(); if (rc < 0) { - SA_LOG_ERR(rc, "select error\n"); + FCM_LOG_ERR(rc, "select error\n"); exit(EXIT_FAILURE); } fcm_dcbd_shutdown(); @@ -2094,7 +2093,7 @@ print_errors(char *buf, int errors) if (!errors) { j = sprintf(msg + len, "none\n"); - SA_LOG("%s %s", buf, msg); + FCM_LOG("%s %s", buf, msg); return; } @@ -2138,6 +2137,6 @@ print_errors(char *buf, int errors) sprintf(msg + j, "peer feature not present"); } - SA_LOG("%s %s\n", buf, msg); + FCM_LOG("%s %s\n", buf, msg); } diff --git a/fcoemon.h b/fcoemon.h index 43d18d7..0c4089d 100644 --- a/fcoemon.h +++ b/fcoemon.h @@ -22,6 +22,19 @@ int fcm_debug; +/* + * Log message. + */ +#define FCM_LOG(...) \ + do { \ + sa_log_func(__func__, __VA_ARGS__); \ + } while (0) + +#define FCM_LOG_ERR(error, ...) \ + do { \ + sa_log_err(error, NULL, __VA_ARGS__); \ + } while (0) + #define FCM_LOG_DBG(fmt, args...) \ do { \ if (fcm_debug) \ diff --git a/fcoemon_utils.h b/fcoemon_utils.h index cab02eb..12769f6 100644 --- a/fcoemon_utils.h +++ b/fcoemon_utils.h @@ -53,19 +53,6 @@ void sa_log_abort(const char *); /* log message and abort */ #define __SA_STRING(x) #x /* - * Log message. - */ -#define SA_LOG(...) \ - do { \ - sa_log_func(__func__, __VA_ARGS__); \ - } while (0) - -#define SA_LOG_ERR(error, ...) \ - do { \ - sa_log_err(error, NULL, __VA_ARGS__); \ - } while (0) - -/* * Logging options. */ #define SA_LOGF_TIME 0x0001 /* include timestamp in message */ _______________________________________________ devel mailing list [email protected] http://www.open-fcoe.org/mailman/listinfo/devel
