xref: /illumos-gate/usr/src/cmd/scadm/sparc/mpxu/common/send_event.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * send_event.c: support for the scadm send_event option (send an event message
29  * to the service processor)
30  */
31 
32 #include <libintl.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <time.h>  /* required by librsc.h */
36 
37 #include "librsc.h"
38 #include "adm.h"
39 
40 
41 static void usage();
42 
43 typedef union data_buffer {
44 	char	DataBuffer[DP_MAX_MSGLEN];
45 	void	*DataBuffer_p;
46 } data_buffer_t;
47 
48 void
ADM_Process_send_event(int argc,char * argv[])49 ADM_Process_send_event(int argc, char *argv[])
50 {
51 	rscp_msg_t		Message;
52 	struct timespec		Timeout;
53 	static data_buffer_t	DataBuffer;
54 	dp_send_alert_t		*Parms;
55 	char			*Alert;
56 
57 
58 	if ((argc != 3) && (argc != 4)) {
59 		usage();
60 		exit(-1);
61 	}
62 	if (argc == 4) {
63 		if (strcasecmp(argv[2],  "-c") != 0) {
64 			usage();
65 			exit(-1);
66 		}
67 	}
68 
69 	ADM_Start();
70 
71 	Parms = (dp_send_alert_t *)&DataBuffer;
72 	Alert = (char *)(&((char *)Parms)[sizeof (dp_send_alert_t)]);
73 	if (argc == 3) {
74 		Parms->critical = 0;
75 		(void) strcpy(Alert, argv[2]);
76 	} else {
77 		Parms->critical = 1;
78 		(void) strcpy(Alert, argv[3]);
79 	}
80 	if (strlen(Alert) > 80) {
81 		(void) fprintf(stderr, "\n%s\n\n",
82 		    gettext("scadm: event message can't exceed 80 characters"));
83 		exit(-1);
84 	}
85 
86 	Message.type = DP_SEND_ALERT;
87 	Message.len  = sizeof (dp_send_alert_t) + strlen(Alert) + 1;
88 	Message.data = Parms;
89 	ADM_Send(&Message);
90 
91 	Timeout.tv_nsec = 0;
92 	Timeout.tv_sec  = ADM_TIMEOUT;
93 	ADM_Recv(&Message, &Timeout, DP_SEND_ALERT_R,
94 	    sizeof (dp_send_alert_r_t));
95 
96 	if (*(int *)Message.data != 0) {
97 		(void) fprintf(stderr, "\n%s\n\n",
98 		    gettext("scadm: could not send alert"));
99 		exit(-1);
100 	}
101 
102 	ADM_Free(&Message);
103 }
104 
105 
106 static void
usage()107 usage()
108 {
109 	(void) fprintf(stderr, "\n%s\n\n",
110 	    gettext("USAGE: scadm send_event [-c] \"message\""));
111 }
112