diff options
Diffstat (limited to 'usr/src/cmd')
21 files changed, 387 insertions, 329 deletions
diff --git a/usr/src/cmd/dcs/sparc/sun4u/rdr_messages.c b/usr/src/cmd/dcs/sparc/sun4u/rdr_messages.c index 51b836a57b..187319c234 100644 --- a/usr/src/cmd/dcs/sparc/sun4u/rdr_messages.c +++ b/usr/src/cmd/dcs/sparc/sun4u/rdr_messages.c @@ -23,8 +23,6 @@ * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* * WARNING: The contents of this file are shared by all projects * that wish to perform remote Dynamic Reconfiguration (DR) @@ -121,7 +119,7 @@ struct { { SHORTMSG, NOMSG }, /* RDR_CONF_HELP */ { SHORTMSG, NOMSG }, /* RDR_CONF_AP_ID_CMP */ { SHORTMSG, NOMSG }, /* RDR_CONF_ABORT_CMD */ - { SHORTMSG, SHORTMSG }, /* RDR_CONF_CONFIRM_CALLBACK */ + { SHORTMSG, SHORTMSG }, /* RDR_CONF_CONFIRM_CALLBACK */ { SHORTMSG, NOMSG }, /* RDR_CONF_MSG_CALLBACK */ { SHORTMSG, LONGMSG } /* RDR_RSRC_INFO */ }; @@ -129,7 +127,7 @@ struct { #define RDR_BAD_FD (-1) -#define RDR_MSG_HDR_SIZE sizeof (rdr_msg_hdr_t) +#define RDR_MSG_HDR_SIZE sizeof (rdr_msg_hdr_t) static const int RDR_ALIGN_64_BIT = 8; /* 8 bytes */ @@ -364,7 +362,7 @@ rdr_open(int family) int newfd; - if ((newfd = socket(family, SOCK_STREAM, 0)) == NULL) { + if ((newfd = socket(family, SOCK_STREAM, 0)) == -1) { return (RDR_BAD_FD); } @@ -2013,7 +2011,7 @@ static int unpack_change_state_request(change_state_params_t *params, const char *buf) { char *bufptr; - rdr_variable_message_info_t var_msg_info; + rdr_variable_message_info_t var_msg_info; rdr_change_state_t change_state_data; @@ -2105,7 +2103,7 @@ pack_change_state_reply(change_state_params_t *params, char **buf, int i; char *bufptr; rdr_change_state_reply_t change_state_data; - rdr_variable_message_info_t var_msg_info; + rdr_variable_message_info_t var_msg_info; (void) memset(&var_msg_info, 0, sizeof (rdr_variable_message_info_t)); @@ -2348,7 +2346,7 @@ static int unpack_private_func_request(private_func_params_t *params, const char *buf) { char *bufptr; - rdr_variable_message_info_t var_msg_info; + rdr_variable_message_info_t var_msg_info; rdr_private_func_t private_func_data; @@ -2443,7 +2441,7 @@ pack_private_func_reply(private_func_params_t *params, char **buf, int i; char *bufptr; rdr_private_func_reply_t private_func_data; - rdr_variable_message_info_t var_msg_info; + rdr_variable_message_info_t var_msg_info; (void) memset(&var_msg_info, 0, sizeof (rdr_variable_message_info_t)); @@ -2657,7 +2655,7 @@ static int unpack_test_request(test_params_t *params, const char *buf) { char *bufptr; - rdr_variable_message_info_t var_msg_info; + rdr_variable_message_info_t var_msg_info; rdr_test_t test_data; @@ -2733,7 +2731,7 @@ pack_test_reply(test_params_t *params, char **buf, int *buf_size) int i; char *bufptr; rdr_test_reply_t test_data; - rdr_variable_message_info_t var_msg_info; + rdr_variable_message_info_t var_msg_info; if ((params == NULL) || (buf == NULL) || (buf_size == NULL)) { @@ -2836,8 +2834,8 @@ pack_list_ext_request(list_ext_params_t *params, char **buf, int *buf_size) { int i; char *bufptr; - rdr_list_ext_t list_ext_data; - rdr_variable_message_info_t var_msg_info; + rdr_list_ext_t list_ext_data; + rdr_variable_message_info_t var_msg_info; if ((params == NULL) || (buf == NULL) || (buf_size == NULL)) { @@ -2959,7 +2957,7 @@ static int unpack_list_ext_request(list_ext_params_t *params, const char *buf) { char *bufptr; - rdr_variable_message_info_t var_msg_info; + rdr_variable_message_info_t var_msg_info; rdr_list_ext_t list_ext_data; @@ -3024,7 +3022,7 @@ unpack_list_ext_request(list_ext_params_t *params, const char *buf) } *(params->errstring) = NULL; } else { /* error_msg_ctl == RDR_DONT_GENERATE_ERR_MSGS */ - params->errstring = NULL; + params->errstring = NULL; } params->flags = list_ext_data.flags; params->permissions = list_ext_data.permissions; @@ -3044,8 +3042,8 @@ pack_list_ext_reply(list_ext_params_t *params, char **buf, int *buf_size) int i; char *bufptr; rdr_list_ext_reply_t list_ext_data; - rdr_variable_message_info_t var_msg_info; - int list_data_size; + rdr_variable_message_info_t var_msg_info; + int list_data_size; (void) memset(&var_msg_info, 0, sizeof (rdr_variable_message_info_t)); @@ -3132,8 +3130,8 @@ pack_list_ext_reply(list_ext_params_t *params, char **buf, int *buf_size) static int unpack_list_ext_reply(list_ext_params_t *params, const char *buf) { - int list_data_size; - char *bufptr; + int list_data_size; + char *bufptr; rdr_list_ext_reply_t list_ext_data; @@ -3160,7 +3158,7 @@ unpack_list_ext_reply(list_ext_params_t *params, const char *buf) return (RDR_MEM_ALLOC); } *(params->ap_id_list) = (rdr_list_t *) - malloc(sizeof (rdr_list_t) * list_ext_data.num_ap_ids); + malloc(sizeof (rdr_list_t) * list_ext_data.num_ap_ids); if (*(params->ap_id_list) == NULL) { return (RDR_MEM_ALLOC); } @@ -3177,7 +3175,7 @@ unpack_list_ext_reply(list_ext_params_t *params, const char *buf) return (RDR_MEM_ALLOC); } if (get_string_from_buf(params->errstring, - list_ext_data.errstring_size, bufptr)) { + list_ext_data.errstring_size, bufptr)) { return (RDR_ERROR); } bufptr += list_ext_data.errstring_size; @@ -3300,7 +3298,7 @@ static int unpack_help_request(help_params_t *params, const char *buf) { char *bufptr; - rdr_variable_message_info_t var_msg_info; + rdr_variable_message_info_t var_msg_info; rdr_help_t help_data; @@ -3569,8 +3567,8 @@ pack_confirm_request(confirm_callback_params_t *params, char **buf, int i; char *bufptr; rdr_confirm_callback_t confirm_callback_data; - int message_strlen; - int message_pad_sz; + int message_strlen; + int message_pad_sz; if ((params == NULL) || (buf == NULL) || (buf_size == NULL)) { @@ -3919,7 +3917,7 @@ pack_rsrc_info_request(rsrc_info_params_t *params, char **buf, int *buf_size) { char *bufptr; rdr_rsrc_info_t rsrc_info_data; - rdr_variable_message_info_t var_msg_info; + rdr_variable_message_info_t var_msg_info; if ((params == NULL) || (buf == NULL) || (buf_size == NULL)) { @@ -3992,7 +3990,7 @@ static int unpack_rsrc_info_request(rsrc_info_params_t *params, const char *buf) { char *bufptr; - rdr_variable_message_info_t var_msg_info; + rdr_variable_message_info_t var_msg_info; rdr_rsrc_info_t rsrc_info_data; @@ -4040,7 +4038,7 @@ pack_rsrc_info_reply(rsrc_info_params_t *params, char **buf, int *buf_size, rdr_rsrc_info_reply_t rsrc_info_data; int pack_status; caddr_t rsrc_info_bufp = NULL; - size_t rsrc_info_size; + size_t rsrc_info_size; if ((params == NULL) || (buf == NULL) || (buf_size == NULL)) { @@ -4100,7 +4098,7 @@ static int unpack_rsrc_info_reply(rsrc_info_params_t *params, const char *buf) { int unpack_status; - char *bufptr; + char *bufptr; rdr_rsrc_info_reply_t rsrc_info_data; @@ -4220,7 +4218,7 @@ unpack_ap_ids(int num_ap_ids, char **ap_ids, const char *buf, var_msg_info->ap_id_int_size = sizeof (int) * num_ap_ids; if (num_ap_ids > 0) { var_msg_info->ap_id_sizes = (int *) - malloc(sizeof (int) * var_msg_info->ap_id_int_size); + malloc(sizeof (int) * var_msg_info->ap_id_int_size); if (var_msg_info->ap_id_sizes == NULL) { return (RDR_MEM_ALLOC); } @@ -4236,7 +4234,7 @@ unpack_ap_ids(int num_ap_ids, char **ap_ids, const char *buf, continue; } if ((chars_copied + ap_id_size) > - var_msg_info->ap_id_char_size) { + var_msg_info->ap_id_char_size) { return (RDR_ERROR); } ap_ids[i] = (char *)malloc(ap_id_size); diff --git a/usr/src/cmd/fm/modules/sun4/cpumem-diagnosis/cmd_cpu.c b/usr/src/cmd/fm/modules/sun4/cpumem-diagnosis/cmd_cpu.c index a86318e0bc..266af44b0d 100644 --- a/usr/src/cmd/fm/modules/sun4/cpumem-diagnosis/cmd_cpu.c +++ b/usr/src/cmd/fm/modules/sun4/cpumem-diagnosis/cmd_cpu.c @@ -1313,7 +1313,7 @@ cmd_trw_alloc(uint64_t ena, uint64_t afar) for (i = 0; i < cmd.cmd_xxcu_ntrw; i++) { cmd_xxcu_trw_t *trw = &cmd.cmd_xxcu_trw[i]; - if (trw->trw_ena == NULL) { + if (trw->trw_ena == 0) { trw->trw_ena = ena; trw->trw_afar = afar; return (trw); diff --git a/usr/src/cmd/fm/modules/sun4/cpumem-diagnosis/cmd_cpuerr.c b/usr/src/cmd/fm/modules/sun4/cpumem-diagnosis/cmd_cpuerr.c index 25ea7bdfb3..711624846c 100644 --- a/usr/src/cmd/fm/modules/sun4/cpumem-diagnosis/cmd_cpuerr.c +++ b/usr/src/cmd/fm/modules/sun4/cpumem-diagnosis/cmd_cpuerr.c @@ -267,6 +267,7 @@ cmd_nop_hdlr(fmd_hdl_t *hdl, cmd_xr_t *xr, fmd_event_t *ep) fmd_hdl_debug(hdl, "nop train resolved for clcode %llx\n", xr->xr_clcode); } + /*ARGSUSED*/ static void cmd_xxu_hdlr(fmd_hdl_t *hdl, cmd_xr_t *xr, fmd_event_t *ep) @@ -399,7 +400,7 @@ cmd_xxcu_resolve(fmd_hdl_t *hdl, cmd_xr_t *xr, fmd_event_t *ep, uint64_t afar; - afar = NULL; + afar = 0; if (xr->xr_afar_status == AFLT_STAT_VALID) afar = xr->xr_afar; @@ -500,7 +501,7 @@ cmd_xxcu_initial(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl, if (cmd_afar_valid(hdl, nvl, clcode, &afar) != 0) { afar_status = AFLT_STAT_INVALID; - afar = NULL; + afar = 0; } else { afar_status = AFLT_STAT_VALID; } diff --git a/usr/src/cmd/fm/modules/sun4/cpumem-diagnosis/cmd_memerr.c b/usr/src/cmd/fm/modules/sun4/cpumem-diagnosis/cmd_memerr.c index 5ef66b5b42..7258d7860a 100644 --- a/usr/src/cmd/fm/modules/sun4/cpumem-diagnosis/cmd_memerr.c +++ b/usr/src/cmd/fm/modules/sun4/cpumem-diagnosis/cmd_memerr.c @@ -868,7 +868,7 @@ cmd_ue_common(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl, if (fmd_nvl_fmri_expand(hdl, asru) < 0) { CMD_STAT_BUMP(bad_mem_asru); - return (NULL); + return (CMD_EVD_BAD); } if ((bank = cmd_bank_lookup(hdl, asru)) == NULL && diff --git a/usr/src/cmd/fm/modules/sun4u/cpumem-diagnosis/cmd_memerr_arch.c b/usr/src/cmd/fm/modules/sun4u/cpumem-diagnosis/cmd_memerr_arch.c index 431b7459c9..448852c4c4 100644 --- a/usr/src/cmd/fm/modules/sun4u/cpumem-diagnosis/cmd_memerr_arch.c +++ b/usr/src/cmd/fm/modules/sun4u/cpumem-diagnosis/cmd_memerr_arch.c @@ -345,8 +345,8 @@ cmd_ioxefrx_fire(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl, (void) nvlist_lookup_uint64(nvl, FIRE_JBC_JITEL1, &afar); rferr->rf_afar = afar & FIRE_JBC_ADDR_MASK; - rferr->rf_afsr = NULL; - rferr->rf_synd = NULL; + rferr->rf_afsr = 0; + rferr->rf_synd = 0; if (nvlist_lookup_string(nvl, FM_EREPORT_PAYLOAD_NAME_ERR_TYPE, &typenm) == 0) @@ -624,7 +624,8 @@ int msynd2bit [] = { /* msynd 0-F */ }; int -cmd_synd2upos(uint16_t syndrome) { +cmd_synd2upos(uint16_t syndrome) +{ return (esynd2bit[syndrome]); } @@ -647,7 +648,7 @@ struct plat2id_map { {"SUNW,Sun-Fire-15000", 1}, {"SUNW,Sun-Fire", 2}, {"SUNW,Netra-T12", 2}, - {"SUNW,Sun-Fire-480R", 3}, + {"SUNW,Sun-Fire-480R", 3}, {"SUNW,Sun-Fire-V490", 3}, {"SUNW,Sun-Fire-V440", 3}, {"SUNW,Sun-Fire-V445", 3}, diff --git a/usr/src/cmd/fm/modules/sun4v/cpumem-diagnosis/cmd_memerr_arch.c b/usr/src/cmd/fm/modules/sun4v/cpumem-diagnosis/cmd_memerr_arch.c index b8005adff2..d784fb4c91 100644 --- a/usr/src/cmd/fm/modules/sun4v/cpumem-diagnosis/cmd_memerr_arch.c +++ b/usr/src/cmd/fm/modules/sun4v/cpumem-diagnosis/cmd_memerr_arch.c @@ -64,7 +64,7 @@ #define FBR_ERROR ".fbr" #define DSU_ERROR ".dsu" #define FERG_INVALID ".invalid" -#define DBU_ERROR ".dbu" +#define DBU_ERROR ".dbu" extern ldom_hdl_t *cpumem_diagnosis_lhp; @@ -367,17 +367,17 @@ cmd_fb(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl, const char *class, if (nvlist_lookup_nvlist(nvl, FM_RSRC_RESOURCE, &asru) < 0) { CMD_STAT_BUMP(bad_mem_asru); - return (NULL); + return (CMD_EVD_UNUSED); } if (nvlist_lookup_nvlist(nvl, FM_EREPORT_DETECTOR, &det) < 0) { CMD_STAT_BUMP(bad_mem_asru); - return (NULL); + return (CMD_EVD_UNUSED); } if (fmd_nvl_fmri_expand(hdl, det) < 0) { fmd_hdl_debug(hdl, "Failed to expand detector"); - return (NULL); + return (CMD_EVD_UNUSED); } branch = cmd_branch_lookup(hdl, asru); @@ -612,12 +612,13 @@ static int galois_mul[16][16] = { }; static int -galois_div(int num, int denom) { +galois_div(int num, int denom) +{ int i; for (i = 0; i < 16; i++) { if (galois_mul[denom][i] == num) - return (i); + return (i); } return (-1); } @@ -628,8 +629,8 @@ galois_div(int num, int denom) { */ int -cmd_synd2upos(uint16_t syndrome) { - +cmd_synd2upos(uint16_t syndrome) +{ uint16_t s0, s1, s2, s3; if (syndrome == 0) @@ -672,8 +673,8 @@ cmd_synd2upos(uint16_t syndrome) { } nvlist_t * -cmd_mem2hc(fmd_hdl_t *hdl, nvlist_t *mem_fmri) { - +cmd_mem2hc(fmd_hdl_t *hdl, nvlist_t *mem_fmri) +{ char **snp; uint_t n; diff --git a/usr/src/cmd/fm/modules/sun4v/etm/etm.c b/usr/src/cmd/fm/modules/sun4v/etm/etm.c index 09ea0549f0..ff50c2a888 100644 --- a/usr/src/cmd/fm/modules/sun4v/etm/etm.c +++ b/usr/src/cmd/fm/modules/sun4v/etm/etm.c @@ -179,10 +179,10 @@ static fmd_xprt_t *etm_fmd_xprt = NULL; /* FMD transport layer handle */ static pthread_t -etm_svr_tid = NULL; /* thread id of connection acceptance server */ +etm_svr_tid = 0; /* thread id of connection acceptance server */ static pthread_t -etm_resp_tid = NULL; /* thread id of msg responder */ +etm_resp_tid = 0; /* thread id of msg responder */ static etm_resp_q_ele_t *etm_resp_q_head = NULL; /* ptr to cur head of responder queue */ @@ -554,7 +554,7 @@ static pthread_mutex_t iosvc_list_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_t -etm_async_e_tid = NULL; /* thread id of io svc async event handler */ +etm_async_e_tid = 0; /* thread id of io svc async event handler */ static etm_proto_v1_ev_hdr_t iosvc_hdr = { ETM_PROTO_MAGIC_NUM, /* magic number */ @@ -587,8 +587,8 @@ static etm_iosvc_t io_svc = { 0, /* xid of last event posted to FMD */ DS_INVALID_HDL, /* DS handle */ NULL, /* fmd xprt handle */ - NULL, /* tid 4 send to remote RootDomain */ - NULL, /* tid 4 recv from remote RootDomain */ + 0, /* tid 4 send to remote RootDomain */ + 0, /* tid 4 recv from remote RootDomain */ PTHREAD_COND_INITIALIZER, /* nudges etm_send_to_remote_root */ PTHREAD_MUTEX_INITIALIZER, /* protects msg_ack_cv */ 0, /* send/recv threads are not dying */ @@ -756,7 +756,7 @@ etm_sleep(unsigned sleep_sec) static int etm_conn_open(fmd_hdl_t *hdl, char *err_substr, - etm_xport_addr_t addr, etm_xport_conn_t *connp) + etm_xport_addr_t addr, etm_xport_conn_t *connp) { etm_xport_conn_t conn; /* connection to return */ int nev; /* -errno value */ @@ -810,7 +810,7 @@ etm_conn_close(fmd_hdl_t *hdl, char *err_substr, etm_xport_conn_t conn) static ssize_t etm_io_op(fmd_hdl_t *hdl, char *err_substr, etm_xport_conn_t conn, - void *buf, size_t byte_cnt, int io_op) + void *buf, size_t byte_cnt, int io_op) { ssize_t rv; /* ret val / byte count */ ssize_t n; /* gen use */ @@ -1013,7 +1013,7 @@ etm_hdr_read(fmd_hdl_t *hdl, etm_xport_conn_t conn, size_t *szp) { uint8_t *hdrp; /* ptr to header to return */ size_t hdr_sz; /* sizeof *hdrp */ - etm_proto_v1_pp_t pp; /* protocol preamble */ + etm_proto_v1_pp_t pp; /* protocol preamble */ etm_proto_v1_ev_hdr_t *ev_hdrp; /* for FMA_EVENT msg */ etm_proto_v1_ctl_hdr_t *ctl_hdrp; /* for CONTROL msg */ etm_proto_v1_resp_hdr_t *resp_hdrp; /* for RESPONSE msg */ @@ -1237,7 +1237,7 @@ etm_hdr_read(fmd_hdl_t *hdl, etm_xport_conn_t conn, size_t *szp) static void* etm_hdr_write(fmd_hdl_t *hdl, etm_xport_conn_t conn, nvlist_t *evp, - int encoding, size_t *szp) + int encoding, size_t *szp) { etm_proto_v1_ev_hdr_t *hdrp; /* for FMA_EVENT msg */ size_t hdr_sz; /* sizeof *hdrp */ @@ -1348,7 +1348,7 @@ etm_post_to_fmd(fmd_hdl_t *hdl, fmd_xprt_t *fmd_xprt, nvlist_t *evp) static int etm_post_to_syslog(fmd_hdl_t *hdl, uint32_t priority, uint32_t body_sz, - uint8_t *body_buf) + uint8_t *body_buf) { char *sysmessage; /* Formatted message */ size_t formatlen; /* maximum length of sysmessage */ @@ -1633,16 +1633,16 @@ etm_iosvc_cleanup(fmd_hdl_t *fmd_hdl, etm_iosvc_t *iosvc, boolean_t clean_msg_q, iosvc->fmd_xprt = NULL; } /* if fmd-xprt has been opened */ - if (iosvc->send_tid != NULL) { + if (iosvc->send_tid != 0) { fmd_thr_signal(fmd_hdl, iosvc->send_tid); fmd_thr_destroy(fmd_hdl, iosvc->send_tid); - iosvc->send_tid = NULL; + iosvc->send_tid = 0; } /* if io svc send thread was created ok */ - if (iosvc->recv_tid != NULL) { + if (iosvc->recv_tid != 0) { fmd_thr_signal(fmd_hdl, iosvc->recv_tid); fmd_thr_destroy(fmd_hdl, iosvc->recv_tid); - iosvc->recv_tid = NULL; + iosvc->recv_tid = 0; } /* if root domain recv thread was created */ @@ -1763,7 +1763,8 @@ etm_iosvc_lookup(fmd_hdl_t *fmd_hdl, char *ldom_name, ds_hdl_t ds_hdl, * remove the ckpt for the iosvc element */ static void -etm_ckpt_remove(fmd_hdl_t *hdl, etm_iosvc_q_ele_t *ele) { +etm_ckpt_remove(fmd_hdl_t *hdl, etm_iosvc_q_ele_t *ele) +{ int err; /* temp error */ nvlist_t *evp = NULL; /* event pointer */ etm_proto_v1_ev_hdr_t *hdrp; /* hdr for FMA_EVENT */ @@ -1871,15 +1872,15 @@ etm_send_ds_msg(fmd_hdl_t *fmd_hdl, boolean_t ckpt_remove, etm_iosvc_t *iosvc, */ int etm_pack_ds_msg(fmd_hdl_t *fmd_hdl, etm_iosvc_t *iosvc, - etm_proto_v1_ev_hdr_t *ev_hdrp, size_t hdr_sz, nvlist_t *evp, - etm_pack_msg_type_t msg_type, uint_t ckpt_opt) + etm_proto_v1_ev_hdr_t *ev_hdrp, size_t hdr_sz, nvlist_t *evp, + etm_pack_msg_type_t msg_type, uint_t ckpt_opt) { etm_proto_v1_ev_hdr_t *hdrp; /* for FMA_EVENT msg */ uint32_t *lenp; /* ptr to FMA event length */ size_t evsz; /* packed FMA event size */ - char *buf; + char *buf; uint32_t rc; /* for return code */ - char *msg; /* body of msg to be Qed */ + char *msg; /* body of msg to be Qed */ etm_iosvc_q_ele_t msg_ele; /* io svc msg Q ele */ etm_proto_v1_ev_hdr_t *evhdrp; @@ -2851,7 +2852,7 @@ etm_async_q_deq(etm_async_event_ele_t *async_e) */ void etm_iosvc_setup(fmd_hdl_t *fmd_hdl, etm_iosvc_t *iosvc, - etm_async_event_ele_t *async_e) + etm_async_event_ele_t *async_e) { iosvc->ds_hdl = async_e->ds_hdl; iosvc->cur_send_xid = 0; @@ -2870,11 +2871,11 @@ etm_iosvc_setup(fmd_hdl_t *fmd_hdl, etm_iosvc_t *iosvc, } iosvc->thr_is_dying = 0; - if (iosvc->recv_tid == NULL) { + if (iosvc->recv_tid == 0) { iosvc->recv_tid = fmd_thr_create(fmd_hdl, etm_recv_from_remote_root, iosvc); } - if (iosvc->send_tid == NULL) { + if (iosvc->send_tid == 0) { iosvc->send_tid = fmd_thr_create(fmd_hdl, etm_send_to_remote_root, iosvc); } @@ -2888,7 +2889,7 @@ etm_iosvc_setup(fmd_hdl_t *fmd_hdl, etm_iosvc_t *iosvc, /* ARGSUSED */ static void etm_iosvc_reg_handler(ds_hdl_t ds_hdl, ds_cb_arg_t arg, ds_ver_t *ver, - ds_domain_hdl_t dhdl) + ds_domain_hdl_t dhdl) { etm_async_event_ele_t async_ele; @@ -3397,15 +3398,15 @@ etm_recv_from_remote_root(void *arg) int32_t rc; /* return value */ size_t maxlen = MAXLEN; /* max msg len */ - char msgbuf[MAXLEN]; /* recv msg buf */ + char msgbuf[MAXLEN]; /* recv msg buf */ size_t msg_size; /* recv msg size */ size_t hdr_sz; /* sizeof *hdrp */ size_t evsz; /* sizeof *evp */ size_t fma_event_size; /* sizeof FMA event */ - nvlist_t *evp; /* ptr to the nvlist */ + nvlist_t *evp; /* ptr to the nvlist */ char *buf; /* ptr to the nvlist */ static uint32_t mem_alloc = 0; /* indicate if alloc mem */ - char *msg; /* ptr to alloc mem */ + char *msg; /* ptr to alloc mem */ fmd_hdl_t *fmd_hdl = init_hdl; @@ -4096,7 +4097,7 @@ etm_send(fmd_hdl_t *fmd_hdl, fmd_xprt_t *xp, fmd_event_t *ep, nvlist_t *nvl) etm_pack_msg_type_t msg_type; /* tell etm_pack_ds_msg() what to do */ etm_iosvc_t *iosvc; /* ptr to cur iosvc struct */ - char *class; /* nvlist class name */ + char *class; /* nvlist class name */ pack_it = 1; msg_type = FMD_XPRT_OTHER_MSG; @@ -4197,22 +4198,22 @@ _fmd_fini(fmd_hdl_t *hdl) etm_is_dying = 1; - if (etm_svr_tid != NULL) { + if (etm_svr_tid != 0) { fmd_thr_signal(hdl, etm_svr_tid); fmd_thr_destroy(hdl, etm_svr_tid); - etm_svr_tid = NULL; + etm_svr_tid = 0; } /* if server thread was successfully created */ - if (etm_resp_tid != NULL) { + if (etm_resp_tid != 0) { fmd_thr_signal(hdl, etm_resp_tid); fmd_thr_destroy(hdl, etm_resp_tid); - etm_resp_tid = NULL; + etm_resp_tid = 0; } /* if responder thread was successfully created */ - if (etm_async_e_tid != NULL) { + if (etm_async_e_tid != 0) { fmd_thr_signal(hdl, etm_async_e_tid); fmd_thr_destroy(hdl, etm_async_e_tid); - etm_async_e_tid = NULL; + etm_async_e_tid = 0; } /* if async event handler thread was successfully created */ @@ -4273,16 +4274,16 @@ _fmd_fini(fmd_hdl_t *hdl) * On root domain side, there is only one iosvc struct in use. */ iosvc = &io_svc; - if (iosvc->send_tid != NULL) { + if (iosvc->send_tid != 0) { fmd_thr_signal(hdl, iosvc->send_tid); fmd_thr_destroy(hdl, iosvc->send_tid); - iosvc->send_tid = NULL; + iosvc->send_tid = 0; } /* if io svc send thread was successfully created */ - if (iosvc->recv_tid != NULL) { + if (iosvc->recv_tid != 0) { fmd_thr_signal(hdl, iosvc->recv_tid); fmd_thr_destroy(hdl, iosvc->recv_tid); - iosvc->recv_tid = NULL; + iosvc->recv_tid = 0; } /* if io svc receive thread was successfully created */ (void) pthread_mutex_lock(&iosvc->msg_q_lock); diff --git a/usr/src/cmd/luxadm/fcalupdate.c b/usr/src/cmd/luxadm/fcalupdate.c index c9a8e158fa..41f800f3bd 100644 --- a/usr/src/cmd/luxadm/fcalupdate.c +++ b/usr/src/cmd/luxadm/fcalupdate.c @@ -66,7 +66,7 @@ #include <l_common.h> #include "luxadm.h" -/* Defines */ +/* Defines */ #define FEPROM_SIZE 256*1024 #define FEPROM_MAX_PROGRAM 25 #define FEPROM_MAX_ERASE 1000 @@ -632,7 +632,7 @@ getbootdev(unsigned int verbose) char *slot = ",0:slot"; ls = (char *)malloc(PATH_MAX); - (void) memset((char *)ls, NULL, PATH_MAX); + (void) memset((char *)ls, 0, PATH_MAX); (void) strcpy(ls, "ls -l "); (void) strcat(ls, bootdev); if ((ptr = popen(ls, "r")) != NULL) { @@ -827,9 +827,9 @@ loop1: /* * getsocpath(): - * Searches the /devices directory recursively returning all soc_name + * Searches the /devices directory recursively returning all soc_name * entries in sbussoc_list (global). This excludes port entries and - * onboard socal (which leaves only directory entries with + * onboard socal (which leaves only directory entries with * soc_name included). devcnt is updated to reflect number of soc_name * devices found. */ diff --git a/usr/src/cmd/luxadm/g_adm.c b/usr/src/cmd/luxadm/g_adm.c index b6377b00da..ed6a389c75 100644 --- a/usr/src/cmd/luxadm/g_adm.c +++ b/usr/src/cmd/luxadm/g_adm.c @@ -94,7 +94,7 @@ static void display_lun_info(L_disk_state, Path_struct *, struct mode_page *, int, WWN_list *, char *); static void display_fc_disk(struct path_struct *, char *, gfc_map_t *, L_inquiry, int); -static void adm_display_err(char *, int); +static void adm_display_err(char *, int); static void temperature_messages(struct l_state_struct *, int); static void ctlr_messages(struct l_state_struct *, int, int); static void fan_messages(struct l_state_struct *, int, int); @@ -285,7 +285,7 @@ char last_logical_path[MAXPATHLEN]; retval++; continue; } - *ptr = NULL; + *ptr = '\0'; slot = path_struct->slot; f_r = path_struct->f_flag; path_phys = NULL; @@ -482,7 +482,7 @@ char err_path[MAXNAMELEN]; if (((ptr = strstr(err_path, ", ")) != NULL) && ((*(ptr + 1) == 'f') || (*(ptr + 1) == 'r') || (*(ptr +1) == 's'))) { - *ptr = NULL; + *ptr = '\0'; slot = path_struct->slot; f_r = path_struct->f_flag; path_phys = NULL; @@ -573,7 +573,7 @@ char ses_path[MAXPATHLEN], inq_path[MAXNAMELEN]; retval++; continue; } - *ptr = NULL; + *ptr = '\0'; slot = path_struct->slot; f_r = path_struct->f_flag; if ((err = l_convert_name(inq_path, &path_phys, @@ -2317,15 +2317,15 @@ int num_status_entries; (void) fprintf(stdout, MSGSTR(32, "Information from %s"), fc_stats->drvr_name); (void) fprintf(stdout, "\n"); - if ((*fc_stats->node_wwn != NULL) && - (*fc_stats->port_wwn[port] != NULL)) { + if ((*fc_stats->node_wwn != '\0') && + (*fc_stats->port_wwn[port] != '\0')) { (void) fprintf(stdout, MSGSTR(104, " Host Adapter WWN's: Node:%s" " Port:%s\n"), fc_stats->node_wwn, fc_stats->port_wwn[port]); } - if (*fc_stats->fw_revision != NULL) { + if (*fc_stats->fw_revision != '\0') { (void) fprintf(stdout, MSGSTR(105, " Host Adapter Firmware Revision: %s\n"), fc_stats->fw_revision); @@ -2613,15 +2613,15 @@ int p_on = 0, p_st = 0; "Information from %s"), ifp_stats.drvr_name); (void) fprintf(stdout, "\n"); - if ((*ifp_stats.node_wwn != NULL) && - (*ifp_stats.port_wwn != NULL)) { + if ((*ifp_stats.node_wwn != '\0') && + (*ifp_stats.port_wwn != '\0')) { (void) fprintf(stdout, MSGSTR(104, " Host Adapter WWN's: Node:%s" " Port:%s\n"), ifp_stats.node_wwn, ifp_stats.port_wwn); } - if (*ifp_stats.fw_revision != NULL) { + if (*ifp_stats.fw_revision != 0) { (void) fprintf(stdout, MSGSTR(105, " Host Adapter Firmware Revision: %s\n"), ifp_stats.fw_revision); @@ -2925,7 +2925,7 @@ char temp2path[MAXPATHLEN]; mp_pathlist_t pathlist; int p_pw = 0, p_on = 0, p_st = 0; gfc_dev_t map_root, map_dev; -int *port_addr, *hard_addr, pos = 0, count; +int *port_addr, *hard_addr, pos = 0, count; uchar_t *hba_port_wwn, *port_wwn, *node_wwn, *dtype_prop; uint_t map_topo; @@ -4062,7 +4062,7 @@ struct mode_page *pg_hdr; if (no_path_flag) { (void) fprintf(stdout, " "); - if (port_a_flag != NULL) { + if (port_a_flag != 0) { (void) fprintf(stdout, MSGSTR(142, "Status(Port B):")); } else { (void) fprintf(stdout, MSGSTR(141, "Status(Port A):")); @@ -4870,7 +4870,7 @@ Interconnect_st interconnect; (void) fprintf(stdout, MSGSTR(30, "Not Installed")); } else if (interconnect.code == S_CRITICAL) { - if (interconnect.eprom_fail != NULL) { + if (interconnect.eprom_fail != 0) { (void) fprintf(stdout, MSGSTR(2140, "Critical Failure: EEPROM failure")); } else { @@ -4879,7 +4879,7 @@ Interconnect_st interconnect; } revision_msg(l_state, elem_index + j); } else if (interconnect.code == S_NONCRITICAL) { - if (interconnect.eprom_fail != NULL) { + if (interconnect.eprom_fail != 0) { (void) fprintf(stdout, MSGSTR(2142, "Non-Critical Failure: EEPROM failure")); } else { @@ -5566,7 +5566,7 @@ cleanup_and_go: * * Sample output for ifp: * - * /devices/pci@1f,4000/SUNW,ifp@2:devctl CONNECTED + * /devices/pci@1f,4000/SUNW,ifp@2:devctl CONNECTED * /devices/pci@1f,2000/SUNW,ifp@1:devctl NOT CONNECTED * * Sample output for socal: diff --git a/usr/src/cmd/luxadm/hotplug.c b/usr/src/cmd/luxadm/hotplug.c index 2efec8ba3c..f3e962ae8f 100644 --- a/usr/src/cmd/luxadm/hotplug.c +++ b/usr/src/cmd/luxadm/hotplug.c @@ -104,7 +104,7 @@ static int h_pre_hotplug_sena(Hotplug_Devlist *, static int h_post_hotplug_sena(Hotplug_Devlist *, WWN_list *, int, int, int, int); static int h_remove_ses_nodes(struct dlist *); -static int h_print_list_warn(Hotplug_Devlist *, int, int); +static int h_print_list_warn(Hotplug_Devlist *, int, int); static int h_display_logical_nodes(struct dlist *); static void h_print_logical_nodes(struct dlist *); static int h_remove_nodes(struct dlist *); @@ -394,7 +394,7 @@ char choice[2]; for (list = bsyRsrv_disk_list; list != NULL; list = list->next, i++) { if ((list->dev_type == DTYPE_DIRECT) && (list->dev_location == SENA)) { - if (list->f_flag != NULL) { + if (list->f_flag != 0) { if (enc_type == DAK_ENC_TYPE) { (void) fprintf(stdout, MSGSTR(5663, " %d: Box Name: \"%s\" slot %d\n"), @@ -549,7 +549,7 @@ int p_pw = 0, p_on = 0, p_st = 0; err = 0; continue; } - *ptr = NULL; + *ptr = '\0'; slot = path_struct->slot; f_r = path_struct->f_flag; if ((err = l_convert_name(inq_path, &path_phys, @@ -687,7 +687,7 @@ int p_pw = 0, p_on = 0, p_st = 0; * set dev_path to NULL, * if disk has null wwn. */ - *dev_path = NULL; + *dev_path = '\0'; dev_location = SENA; goto getinfo; } @@ -2193,12 +2193,12 @@ Box_list *bl1, *box_list = NULL; */ static int h_post_remove_dev(Hotplug_Devlist *hotplug_disk, - int todo, int verbose_flag) + int todo, int verbose_flag) { -char device_name[MAXNAMELEN], *dev_path = NULL; -int tid, err; -gfc_map_t map; -int nArg; + char device_name[MAXNAMELEN], *dev_path = NULL; + int tid, err; + gfc_map_t map; + int nArg; tid = hotplug_disk->tid; @@ -2669,7 +2669,7 @@ char *tape_entries[] = { "", "b", "bn", "c", "cb", "cbn", "cn", (void) strcpy(buf, ptr); if ((ptr = strrchr(buf, 's')) == NULL) continue; - *(++ptr) = NULL; + *(++ptr) = '\0'; found_dev++; if (found_dev == 1) (void) fprintf(stdout, @@ -2695,7 +2695,7 @@ char *tape_entries[] = { "", "b", "bn", "c", "cb", "cbn", "cn", buf_ptr = ptr; while (*ptr >= '0' && *ptr <= '9') ptr++; - *ptr = NULL; + *ptr = '\0'; for (i = 0, ptr = tape_entries[0]; ptr != NULL; i++, ptr = tape_entries[i]) { @@ -2795,7 +2795,7 @@ Hotplug_Devlist *disk_list = disk_list_head; for (i = 1; disk_list; i++, disk_list = disk_list->next) { if ((disk_list->dev_type == DTYPE_DIRECT) && (disk_list->dev_location == SENA)) { - if (disk_list->f_flag != NULL) { + if (disk_list->f_flag != 0) { if (enc_type == DAK_ENC_TYPE) { (void) fprintf(stdout, MSGSTR(5665, " %d: Box Name: \"%s\" slot %d\n"), diff --git a/usr/src/cmd/luxadm/qlgcupdate.c b/usr/src/cmd/luxadm/qlgcupdate.c index 404f4b7c06..07b6941b91 100644 --- a/usr/src/cmd/luxadm/qlgcupdate.c +++ b/usr/src/cmd/luxadm/qlgcupdate.c @@ -159,8 +159,8 @@ q_qlgc_update(unsigned int verbose, char *file) * is "sbus@12". They are initialized to a random value and are * set such that they are not equal initially. */ - static char port1[MAXNAMELEN] = {NULL}; - static char port2[MAXNAMELEN] = {NULL}; + static char port1[MAXNAMELEN] = { 0 }; + static char port2[MAXNAMELEN] = { 0 }; if (file) { fflag++; @@ -401,8 +401,8 @@ q_findversion(int verbose, int index, uchar_t *version, uint16_t *chip_id) { int fd, ntries; struct ifp_fm_version *version_buffer = NULL; - char prom_ver[100] = {NULL}; - char mcode_ver[100] = {NULL}; + char prom_ver[100] = { 0 }; + char mcode_ver[100] = { 0 }; fcio_t fcio; if (strstr(&pcibus_list[index][0], fc_trans)) { @@ -516,7 +516,7 @@ q_findfileversion(char *dl_fcode, uchar_t *version_file, uint16_t *file_id, { int mark; int qlc_offset = 0; - char temp[4] = {NULL}; + char temp[4] = { 0 }; /* @@ -1328,7 +1328,7 @@ emulex_fcodeversion(di_node_t node, uchar_t *ver) { promprop)) != NULL) && (strcmp(promname, "fcode-version") == 0)) { size = di_prom_prop_data(promprop, &ver_data); - (void) memset(ver, NULL, size); + (void) memset(ver, 0, size); (void) memcpy(ver, ver_data, size); found = 1; } diff --git a/usr/src/cmd/modload/Makefile b/usr/src/cmd/modload/Makefile index c186767c6a..7e258fa01a 100644 --- a/usr/src/cmd/modload/Makefile +++ b/usr/src/cmd/modload/Makefile @@ -21,9 +21,7 @@ # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # -# cmd/modload/Makefile -# -# makefile for loadable module utilities +# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. DRVPROG = add_drv rem_drv update_drv MODPROG = modinfo modunload modload @@ -36,19 +34,18 @@ XPRIV = $(ETCSEC)/extra_privs $(XPRIV) := FILEMODE = 644 -SUBDIRS += $(MACH64) +SUBDIRS += $(MACH64) all := TARGET = all install := TARGET = install clean := TARGET = clean clobber := TARGET = clobber -lint := TARGET = lint .KEEP_STATE: all: $(SUBDIRS) -clean clobber lint: $(SUBDIRS) +clean clobber: $(SUBDIRS) install: $(SUBDIRS) $(XPRIV) diff --git a/usr/src/cmd/modload/Makefile.com b/usr/src/cmd/modload/Makefile.com index cf82649c7d..19d24ebb74 100644 --- a/usr/src/cmd/modload/Makefile.com +++ b/usr/src/cmd/modload/Makefile.com @@ -23,6 +23,7 @@ # Use is subject to license terms. # # Copyright (c) 2018, Joyent, Inc. +# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. # # makefile for loadable module utilities @@ -52,18 +53,6 @@ COMMONSRC = $(DRVCOMMONSRC) $(MODCOMMONSRC) CLOBBERFILES = $(PROG) -# lint is complicated here by the fact that we -# build multiple commands and with differing -# common source, drvsubr vs modsubr/plcysubr -# -LINT_PROG= $(PROG:%=lint_%.c) -LINTFLAGS += -erroff=E_NAME_DEF_NOT_USED2 - -CERRWARN += -_gcc=-Wno-parentheses - -# not linted -SMATCH=off - # install specifics $(ROOTDRVPROG) := FILEMODE = 0555 @@ -72,10 +61,6 @@ add_drv := LDLIBS += -ldevinfo -lelf rem_drv := LDLIBS += -ldevinfo update_drv := LDLIBS += -ldevinfo -lint_add_drv.c := LDLIBS += -ldevinfo -lelf -lint_rem_drv.c := LDLIBS += -ldevinfo -lint_update_drv.c := LDLIBS += -ldevinfo - .KEEP_STATE: %.o: ../%.c @@ -110,9 +95,4 @@ modinfo: modinfo.o $(MODCOMMONOBJ) clean: $(RM) $(OBJECTS) -lint_%.c: - $(LINT.c) $(@:lint_%.c=../%.c) $(COMMONSRC) $(LDLIBS) - -lint: $(LINT_PROG) - include ../../Makefile.targ diff --git a/usr/src/cmd/modload/addrem.h b/usr/src/cmd/modload/addrem.h index 98448a0625..dc2a1732d4 100644 --- a/usr/src/cmd/modload/addrem.h +++ b/usr/src/cmd/modload/addrem.h @@ -20,6 +20,7 @@ */ /* * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. */ #ifndef _CMD_MODLOAD_ADDREM_H @@ -44,7 +45,7 @@ extern "C" { #define MAX_CMD_LINE 256 #define MAX_N2M_ALIAS_LINE FILENAME_MAX + FILENAME_MAX + 1 -#define MAXLEN_NAM_TO_MAJ_ENT FILENAME_MAX + MAX_STR_MAJOR + 1 +#define MAXLEN_NAM_TO_MAJ_ENT FILENAME_MAX + MAX_STR_MAJOR + 1 #define OPT_LEN 128 #define CADDR_HEX_STR 16 #define UINT_STR 10 @@ -118,7 +119,7 @@ extern char *get_perm_entry(char *, char *); extern int check_perms_aliases(int, int); extern int check_name_to_major(int); extern void enter_lock(void); -extern void err_exit(void); +extern void err_exit(void) __NORETURN; extern void exit_unlock(void); extern char *get_entry(char *, char *, char, int); extern int build_filenames(char *); diff --git a/usr/src/cmd/modload/amd64/Makefile b/usr/src/cmd/modload/amd64/Makefile index cd2153b08c..87cd1cb261 100644 --- a/usr/src/cmd/modload/amd64/Makefile +++ b/usr/src/cmd/modload/amd64/Makefile @@ -22,10 +22,9 @@ # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # +# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. include ../Makefile.com include ../../Makefile.cmd.64 -LINTFLAGS64 += -erroff=E_NAME_DEF_NOT_USED2 - install: all $(ROOTUSRSBINPROG) diff --git a/usr/src/cmd/modload/drvsubr.c b/usr/src/cmd/modload/drvsubr.c index 83282f471f..75662833e9 100644 --- a/usr/src/cmd/modload/drvsubr.c +++ b/usr/src/cmd/modload/drvsubr.c @@ -26,6 +26,9 @@ * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ +/* + * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. + */ #include <stdio.h> #include <stdlib.h> @@ -116,7 +119,7 @@ log_minorperm_error(minorperm_err_t err, int key) * open file * for each entry in list * where list entries are separated by <list_separator> - * append entry : driver_name <entry_separator> entry + * append entry : driver_name <entry_separator> entry * close file * return error/noerr */ @@ -207,7 +210,7 @@ append_to_file( * open file * for each entry in list * where list entries are separated by <list_separator> - * append entry : driver_name <entry_separator> entry + * append entry : driver_name <entry_separator> entry * close file * return error/noerr */ @@ -347,7 +350,7 @@ delete_entry( int rv, i; int status = NOERR; int drvr_found = 0; - boolean_t nomatch = B_TRUE; + boolean_t nomatch = B_TRUE; char newfile[MAXPATHLEN]; char *cp; char line[MAX_DBFILE_ENTRY]; @@ -1213,9 +1216,6 @@ exec_devfsadm( int n = 0; char *cmdline[MAX_CMD_LINE]; char maj_num[128]; - char *previous; - char *current; - int len; int rv; /* build command line */ @@ -1242,24 +1242,35 @@ exec_devfsadm( cmdline[n++] = "-x"; if (aliases != NULL) { + char *buf, *p; + size_t len; + int n_start = n; + len = strlen(aliases); - previous = aliases; - do { - cmdline[n++] = "-a"; - cmdline[n] = calloc(len + 1, 1); - if (cmdline[n] == NULL) { - (void) fprintf(stderr, - gettext(ERR_NO_MEM)); - return (ERROR); - } - current = get_entry(previous, - cmdline[n++], ' ', 0); - previous = current; - } while (*current != '\0'); + p = buf = calloc(len + 1, 1); + if (buf == NULL) { + (void) fprintf(stderr, gettext(ERR_NO_MEM)); + return (ERROR); + } + while (*aliases != '\0') { + while (n < MAX_CMD_LINE - 3 && *aliases != '\0') { + cmdline[n++] = "-a"; + aliases = get_entry(aliases, p, ' ', 0); + cmdline[n++] = p; + p += strlen(p) + 1; + } + cmdline[n] = NULL; + rv = exec_command(DRVCONFIG_PATH, cmdline); + if (rv != NOERR) + break; + n = n_start; + } + free(buf); + return (rv == NOERR ? NOERR : ERROR); } - cmdline[n] = (char *)0; + cmdline[n] = NULL; rv = exec_command(DRVCONFIG_PATH, cmdline); if (rv == NOERR) @@ -1387,7 +1398,7 @@ create_reconfig(char *basedir) * open file * for each entry in list * where list entries are separated by <list_separator> - * modify entry : driver_name <entry_separator> entry + * modify entry : driver_name <entry_separator> entry * close file * * return error/noerr @@ -1538,7 +1549,7 @@ update_minor_entry(char *driver_name, char *perm_list) } if (!match) { - (void) bzero(line, sizeof (&line[0])); + (void) bzero(line, sizeof (line)); (void) snprintf(line, sizeof (line), "%s:%s %s %s %s\n", driver_name, minor, perm, own, grp); @@ -1929,7 +1940,7 @@ unique_drv_alias(char *drv_alias) continue; /* sanity-check */ if (sscanf(line, - "%" VAL2STR(FILENAME_MAX) "s" /* drv */ + "%" VAL2STR(FILENAME_MAX) "s" /* drv */ "%" VAL2STR(FILENAME_MAX) "s", /* alias */ drv, alias) != 2) (void) fprintf(stderr, gettext(ERR_BAD_LINE), @@ -1965,8 +1976,7 @@ unique_drv_alias(char *drv_alias) * from the remainder of the line by white space. */ int -unique_driver_name(char *driver_name, char *file_name, - int *is_unique) +unique_driver_name(char *driver_name, char *file_name, int *is_unique) { int ret, err; @@ -2174,7 +2184,7 @@ update_name_to_major(char *driver_name, major_t *major_num, int server) /* * if driver_name already in rem_name_to_major - * delete entry from rem_nam_to_major + * delete entry from rem_nam_to_major * put entry into name_to_major */ diff --git a/usr/src/cmd/modload/plcysubr.c b/usr/src/cmd/modload/plcysubr.c index 1fa59159ac..c17d6e9245 100644 --- a/usr/src/cmd/modload/plcysubr.c +++ b/usr/src/cmd/modload/plcysubr.c @@ -27,7 +27,9 @@ * drvsubr.c because of static linking requirements. */ -#pragma ident "%Z%%M% %I% %E% SMI" +/* + * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. + */ #include <stdio.h> #include <stdlib.h> @@ -87,18 +89,16 @@ devplcy_init(void) devplcysys_sz = DEVPLCYSYS_SZ(privimplinfo); toktab[RDPOL].off = - (char *)DEVPLCYSYS_RDP((devplcysys_t *)0, privimplinfo) - - (char *)0; + (char *)DEVPLCYSYS_RDP((devplcysys_t *)0, privimplinfo) - (char *)0; toktab[WRPOL].off = - (char *)DEVPLCYSYS_WRP((devplcysys_t *)0, privimplinfo) - - (char *)0; + (char *)DEVPLCYSYS_WRP((devplcysys_t *)0, privimplinfo) - (char *)0; } /* * Read a configuration file line and return a static buffer pointing to it. * It returns a static struct fileentry which has several fields: * - rawbuf, which includes the lines including empty lines and comments - * leading up to the file and the entry as found in the file + * leading up to the file and the entry as found in the file * - orgentry, pointer in rawbuf to the start of the entry proper. * - entry, a pre-parsed entry, escaped newlines removed. * - startline, the line number of the first line in the file @@ -481,13 +481,14 @@ parse_plcy_token(char *token, devplcysys_t *dp) case PSET: pset = priv_str_to_set(val, ",", &perr); if (pset == NULL) { - if (perr == NULL) - (void) fprintf(stderr, - gettext(ERR_NO_MEM)); - else - (void) fprintf(stderr, - gettext(ERR_BAD_PRIVS), - perr - val, val, perr); + if (perr == NULL) { + (void) fprintf(stderr, + gettext(ERR_NO_MEM)); + } else { + (void) fprintf(stderr, + gettext(ERR_BAD_PRIVS), + perr - val, val, perr); + } return (1); } priv_copyset(pset, item); @@ -495,8 +496,8 @@ parse_plcy_token(char *token, devplcysys_t *dp) break; default: (void) fprintf(stderr, - "Internal Error: bad token type: %d\n", - toktab[i].type); + "Internal Error: bad token type: %d\n", + toktab[i].type); return (1); } /* Standard cleanup & return for good tokens */ @@ -547,6 +548,7 @@ check_plcy_entry(char *entry, const char *driver, boolean_t todel) if (res == NULL || ds == NULL) { (void) fprintf(stderr, gettext(ERR_NO_MEM)); + free(res); return (NULL); } @@ -612,7 +614,7 @@ check_plcy_entry(char *entry, const char *driver, boolean_t todel) tokseen = B_TRUE; } } - if (todel && tokseen || *res == '\0' || !todel && !tokseen) { + if ((todel && tokseen) || *res == '\0' || (!todel && !tokseen)) { (void) fprintf(stderr, gettext(ERR_INVALID_PLCY)); free(res); return (NULL); @@ -690,7 +692,7 @@ check_priv_entry(const char *privlist, boolean_t add) if (add && modctl(MODALLOCPRIV, pr) != 0) { (void) fprintf(stderr, gettext(ERR_BAD_PRIV), pr, - strerror(errno)); + strerror(errno)); return (ERROR); } } diff --git a/usr/src/cmd/modload/sparcv9/Makefile b/usr/src/cmd/modload/sparcv9/Makefile index cd2153b08c..87cd1cb261 100644 --- a/usr/src/cmd/modload/sparcv9/Makefile +++ b/usr/src/cmd/modload/sparcv9/Makefile @@ -22,10 +22,9 @@ # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # +# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. include ../Makefile.com include ../../Makefile.cmd.64 -LINTFLAGS64 += -erroff=E_NAME_DEF_NOT_USED2 - install: all $(ROOTUSRSBINPROG) diff --git a/usr/src/cmd/svc/svccfg/svccfg_xml.c b/usr/src/cmd/svc/svccfg/svccfg_xml.c index 13c7a90d12..c0810de2ab 100644 --- a/usr/src/cmd/svc/svccfg/svccfg_xml.c +++ b/usr/src/cmd/svc/svccfg/svccfg_xml.c @@ -23,7 +23,7 @@ */ /* * Copyright 2011 Nexenta Systems, Inc. All rights reserved. - * Copyright 2019 Joyent, Inc. + * Copyright 2020 Joyent, Inc. */ @@ -3404,6 +3404,28 @@ out: } /* + * Validate the svc:/-prefixed FMRI generated from the service name. + */ +static void +validate_service_name(const entity_t *s) +{ + char *fmri; + int ftype; + const char *finst; + + if ((fmri = uu_strdup(s->sc_fmri)) == NULL) + uu_die(gettext("couldn't allocate memory")); + + if (scf_parse_fmri(fmri, &ftype, NULL, NULL, &finst, NULL, NULL) != 0 || + finst != NULL || ftype != SCF_FMRI_TYPE_SVC) { + uu_die(gettext("invalid value \"%s\": should be a bare " + "service name\n"), s->sc_name); + } + + uu_free(fmri); +} + +/* * Translate a service element into an internal instance/property tree, added * to bundle. * @@ -3427,6 +3449,8 @@ lxml_get_service(bundle_t *bundle, xmlNodePtr svc, svccfg_op_t op) s = internal_service_new((char *)xmlGetProp(svc, (xmlChar *)name_attr)); + validate_service_name(s); + version = xmlGetProp(svc, (xmlChar *)version_attr); s->sc_u.sc_service.sc_service_version = atol((const char *)version); xmlFree(version); diff --git a/usr/src/cmd/zoneadmd/Makefile.com b/usr/src/cmd/zoneadmd/Makefile.com index 9725021b17..aaf21c7f5b 100644 --- a/usr/src/cmd/zoneadmd/Makefile.com +++ b/usr/src/cmd/zoneadmd/Makefile.com @@ -35,7 +35,7 @@ OBJS= zoneadmd.o zcons.o zfd.o vplat.o log.o CFLAGS += $(CCVERBOSE) LDLIBS += -lsocket -lzonecfg -lnsl -ldevinfo -ldevice -lnvpair \ -lgen -lbsm -lcontract -lzfs -luuid -lbrand -ldladm -ltsnet -ltsol \ - -linetutil -lscf -lppt + -linetutil -lscf -lppt -lcustr CSTD= $(CSTD_GNU99) diff --git a/usr/src/cmd/zoneadmd/log.c b/usr/src/cmd/zoneadmd/log.c index 121c5236a7..47f25ced72 100644 --- a/usr/src/cmd/zoneadmd/log.c +++ b/usr/src/cmd/zoneadmd/log.c @@ -10,7 +10,7 @@ */ /* - * Copyright 2019 Joyent, Inc. + * Copyright 2020 Joyent, Inc. */ /* @@ -94,11 +94,12 @@ * logstream_err() should be used to log via syslog. */ -#include <assert.h> #include <dirent.h> #include <errno.h> #include <fcntl.h> #include <glob.h> +#include <libcustr.h> +#include <netdb.h> #include <signal.h> #include <stdarg.h> #include <stdio.h> @@ -132,19 +133,37 @@ #define ZLOG_KEEP "zlog-keep-rotated" /* zonecfg attr */ #define ZLOG_KEEP_MAX 1000 /* number of log files */ +/* + * While we could get the numeric value of BUNYAN_LOG_INFO from bunyan.h, + * the log version is internal to the library, so we just define the values + * we need here. + */ +#define BUNYAN_VERSION 0 +#define BUNYAN_LOG_LEVEL 30 /* info */ + typedef struct logfile { char lf_path[MAXPATHLEN]; /* log file name (absolute path) */ char lf_name[MAXNAMELEN]; /* tail of log file name */ + char lf_buf[BUFSIZ]; /* Buffer for event messages */ + custr_t *lf_cus; /* custr_t wrapper for lf_buf */ int lf_fd; /* file descriptor */ size_t lf_size; /* Current size */ boolean_t lf_write_err; /* Avoid spamming console via logsys */ boolean_t lf_closing; /* Avoid rotation recursion */ } logfile_t; +/* Large enough to hold BUFSIZ bytes with some escaping */ +#define LS_BUFSZ (BUFSIZ * 2) + +/* Large enough to hold LS_BUF contents + bunyan mandatory properties */ +#define LS_OBUFSZ (LS_BUFSZ + MAXNAMELEN + 128) + typedef struct logstream { char ls_stream[MAXNAMELEN]; /* stdout, stderr, etc. */ - char ls_buf[BUFSIZ * 2]; /* Not-yet written data, json */ - int ls_buflen; + char ls_buf[LS_BUFSZ]; /* Not-yet written data, json */ + char ls_obuf[LS_OBUFSZ]; /* Buffer to form output json */ + custr_t *ls_cusbuf; /* custr_t wrapper to ls_buf */ + custr_t *ls_cusobuf; /* custr_t wrapper to ls_ofbuf */ logstream_flags_t ls_flags; logfile_t *ls_logfile; /* N streams per log file */ } logstream_t; @@ -162,17 +181,20 @@ boolean_t logging_poisoned = B_FALSE; static logstream_t streams[MAX_LOG_STREAMS]; static logfile_t logfiles[MAX_LOG_STREAMS]; +static char host[MAXHOSTNAMELEN]; +static char pidstr[10]; + static boolean_t logging_initialized = B_FALSE; static uint64_t logging_rot_size; /* See ZLOG_MAXSZ */ static uint64_t logging_rot_keep; /* See ZLOG_KEEP */ static int logging_pending_sig = 0; /* Signal recvd while logging */ -static mutex_t logging_lock; /* The global logging lock */ +static mutex_t logging_lock = ERRORCHECKMUTEX; /* The global logging lock */ static void logstream_flush_all(logfile_t *); static void logstream_sighandler(int); static void rotate_log(logfile_t *); -static size_t make_json(jsonpair_t *, int, char *, size_t); -static void logfile_write(logfile_t *, const char *, size_t); +static size_t make_json(jsonpair_t *, size_t, custr_t *); +static void logfile_write(logfile_t *, custr_t *); /* * If errors are encountered while logging_lock is held, we can't use zerror(). @@ -206,24 +228,19 @@ logstream_err(boolean_t use_strerror, const char *fmt, ...) static void logstream_lock(void) { - int ret; - - assert(logging_initialized && !logging_poisoned); + VERIFY(logging_initialized); + VERIFY(!logging_poisoned); - ret = mutex_lock(&logging_lock); - assert(ret == 0); + mutex_enter(&logging_lock); } static void logstream_unlock(void) { - int ret; - int err = errno; int sig = logging_pending_sig; logging_pending_sig = 0; - ret = mutex_unlock(&logging_lock); - assert(ret == 0); + mutex_exit(&logging_lock); /* * If a signal arrived while this thread was holding the lock, call the @@ -232,28 +249,25 @@ logstream_unlock(void) if (sig != 0) { logstream_sighandler(sig); } - - errno = err; } static void logfile_write_event(logfile_t *lfp, const char *stream, const char *event) { - char buf[BUFSIZ]; size_t len; jsonpair_t pairs[] = { - { "event", event }, - { "stream", stream } + { "stream", stream }, + { "msg", event } }; - len = make_json(pairs, ARRAY_SIZE(pairs), buf, sizeof (buf)); - if (len >= sizeof (buf)) { - logstream_err(B_FALSE, "%s: buffer too small. Need %llu bytes, " - "have %llu bytes", __func__, len + 1, sizeof (buf)); + len = make_json(pairs, ARRAY_SIZE(pairs), lfp->lf_cus); + if (len >= sizeof (lfp->lf_buf)) { + logstream_err(B_FALSE, "%s: buffer too small. Need %zu bytes, " + "have %zu bytes", __func__, len + 1, sizeof (lfp->lf_buf)); return; } - logfile_write(lfp, buf, len); + logfile_write(lfp, lfp->lf_cus); } static void @@ -261,7 +275,7 @@ close_log(logfile_t *lfp, const char *why, boolean_t ign_err) { int err; - assert(MUTEX_HELD(&logging_lock)); + VERIFY(MUTEX_HELD(&logging_lock)); /* * Something may have gone wrong during log rotation, leading to a @@ -279,7 +293,7 @@ close_log(logfile_t *lfp, const char *why, boolean_t ign_err) err = close(lfp->lf_fd); if (!ign_err) - assert(err == 0); + VERIFY0(err); lfp->lf_size = 0; lfp->lf_fd = -1; @@ -289,10 +303,9 @@ static void open_log(logfile_t *lfp, const char *why) { struct stat64 sb; - int err; - assert(MUTEX_HELD(&logging_lock)); - assert(lfp->lf_fd == -1); + VERIFY(MUTEX_HELD(&logging_lock)); + VERIFY3S(lfp->lf_fd, ==, -1); lfp->lf_fd = open(lfp->lf_path, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, 0600); @@ -303,8 +316,7 @@ open_log(logfile_t *lfp, const char *why) return; } - err = fstat64(lfp->lf_fd, &sb); - assert(err == 0); + VERIFY0(fstat64(lfp->lf_fd, &sb)); lfp->lf_size = sb.st_size; lfp->lf_write_err = B_FALSE; lfp->lf_closing = B_FALSE; @@ -411,6 +423,7 @@ logstream_atfork_child(void) { logging_poisoned = B_TRUE; logging_pending_sig = 0; + (void) snprintf(pidstr, sizeof (pidstr), "%d", getpid()); logstream_unlock(); } @@ -418,21 +431,40 @@ void logstream_init(zlog_t *zlogp) { zone_dochandle_t handle; - int err; int i; - assert(!logging_initialized); + VERIFY(!logging_initialized); - err = mutex_init(&logging_lock, USYNC_THREAD | LOCK_ERRORCHECK, 0); - assert(err == 0); + VERIFY0(gethostname(host, sizeof (host))); + (void) snprintf(pidstr, sizeof (pidstr), "%d", getpid()); for (i = 0; i < ARRAY_SIZE(logfiles); i++) { - logfiles[i].lf_fd = -1; + logfile_t *lfp = &logfiles[i]; + + lfp->lf_fd = -1; + if (custr_alloc_buf(&lfp->lf_cus, lfp->lf_buf, + sizeof (lfp->lf_buf)) != 0) { + (void) fprintf(stderr, "failed to allocate custr_t for " + "log file\n"); + abort(); + } + } + + for (i = 0; i < ARRAY_SIZE(streams); i++) { + logstream_t *lsp = &streams[i]; + + if (custr_alloc_buf(&lsp->ls_cusbuf, lsp->ls_buf, + sizeof (lsp->ls_buf)) != 0 || + custr_alloc_buf(&lsp->ls_cusobuf, lsp->ls_obuf, + sizeof (lsp->ls_obuf)) != 0) { + (void) fprintf(stderr, "failed to allocate custr_t for " + "log stream\n"); + abort(); + } } - err = pthread_atfork(logstream_atfork_prepare, - logstream_atfork_parent, logstream_atfork_child); - assert(err == 0); + VERIFY0(pthread_atfork(logstream_atfork_prepare, + logstream_atfork_parent, logstream_atfork_child)); logging_initialized = B_TRUE; @@ -481,7 +513,7 @@ rotate_log(logfile_t *lfp) glob_t glb = { 0 }; int err; - assert(MUTEX_HELD(&logging_lock)); + VERIFY(MUTEX_HELD(&logging_lock)); if (lfp->lf_closing) { return; @@ -550,13 +582,10 @@ rotate_log(logfile_t *lfp) * sbuf to json. * * sbuf, slen Source buffer and the number of bytes in it to process - * dbuf, dlen Destination buffer and its size. On return, the result - * is always null terminated. + * dest Destination custr_t containing escaped JSON. * scntp On return, *scntp stores number of scnt bytes consumed - * dcntp On return, *dcntp stores number of bytes stored in dcnt, - * excluding trailing nul. * flushp If non-NULL, line-buffered mode is enabled. Processing - * will stop at the first newline or when obuf is full and + * will stop at the first newline or when dest is full and * *flushp will be set to B_TRUE. * * This function makes no attempt to handle wide characters properly because @@ -566,10 +595,9 @@ rotate_log(logfile_t *lfp) * readers to interpret non-ASCII data. */ static void -escape_json(const char *sbuf, int slen, char *dbuf, int dlen, int *scntp, - int *dcntp, boolean_t *flushp) +escape_json(const char *sbuf, size_t slen, custr_t *dest, size_t *scntp, + boolean_t *flushp) { - int i; char c; const char *save_sbuf = sbuf; const char *sbuf_end = sbuf + slen - 1; @@ -577,12 +605,16 @@ escape_json(const char *sbuf, int slen, char *dbuf, int dlen, int *scntp, const char *append; int len; + if (slen == 0) { + *scntp = 0; + return; + } + if (flushp != NULL) { *flushp = B_FALSE; } - i = 0; - while (i < (dlen - 1) && sbuf <= sbuf_end) { + while (sbuf <= sbuf_end) { c = sbuf[0]; switch (c) { @@ -624,47 +656,40 @@ escape_json(const char *sbuf, int slen, char *dbuf, int dlen, int *scntp, } else { len = snprintf(append_buf, sizeof (append_buf), "\\u%04x", (int)(0xff & c)); - assert(len < sizeof (append_buf)); + VERIFY3S(len, <, sizeof (append_buf)); } append = append_buf; break; } - len = strlcpy(&dbuf[i], append, dlen - i); - if (len >= dlen - i) { + if (custr_append(dest, append) != 0) { + VERIFY3S(errno, ==, EOVERFLOW); if (flushp != NULL) { *flushp = B_TRUE; } break; - } else { - sbuf++; - i += len; } + + sbuf++; + if (flushp != NULL && *flushp) { break; } } - dbuf[i] = '\0'; - - *dcntp = i; *scntp = sbuf - save_sbuf; - assert(*dcntp < dlen); - assert(*scntp <= slen); - - /* Buffer is too full to append "\\n". Force a flush. */ - if (flushp != NULL && i >= dlen - 2) { - *flushp = B_TRUE; - } + VERIFY3U(*scntp, <=, slen); } /* * Like write(2), but to a logfile_t and with retries on short writes. */ static void -logfile_write(logfile_t *lfp, const char *buf, size_t buflen) +logfile_write(logfile_t *lfp, custr_t *cus) { + const char *buf = custr_cstr(cus); + size_t buflen = custr_len(cus); ssize_t wlen; size_t wanted = buflen; @@ -691,23 +716,14 @@ logfile_write(logfile_t *lfp, const char *buf, size_t buflen) } } -/* - * Convert the json pairs into a json object. A "time" element is added to - * every object. Returns the number of bytes that would have been written to - * buf if bufsz had buf been sufficiently large (excluding the terminating null - * byte). Like snprintf(). - */ -static size_t -make_json(jsonpair_t *pairs, int npairs, char *buf, size_t bufsz) +static void +add_bunyan_preamble(custr_t *cus) { struct tm gtm; struct timeval tv; - char ts[32]; - size_t len = 0; - int i; - const char *key, *val, *start, *end; - - assert(npairs > 0); + /* Large enough for YYYY-MM-DDTHH:MM:SS.000000000Z + NUL */ + char timestr[32] = { 0 }; + size_t len; if (gettimeofday(&tv, NULL) != 0 || gmtime_r(&tv.tv_sec, >m) == NULL) { @@ -715,59 +731,87 @@ make_json(jsonpair_t *pairs, int npairs, char *buf, size_t bufsz) abort(); } - if (snprintf(ts, sizeof (ts), "%04d-%02d-%02dT%02d:%02d:%02d.%09ldZ", - gtm.tm_year + 1900, gtm.tm_mon + 1, gtm.tm_mday, - gtm.tm_hour, gtm.tm_min, gtm.tm_sec, tv.tv_usec * 1000) >= - sizeof (ts)) { - logstream_err(B_FALSE, "timestamp buffer too small"); - abort(); - } + len = strftime(timestr, sizeof (timestr) - 1, "%FT%T", >m); + VERIFY3U(len, >, 0); + VERIFY3U(len, <, sizeof (timestr) - 1); - start = "{"; - end = ""; - for (i = 0; i <= npairs; i++) { - if (i < npairs) { - key = pairs[i].jp_key; - val = pairs[i].jp_val; - } else { - key = "time"; - val = ts; - end = "}\n"; - } + VERIFY0(custr_append_printf(cus, "\"time\": \"%s.%09ldZ\", ", + timestr, tv.tv_usec * 1000)); + VERIFY0(custr_append_printf(cus, "\"v\": %d, ", BUNYAN_VERSION)); + VERIFY0(custr_append_printf(cus, "\"hostname\": \"%s\", ", host)); + VERIFY0(custr_append(cus, "\"name\": \"zoneadmd\",")); + VERIFY0(custr_append_printf(cus, "\"pid\": %s, ", pidstr)); + VERIFY0(custr_append_printf(cus, "\"level\": %d", BUNYAN_LOG_LEVEL)); +} - len += snprintf(bufsz > len ? buf + len : NULL, - bufsz > len ? bufsz - len : 0, "%s\"%s\":\"%s\"%s", - start, key, val, end); +/* + * Convert the json pairs into a json object. The properties required for + * bunyan-formatted json objects are added to every object. + * Returns the number of bytes that would have been written to + * buf if bufsz had buf been sufficiently large (excluding the terminating null + * byte). Like snprintf(). + */ +static size_t +make_json(jsonpair_t *pairs, size_t npairs, custr_t *cus) +{ + int i; + const char *key, *val; + const char *start = ", "; + + VERIFY3S(npairs, >, 0); + + custr_reset(cus); + + VERIFY0(custr_append(cus, "{ ")); + + add_bunyan_preamble(cus); - start = ","; + for (i = 0; i < npairs; i++) { + size_t len; + + key = pairs[i].jp_key; + val = pairs[i].jp_val; + + /* The total number of bytes we're adding to cus */ + len = 3 + strlen(key) + 3 + strlen(val) + 1; + if (custr_append_printf(cus, "%s\"%s\":\"%s\"", + start, key, val) != 0) { + VERIFY3S(errno, ==, EOVERFLOW); + return (custr_len(cus) + len); + } } - return (len); + if (custr_append(cus, " }\n") != 0) { + return (custr_len(cus) + 3); + } + + return (custr_len(cus)); } static void logstream_write_json(logstream_t *lsp) { - char obuf[sizeof (lsp->ls_buf) + sizeof (lsp->ls_stream) + 64]; size_t len; jsonpair_t pairs[] = { - { "log", lsp->ls_buf }, + { "msg", lsp->ls_buf }, { "stream", lsp->ls_stream }, }; - if (lsp->ls_buflen == 0) { + if (custr_len(lsp->ls_cusbuf) == 0) { return; } - len = make_json(pairs, ARRAY_SIZE(pairs), obuf, sizeof (obuf)); - lsp->ls_buflen = 0; - if (len >= sizeof (obuf)) { + len = make_json(pairs, ARRAY_SIZE(pairs), lsp->ls_cusobuf); + + custr_reset(lsp->ls_cusbuf); + if (len >= sizeof (lsp->ls_obuf)) { logstream_err(B_FALSE, "%s: buffer too small. Need %llu bytes, " - "have %llu bytes", __func__, len + 1, sizeof (obuf)); + "have %llu bytes", __func__, len + 1, + sizeof (lsp->ls_obuf)); return; } - logfile_write(lsp->ls_logfile, obuf, len); + logfile_write(lsp->ls_logfile, lsp->ls_cusobuf); } /* @@ -784,14 +828,15 @@ void logstream_write(int ls, char *buf, int len) { logstream_t *lsp; - int scnt, dcnt; + size_t scnt; boolean_t newline; boolean_t buffered; if (ls == -1 || len == 0) { return; } - assert(ls >= 0 && ls < ARRAY_SIZE(streams)); + VERIFY3S(ls, >=, 0); + VERIFY3S(ls, <, ARRAY_SIZE(streams)); logstream_lock(); @@ -804,11 +849,9 @@ logstream_write(int ls, char *buf, int len) buffered = !!(lsp->ls_flags & LS_LINE_BUFFERED); do { - escape_json(buf, len, lsp->ls_buf + lsp->ls_buflen, - sizeof (lsp->ls_buf) - lsp->ls_buflen, - &scnt, &dcnt, buffered ? &newline : NULL); + escape_json(buf, len, lsp->ls_cusbuf, &scnt, + buffered ? &newline : NULL); - lsp->ls_buflen += dcnt; buf += scnt; len -= scnt; @@ -825,7 +868,7 @@ logstream_flush(int ls) { logstream_t *lsp; - assert(MUTEX_HELD(&logging_lock)); + VERIFY(MUTEX_HELD(&logging_lock)); lsp = &streams[ls]; if (lsp->ls_stream[0] == '\0' || lsp->ls_logfile == NULL) { @@ -839,7 +882,7 @@ logstream_flush_all(logfile_t *lfp) { int i; - assert(MUTEX_HELD(&logging_lock)); + VERIFY(MUTEX_HELD(&logging_lock)); for (i = 0; i < ARRAY_SIZE(streams); i++) { if (streams[i].ls_logfile == lfp) { @@ -856,8 +899,8 @@ logstream_open(const char *logname, const char *stream, logstream_flags_t flags) logstream_t *lsp; logfile_t *lfp = NULL; - assert(strlen(logname) < sizeof (lfp->lf_name)); - assert(strlen(stream) < sizeof (lsp->ls_stream)); + VERIFY3U(strlen(logname), <, sizeof (lfp->lf_name)); + VERIFY3U(strlen(stream), <, sizeof (lsp->ls_stream)); logstream_lock(); @@ -867,7 +910,7 @@ logstream_open(const char *logname, const char *stream, logstream_flags_t flags) */ for (i = 0; i < ARRAY_SIZE(streams); i++) { if (ls == -1 && streams[i].ls_stream[0] == '\0') { - assert(streams[i].ls_logfile == NULL); + VERIFY3P(streams[i].ls_logfile, ==, NULL); ls = i; continue; } @@ -878,7 +921,7 @@ logstream_open(const char *logname, const char *stream, logstream_flags_t flags) return (-1); } } - assert(ls != -1); + VERIFY3S(ls, !=, -1); /* Find an existing or available logfile_t */ for (i = 0; i < ARRAY_SIZE(logfiles); i++) { @@ -927,7 +970,8 @@ logstream_close(int ls, boolean_t abrupt) if (ls == -1) { return; } - assert(ls >= 0 && ls < ARRAY_SIZE(streams)); + VERIFY3S(ls, >=, 0); + VERIFY3S(ls, <, ARRAY_SIZE(streams)); logstream_lock(); logstream_flush(ls); @@ -935,8 +979,8 @@ logstream_close(int ls, boolean_t abrupt) lsp = &streams[ls]; lfp = lsp->ls_logfile; - assert(lsp->ls_stream[0] != '\0'); - assert(lfp != NULL); + VERIFY(lsp->ls_stream[0] != '\0'); + VERIFY3P(lfp, !=, NULL); (void) memset(lsp, 0, sizeof (*lsp)); |