4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <sys/sysevent/eventdefs.h>
27 #include <sys/fm/util.h>
28 #include <fm/fmd_log.h>
29 #include <libsysevent.h>
33 #include <inj_string.h>
41 (void) fprintf(stderr
, "Usage: %s [-nqv] [-c chan] [file]\n"
42 "\t-c specify alternate channel to use for publication\n"
43 "\t-n compile program but do not inject any events\n"
44 "\t-q enable quiet mode (silence status messages)\n"
45 "\t-v enable verbose output (display event details)\n",
52 * Sysevent-based event delivery
55 sev_open(const char *chan
)
62 if ((errno
= sysevent_evc_bind(chan
, &hdl
,
63 EVCH_CREAT
| EVCH_HOLD_PEND
)) != 0)
64 die("can't bind to error channel %s", chan
);
70 sev_send(void *arg
, nvlist_t
*msg
)
72 if ((errno
= sysevent_evc_publish(arg
, EC_FM
, ESC_FM_ERROR
,
73 "com.sun", getpname(), msg
, EVCH_SLEEP
)) != 0)
74 warn("failed to send event");
80 (void) sysevent_evc_unbind(arg
);
83 static inj_mode_ops_t sysevent_ops
= {
94 sim_open(const char *arg
)
101 sim_send(void *arg
, nvlist_t
*msg
)
111 static inj_mode_ops_t simulate_ops
= {
118 main(int argc
, char *argv
[])
120 const inj_mode_ops_t
*mode
= NULL
;
121 void *mode_arg
= NULL
;
128 while ((c
= getopt(argc
, argv
, "c:nqv")) != EOF
) {
131 if (mode
!= NULL
|| mode_arg
!= NULL
)
134 mode
= &sysevent_ops
;
142 mode
= &simulate_ops
;
159 mode
= &sysevent_ops
;
171 srand48(gethrtime());
173 if (argc
> 0 && (lp
= fmd_log_open(FMD_LOG_VERSION
, file
, &c
)) != NULL
)
174 program
= inj_logfile_read(lp
);
176 program
= inj_program_read(file
);
178 inj_program_run(program
, mode
, mode_arg
);