1*03831d35Sstevel /*
2*03831d35Sstevel  * CDDL HEADER START
3*03831d35Sstevel  *
4*03831d35Sstevel  * The contents of this file are subject to the terms of the
5*03831d35Sstevel  * Common Development and Distribution License, Version 1.0 only
6*03831d35Sstevel  * (the "License").  You may not use this file except in compliance
7*03831d35Sstevel  * with the License.
8*03831d35Sstevel  *
9*03831d35Sstevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*03831d35Sstevel  * or http://www.opensolaris.org/os/licensing.
11*03831d35Sstevel  * See the License for the specific language governing permissions
12*03831d35Sstevel  * and limitations under the License.
13*03831d35Sstevel  *
14*03831d35Sstevel  * When distributing Covered Code, include this CDDL HEADER in each
15*03831d35Sstevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*03831d35Sstevel  * If applicable, add the following below this CDDL HEADER, with the
17*03831d35Sstevel  * fields enclosed by brackets "[]" replaced with your own identifying
18*03831d35Sstevel  * information: Portions Copyright [yyyy] [name of copyright owner]
19*03831d35Sstevel  *
20*03831d35Sstevel  * CDDL HEADER END
21*03831d35Sstevel  */
22*03831d35Sstevel /*
23*03831d35Sstevel  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24*03831d35Sstevel  * Use is subject to license terms.
25*03831d35Sstevel  */
26*03831d35Sstevel 
27*03831d35Sstevel #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*03831d35Sstevel 
29*03831d35Sstevel /*
30*03831d35Sstevel  * set.c: support for the scadm set option (set NV variables in the service
31*03831d35Sstevel  * processor)
32*03831d35Sstevel  */
33*03831d35Sstevel 
34*03831d35Sstevel #include <libintl.h>
35*03831d35Sstevel #include <stdio.h>
36*03831d35Sstevel #include <string.h>
37*03831d35Sstevel #include <time.h>  /* required by librsc.h */
38*03831d35Sstevel 
39*03831d35Sstevel #include "librsc.h"
40*03831d35Sstevel #include "adm.h"
41*03831d35Sstevel 
42*03831d35Sstevel 
43*03831d35Sstevel void
ADM_Process_set(int argc,char * argv[])44*03831d35Sstevel ADM_Process_set(int argc, char *argv[])
45*03831d35Sstevel {
46*03831d35Sstevel 	rscp_msg_t	Message;
47*03831d35Sstevel 	struct timespec	Timeout;
48*03831d35Sstevel 	static char	DataBuffer[DP_MAX_MSGLEN];
49*03831d35Sstevel 
50*03831d35Sstevel 
51*03831d35Sstevel 	if (argc != 4) {
52*03831d35Sstevel 		(void) fprintf(stderr, "\n%s\n\n",
53*03831d35Sstevel 		    gettext("USAGE: scadm set <variable> <value>"));
54*03831d35Sstevel 		exit(-1);
55*03831d35Sstevel 	}
56*03831d35Sstevel 
57*03831d35Sstevel 	ADM_Start();
58*03831d35Sstevel 
59*03831d35Sstevel 	Message.type = DP_SET_CFGVAR;
60*03831d35Sstevel 	Message.len  = strlen(argv[2]) + strlen(argv[3]) + 2;
61*03831d35Sstevel 	if (Message.len > DP_MAX_MSGLEN - 4) {
62*03831d35Sstevel 		(void) fprintf(stderr, "\n%s\n\n",
63*03831d35Sstevel 		    gettext("scadm: command line too long"));
64*03831d35Sstevel 		exit(-1);
65*03831d35Sstevel 	}
66*03831d35Sstevel 
67*03831d35Sstevel 	/*
68*03831d35Sstevel 	 * Concatenate the two strings into DataBuffer.  Make sure you
69*03831d35Sstevel 	 * leave space for the string termination char.
70*03831d35Sstevel 	 */
71*03831d35Sstevel 	(void) strcpy(DataBuffer, argv[2]);
72*03831d35Sstevel 	(void) strcpy(&DataBuffer[strlen(argv[2])+1], argv[3]);
73*03831d35Sstevel 	Message.data = DataBuffer;
74*03831d35Sstevel 
75*03831d35Sstevel 	ADM_Send(&Message);
76*03831d35Sstevel 
77*03831d35Sstevel 	Timeout.tv_nsec = 0;
78*03831d35Sstevel 	Timeout.tv_sec  = ADM_TIMEOUT;
79*03831d35Sstevel 	ADM_Recv(&Message, &Timeout,
80*03831d35Sstevel 	    DP_SET_CFGVAR_R, sizeof (dp_set_cfgvar_r_t));
81*03831d35Sstevel 
82*03831d35Sstevel 	if (*(int *)Message.data != 0) {
83*03831d35Sstevel 		(void) fprintf(stderr, "\n%s\n\n",
84*03831d35Sstevel 		    gettext("scadm: invalid variable or value"));
85*03831d35Sstevel 		exit(-1);
86*03831d35Sstevel 	}
87*03831d35Sstevel 
88*03831d35Sstevel 	ADM_Free(&Message);
89*03831d35Sstevel }
90