예제 #1
0
/* ARGSUSED */
ilbadm_status_t
ilbadm_show_hc(int argc, char *argv[])
{
    ilb_handle_t	h = ILB_INVALID_HANDLE;
    ilb_status_t	rclib;
    ofmt_handle_t	ofmt_h;
    ofmt_status_t	ofmt_ret;

    if ((ofmt_ret = ofmt_open("all", hc_fields, 0, SHOW_HC_COLS,
                              &ofmt_h)) != OFMT_SUCCESS) {
        char err_buf[SHOW_HC_COLS];

        ilbadm_err(gettext("ofmt_open failed: %s"),
                   ofmt_strerror(ofmt_h, ofmt_ret, err_buf, SHOW_HC_COLS));
        return (ILBADM_LIBERR);
    }
    rclib = ilb_open(&h);
    if (rclib != ILB_STATUS_OK)
        goto out;

    if (argc == 1) {
        rclib = ilb_walk_hc(h, ilbadm_print_hc, ofmt_h);
    } else {
        ilb_hc_info_t hc_info;
        int i;

        for (i = 1; i < argc; i++) {
            rclib = ilb_get_hc_info(h, argv[i], &hc_info);
            if (rclib == ILB_STATUS_OK)
                ofmt_print(ofmt_h, &hc_info);
            else
                break;
        }
    }
out:
    ofmt_close(ofmt_h);

    if (h != ILB_INVALID_HANDLE)
        (void) ilb_close(h);

    if (rclib != ILB_STATUS_OK) {
        ilbadm_err(ilb_errstr(rclib));
        return (ILBADM_LIBERR);
    }

    return (ILBADM_OK);
}
예제 #2
0
/*
 * Walk through all health checks, will need if we implement list-hc
 */
ilb_status_t
ilb_walk_hc(ilb_handle_t h, hc_walkerfunc_t func, void *arg)
{
	ilb_status_t	rc;
	ilb_hc_info_t	hc_info;
	ilbd_namelist_t	*hc_names;
	ilb_comm_t	ic, *rbuf;
	size_t		rbufsz;
	int		i;

	rbufsz = ILBD_MSG_SIZE;
	if ((rbuf = malloc(rbufsz)) == NULL)
		return (ILB_STATUS_ENOMEM);
	ic.ic_cmd = ILBD_RETRIEVE_HC_NAMES;

	rc = i_ilb_do_comm(h, &ic, sizeof (ic), rbuf, &rbufsz);
	if (rc != ILB_STATUS_OK)
		goto out;
	if (rbuf->ic_cmd != ILBD_CMD_OK) {
		rc = *(ilb_status_t *)&rbuf->ic_data;
		goto out;
	}

	hc_names = (ilbd_namelist_t *)&rbuf->ic_data;
	for (i = 0; i < hc_names->ilbl_count; i++) {
		rc = ilb_get_hc_info(h, hc_names->ilbl_name[i], &hc_info);
		/*
		 * Since getting the list of hc names and getting the info
		 * of each of them are not atomic, some hc objects may have
		 * been deleted.  If this is the case, just skip them.
		 */
		if (rc == ILB_STATUS_ENOENT) {
			rc = ILB_STATUS_OK;
			continue;
		} else if (rc != ILB_STATUS_OK) {
			break;
		}
		rc = func(h, &hc_info, arg);
	}

out:
	free(rbuf);
	return (rc);
}