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