xref: /illumos-gate/usr/src/cmd/scadm/sparc/mpxu/common/set.c (revision 7a6d80f1660abd4755c68cbd094d4a914681d26e)
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  * set.c: support for the scadm set option (set NV variables in the service
29  * 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 void
42 ADM_Process_set(int argc, char *argv[])
43 {
44 	rscp_msg_t	Message;
45 	struct timespec	Timeout;
46 	static char	DataBuffer[DP_MAX_MSGLEN];
47 
48 
49 	if (argc != 4) {
50 		(void) fprintf(stderr, "\n%s\n\n",
51 		    gettext("USAGE: scadm set <variable> <value>"));
52 		exit(-1);
53 	}
54 
55 	ADM_Start();
56 
57 	Message.type = DP_SET_CFGVAR;
58 	Message.len  = strlen(argv[2]) + strlen(argv[3]) + 2;
59 	if (Message.len > DP_MAX_MSGLEN - 4) {
60 		(void) fprintf(stderr, "\n%s\n\n",
61 		    gettext("scadm: command line too long"));
62 		exit(-1);
63 	}
64 
65 	/*
66 	 * Concatenate the two strings into DataBuffer.  Make sure you
67 	 * leave space for the string termination char.
68 	 */
69 	(void) strcpy(DataBuffer, argv[2]);
70 	(void) strcpy(&DataBuffer[strlen(argv[2])+1], argv[3]);
71 	Message.data = DataBuffer;
72 
73 	ADM_Send(&Message);
74 
75 	Timeout.tv_nsec = 0;
76 	Timeout.tv_sec  = ADM_TIMEOUT;
77 	ADM_Recv(&Message, &Timeout,
78 	    DP_SET_CFGVAR_R, sizeof (dp_set_cfgvar_r_t));
79 
80 	if (*(int *)Message.data != 0) {
81 		(void) fprintf(stderr, "\n%s\n\n",
82 		    gettext("scadm: invalid variable or value"));
83 		exit(-1);
84 	}
85 
86 	ADM_Free(&Message);
87 }
88