b695575577bae0337af339d76949713bfe1c9013Robert Johnston/*
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * CDDL HEADER START
b695575577bae0337af339d76949713bfe1c9013Robert Johnston *
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * The contents of this file are subject to the terms of the
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * Common Development and Distribution License (the "License").
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * You may not use this file except in compliance with the License.
b695575577bae0337af339d76949713bfe1c9013Robert Johnston *
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * or http://www.opensolaris.org/os/licensing.
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * See the License for the specific language governing permissions
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * and limitations under the License.
b695575577bae0337af339d76949713bfe1c9013Robert Johnston *
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * When distributing Covered Code, include this CDDL HEADER in each
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * If applicable, add the following below this CDDL HEADER, with the
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * fields enclosed by brackets "[]" replaced with your own identifying
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * information: Portions Copyright [yyyy] [name of copyright owner]
b695575577bae0337af339d76949713bfe1c9013Robert Johnston *
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * CDDL HEADER END
b695575577bae0337af339d76949713bfe1c9013Robert Johnston */
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston/*
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * Use is subject to license terms.
b695575577bae0337af339d76949713bfe1c9013Robert Johnston */
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston#include <sys/types.h>
b695575577bae0337af339d76949713bfe1c9013Robert Johnston#include <sys/wait.h>
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston#include <sys/fm/protocol.h>
b695575577bae0337af339d76949713bfe1c9013Robert Johnston#include <fm/fmd_msg.h>
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston#include <unistd.h>
b695575577bae0337af339d76949713bfe1c9013Robert Johnston#include <signal.h>
b695575577bae0337af339d76949713bfe1c9013Robert Johnston#include <strings.h>
b695575577bae0337af339d76949713bfe1c9013Robert Johnston#include <stdlib.h>
b695575577bae0337af339d76949713bfe1c9013Robert Johnston#include <stdio.h>
b695575577bae0337af339d76949713bfe1c9013Robert Johnston#include <errno.h>
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston#define TEST_ARR_SZ 2
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnstonint
b695575577bae0337af339d76949713bfe1c9013Robert Johnstonmain(int argc, char *argv[])
b695575577bae0337af339d76949713bfe1c9013Robert Johnston{
b695575577bae0337af339d76949713bfe1c9013Robert Johnston fmd_msg_hdl_t *h;
b695575577bae0337af339d76949713bfe1c9013Robert Johnston pid_t pid;
b695575577bae0337af339d76949713bfe1c9013Robert Johnston int i, err = 0;
b695575577bae0337af339d76949713bfe1c9013Robert Johnston char *s;
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston nvlist_t *auth, *fmri, *list, *test_arr[TEST_ARR_SZ];
b695575577bae0337af339d76949713bfe1c9013Robert Johnston const char *code = "TEST-8000-08";
b695575577bae0337af339d76949713bfe1c9013Robert Johnston int64_t tod[] = { 0x9400000, 0 };
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (argc > 1) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "Usage: %s\n", argv[0]);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (2);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston /*
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * Build up a valid list.suspect event for a fictional diagnosis
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * using a diagnosis code from our test dictionary so we can format
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * messages.
b695575577bae0337af339d76949713bfe1c9013Robert Johnston */
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (nvlist_alloc(&auth, NV_UNIQUE_NAME, 0) != 0 ||
b695575577bae0337af339d76949713bfe1c9013Robert Johnston nvlist_alloc(&fmri, NV_UNIQUE_NAME, 0) != 0 ||
b695575577bae0337af339d76949713bfe1c9013Robert Johnston nvlist_alloc(&list, NV_UNIQUE_NAME, 0) != 0) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: nvlist_alloc failed\n", argv[0]);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_uint8(auth, FM_VERSION, FM_FMRI_AUTH_VERSION);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_string(auth, FM_FMRI_AUTH_PRODUCT, "product");
9c94f155585ea35e938fea603bc227c685223abdCheng Sean Ye err |= nvlist_add_string(auth, FM_FMRI_AUTH_PRODUCT_SN, "product_sn");
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_string(auth, FM_FMRI_AUTH_CHASSIS, "chassis");
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_string(auth, FM_FMRI_AUTH_DOMAIN, "domain");
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_string(auth, FM_FMRI_AUTH_SERVER, "server");
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (err != 0) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: failed to build auth nvlist: %s\n",
b695575577bae0337af339d76949713bfe1c9013Robert Johnston argv[0], strerror(err));
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_uint8(fmri, FM_VERSION, FM_FMD_SCHEME_VERSION);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_string(fmri, FM_FMRI_SCHEME, FM_FMRI_SCHEME_FMD);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_nvlist(fmri, FM_FMRI_AUTHORITY, auth);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_string(fmri, FM_FMRI_FMD_NAME, "fmd_msg_test");
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_string(fmri, FM_FMRI_FMD_VERSION, "1.0");
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (err != 0) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: failed to build fmri nvlist: %s\n",
b695575577bae0337af339d76949713bfe1c9013Robert Johnston argv[0], strerror(err));
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_uint8(list, FM_VERSION, FM_SUSPECT_VERSION);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_string(list, FM_CLASS, FM_LIST_SUSPECT_CLASS);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_string(list, FM_SUSPECT_UUID, "12345678");
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_string(list, FM_SUSPECT_DIAG_CODE, code);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_int64_array(list, FM_SUSPECT_DIAG_TIME, tod, 2);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_nvlist(list, FM_SUSPECT_DE, fmri);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_uint32(list, FM_SUSPECT_FAULT_SZ, 0);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston /*
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * Add a contrived nvlist array to our list.suspect so that we can
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * exercise the expansion syntax for dereferencing nvlist array members
b695575577bae0337af339d76949713bfe1c9013Robert Johnston */
b695575577bae0337af339d76949713bfe1c9013Robert Johnston for (i = 0; i < TEST_ARR_SZ; i++) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (nvlist_alloc(&test_arr[i], NV_UNIQUE_NAME, 0) != 0) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: failed to alloc nvlist "
b695575577bae0337af339d76949713bfe1c9013Robert Johnston "array: %s\n", argv[0], strerror(err));
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_uint8(test_arr[i], "index", i);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston err |= nvlist_add_nvlist_array(list, "test_arr", test_arr, TEST_ARR_SZ);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (err != 0) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: failed to build list nvlist: %s\n",
b695575577bae0337af339d76949713bfe1c9013Robert Johnston argv[0], strerror(err));
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston /*
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * Now initialize the libfmd_msg library for testing, using the message
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * catalogs found in the proto area of the current workspace.
b695575577bae0337af339d76949713bfe1c9013Robert Johnston */
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if ((h = fmd_msg_init(getenv("ROOT"), FMD_MSG_VERSION)) == NULL) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: fmd_msg_init failed: %s\n",
b695575577bae0337af339d76949713bfe1c9013Robert Johnston argv[0], strerror(errno));
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston /*
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * Test 0: Verify that both fmd_msg_getitem_id and fmd_msg_gettext_id
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * return NULL and EINVAL for an illegal message code, and NULL
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * and ENOENT for a valid but not defined message code.
b695575577bae0337af339d76949713bfe1c9013Robert Johnston */
b695575577bae0337af339d76949713bfe1c9013Robert Johnston s = fmd_msg_getitem_id(h, NULL, "I_AM_NOT_VALID", 0);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (s != NULL || errno != EINVAL) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: test0 FAIL: illegal code returned "
b695575577bae0337af339d76949713bfe1c9013Robert Johnston "s = %p, errno = %d\n", argv[0], (void *)s, errno);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston s = fmd_msg_gettext_id(h, NULL, "I_AM_NOT_VALID");
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (s != NULL || errno != EINVAL) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: test0 FAIL: illegal code returned "
b695575577bae0337af339d76949713bfe1c9013Robert Johnston "s = %p, errno = %d\n", argv[0], (void *)s, errno);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston s = fmd_msg_getitem_id(h, NULL, "I_AM_NOT_HERE-0000-0000", 0);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (s != NULL || errno != ENOENT) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: test0 FAIL: missing code returned "
b695575577bae0337af339d76949713bfe1c9013Robert Johnston "s = %p, errno = %d\n", argv[0], (void *)s, errno);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston s = fmd_msg_gettext_id(h, NULL, "I_AM_NOT_HERE-0000-0000");
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (s != NULL || errno != ENOENT) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: test0 FAIL: missing code returned "
b695575577bae0337af339d76949713bfe1c9013Robert Johnston "s = %p, errno = %d\n", argv[0], (void *)s, errno);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston /*
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * Test 1: Use fmd_msg_getitem_id to retrieve the item strings for
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * a known message code without having any actual event handle.
b695575577bae0337af339d76949713bfe1c9013Robert Johnston */
b695575577bae0337af339d76949713bfe1c9013Robert Johnston for (i = 0; i < FMD_MSG_ITEM_MAX; i++) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if ((s = fmd_msg_getitem_id(h, NULL, code, i)) == NULL) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: fmd_msg_getitem_id failed "
b695575577bae0337af339d76949713bfe1c9013Robert Johnston "for %s, item %d: %s\n",
b695575577bae0337af339d76949713bfe1c9013Robert Johnston argv[0], code, i, strerror(errno));
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) printf("code %s item %d = <<%s>>\n", code, i, s);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston free(s);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston /*
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * Test 2: Use fmd_msg_gettext_id to retrieve the complete message for
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * a known message code without having any actual event handle.
b695575577bae0337af339d76949713bfe1c9013Robert Johnston */
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if ((s = fmd_msg_gettext_id(h, NULL, code)) == NULL) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: fmd_msg_gettext_id failed for %s: "
b695575577bae0337af339d76949713bfe1c9013Robert Johnston "%s\n", argv[0], code, strerror(errno));
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) printf("%s\n", s);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston free(s);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston /*
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * Test 3: Use fmd_msg_getitem_nv to retrieve the item strings for
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * our list.suspect event handle.
b695575577bae0337af339d76949713bfe1c9013Robert Johnston */
b695575577bae0337af339d76949713bfe1c9013Robert Johnston for (i = 0; i < FMD_MSG_ITEM_MAX; i++) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if ((s = fmd_msg_getitem_nv(h, NULL, list, i)) == NULL) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: fmd_msg_getitem_nv failed "
b695575577bae0337af339d76949713bfe1c9013Robert Johnston "for %s, item %d: %s\n",
b695575577bae0337af339d76949713bfe1c9013Robert Johnston argv[0], code, i, strerror(errno));
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) printf("code %s item %d = <<%s>>\n", code, i, s);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston free(s);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston /*
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * Test 4: Use fmd_msg_getitem_nv to retrieve the complete message for
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * a known message code using our list.suspect event handle.
b695575577bae0337af339d76949713bfe1c9013Robert Johnston */
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if ((s = fmd_msg_gettext_nv(h, NULL, list)) == NULL) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: fmd_msg_gettext_nv failed for %s: "
b695575577bae0337af339d76949713bfe1c9013Robert Johnston "%s\n", argv[0], code, strerror(errno));
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) printf("%s\n", s);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston free(s);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston /*
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * Test 5: Use fmd_msg_getitem_nv to retrieve the complete message for
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * a known message code using our list.suspect event handle, but this
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * time set the URL to our own customized URL. Our contrived message
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * has been designed to exercise the key aspects of the variable
b695575577bae0337af339d76949713bfe1c9013Robert Johnston * expansion syntax.
b695575577bae0337af339d76949713bfe1c9013Robert Johnston */
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (fmd_msg_url_set(h, "http://foo.bar.com/") != 0) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: fmd_msg_url_set failed: %s\n",
b695575577bae0337af339d76949713bfe1c9013Robert Johnston argv[0], strerror(errno));
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if ((s = fmd_msg_gettext_nv(h, NULL, list)) == NULL) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "%s: fmd_msg_gettext_nv failed for %s: "
b695575577bae0337af339d76949713bfe1c9013Robert Johnston "%s\n", argv[0], code, strerror(errno));
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) printf("%s\n", s);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston free(s);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston for (i = 0; i < TEST_ARR_SZ; i++)
b695575577bae0337af339d76949713bfe1c9013Robert Johnston nvlist_free(test_arr[i]);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston nvlist_free(fmri);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston nvlist_free(auth);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston nvlist_free(list);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston fmd_msg_fini(h); /* free library state before dumping core */
b695575577bae0337af339d76949713bfe1c9013Robert Johnston pid = fork(); /* fork into background to not bother make(1) */
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston switch (pid) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston case -1:
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "FAIL (failed to fork)\n");
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston case 0:
b695575577bae0337af339d76949713bfe1c9013Robert Johnston abort();
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (waitpid(pid, &err, 0) == -1) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "FAIL (failed to wait for %d: %s)\n",
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (int)pid, strerror(errno));
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (WIFSIGNALED(err) == 0 || WTERMSIG(err) != SIGABRT) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "FAIL (child did not SIGABRT)\n");
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston if (!WCOREDUMP(err)) {
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "FAIL (no core generated)\n");
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (1);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston }
b695575577bae0337af339d76949713bfe1c9013Robert Johnston
b695575577bae0337af339d76949713bfe1c9013Robert Johnston (void) fprintf(stderr, "done\n");
b695575577bae0337af339d76949713bfe1c9013Robert Johnston return (0);
b695575577bae0337af339d76949713bfe1c9013Robert Johnston}