xref: /onnv-gate/usr/src/cmd/svr4pkg/libinst/echo.c (revision 9781:ccf49524d5dc)
1*9781SMoriah.Waterland@Sun.COM /*
2*9781SMoriah.Waterland@Sun.COM  * CDDL HEADER START
3*9781SMoriah.Waterland@Sun.COM  *
4*9781SMoriah.Waterland@Sun.COM  * The contents of this file are subject to the terms of the
5*9781SMoriah.Waterland@Sun.COM  * Common Development and Distribution License (the "License").
6*9781SMoriah.Waterland@Sun.COM  * You may not use this file except in compliance with the License.
7*9781SMoriah.Waterland@Sun.COM  *
8*9781SMoriah.Waterland@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9781SMoriah.Waterland@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*9781SMoriah.Waterland@Sun.COM  * See the License for the specific language governing permissions
11*9781SMoriah.Waterland@Sun.COM  * and limitations under the License.
12*9781SMoriah.Waterland@Sun.COM  *
13*9781SMoriah.Waterland@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*9781SMoriah.Waterland@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9781SMoriah.Waterland@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*9781SMoriah.Waterland@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*9781SMoriah.Waterland@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*9781SMoriah.Waterland@Sun.COM  *
19*9781SMoriah.Waterland@Sun.COM  * CDDL HEADER END
20*9781SMoriah.Waterland@Sun.COM  */
21*9781SMoriah.Waterland@Sun.COM 
22*9781SMoriah.Waterland@Sun.COM /*
23*9781SMoriah.Waterland@Sun.COM  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*9781SMoriah.Waterland@Sun.COM  * Use is subject to license terms.
25*9781SMoriah.Waterland@Sun.COM  */
26*9781SMoriah.Waterland@Sun.COM 
27*9781SMoriah.Waterland@Sun.COM /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*9781SMoriah.Waterland@Sun.COM /* All Rights Reserved */
29*9781SMoriah.Waterland@Sun.COM 
30*9781SMoriah.Waterland@Sun.COM 
31*9781SMoriah.Waterland@Sun.COM 
32*9781SMoriah.Waterland@Sun.COM /*
33*9781SMoriah.Waterland@Sun.COM  * System includes
34*9781SMoriah.Waterland@Sun.COM  */
35*9781SMoriah.Waterland@Sun.COM 
36*9781SMoriah.Waterland@Sun.COM #include <stdio.h>
37*9781SMoriah.Waterland@Sun.COM #include <stdarg.h>
38*9781SMoriah.Waterland@Sun.COM #include <unistd.h>
39*9781SMoriah.Waterland@Sun.COM #include <fcntl.h>
40*9781SMoriah.Waterland@Sun.COM #include <sys/types.h>
41*9781SMoriah.Waterland@Sun.COM #include <zone.h>
42*9781SMoriah.Waterland@Sun.COM 
43*9781SMoriah.Waterland@Sun.COM /*
44*9781SMoriah.Waterland@Sun.COM  * consolidation pkg command library includes
45*9781SMoriah.Waterland@Sun.COM  */
46*9781SMoriah.Waterland@Sun.COM 
47*9781SMoriah.Waterland@Sun.COM #include "pkglib.h"
48*9781SMoriah.Waterland@Sun.COM 
49*9781SMoriah.Waterland@Sun.COM /*
50*9781SMoriah.Waterland@Sun.COM  * internal global variables
51*9781SMoriah.Waterland@Sun.COM  */
52*9781SMoriah.Waterland@Sun.COM 
53*9781SMoriah.Waterland@Sun.COM static boolean_t	debugFlag = B_FALSE;	/* debug messages enabled? */
54*9781SMoriah.Waterland@Sun.COM static boolean_t	echoFlag = B_TRUE;	/* interactive msgs enabled? */
55*9781SMoriah.Waterland@Sun.COM 
56*9781SMoriah.Waterland@Sun.COM /*
57*9781SMoriah.Waterland@Sun.COM  * *****************************************************************************
58*9781SMoriah.Waterland@Sun.COM  * global external (public) functions
59*9781SMoriah.Waterland@Sun.COM  * *****************************************************************************
60*9781SMoriah.Waterland@Sun.COM  */
61*9781SMoriah.Waterland@Sun.COM 
62*9781SMoriah.Waterland@Sun.COM /*
63*9781SMoriah.Waterland@Sun.COM  * Name:	echo
64*9781SMoriah.Waterland@Sun.COM  * Synopsis:	Output an interactive message if interaction is enabled
65*9781SMoriah.Waterland@Sun.COM  * Description:	Main method for outputting an interactive message; call to
66*9781SMoriah.Waterland@Sun.COM  *		output interactive message if interation has not been disabled
67*9781SMoriah.Waterland@Sun.COM  *		by a previous call to echoSetFlag(0).
68*9781SMoriah.Waterland@Sun.COM  * Arguments:	format - [RO, RO*] (char *)
69*9781SMoriah.Waterland@Sun.COM  *			printf-style format for debugging message to be output
70*9781SMoriah.Waterland@Sun.COM  *		VARG_LIST - [RO] (?)
71*9781SMoriah.Waterland@Sun.COM  *			arguments as appropriate to 'format' specified
72*9781SMoriah.Waterland@Sun.COM  * Returns:	void
73*9781SMoriah.Waterland@Sun.COM  */
74*9781SMoriah.Waterland@Sun.COM 
75*9781SMoriah.Waterland@Sun.COM /*PRINTFLIKE1*/
76*9781SMoriah.Waterland@Sun.COM void
echo(char * fmt,...)77*9781SMoriah.Waterland@Sun.COM echo(char *fmt, ...)
78*9781SMoriah.Waterland@Sun.COM {
79*9781SMoriah.Waterland@Sun.COM 	va_list ap;
80*9781SMoriah.Waterland@Sun.COM 
81*9781SMoriah.Waterland@Sun.COM 	/* output message if echoing is enabled */
82*9781SMoriah.Waterland@Sun.COM 
83*9781SMoriah.Waterland@Sun.COM 	if (echoFlag == B_TRUE) {
84*9781SMoriah.Waterland@Sun.COM 		va_start(ap, fmt);
85*9781SMoriah.Waterland@Sun.COM 
86*9781SMoriah.Waterland@Sun.COM 		(void) vfprintf(stderr, fmt, ap);
87*9781SMoriah.Waterland@Sun.COM 
88*9781SMoriah.Waterland@Sun.COM 		va_end(ap);
89*9781SMoriah.Waterland@Sun.COM 
90*9781SMoriah.Waterland@Sun.COM 		(void) putc('\n', stderr);
91*9781SMoriah.Waterland@Sun.COM 	}
92*9781SMoriah.Waterland@Sun.COM }
93*9781SMoriah.Waterland@Sun.COM 
94*9781SMoriah.Waterland@Sun.COM /*
95*9781SMoriah.Waterland@Sun.COM  * Name:	echoDebug
96*9781SMoriah.Waterland@Sun.COM  * Synopsis:	Output a debugging message if debugging is enabled
97*9781SMoriah.Waterland@Sun.COM  * Description:	Main method for outputting a debugging message; call to
98*9781SMoriah.Waterland@Sun.COM  *		output debugging message if debugging has been enabled
99*9781SMoriah.Waterland@Sun.COM  *		by a previous call to echoDebugSetFlag(1).
100*9781SMoriah.Waterland@Sun.COM  * Arguments:	format - [RO, RO*] (char *)
101*9781SMoriah.Waterland@Sun.COM  *			printf-style format for debugging message to be output
102*9781SMoriah.Waterland@Sun.COM  *		VARG_LIST - [RO] (?)
103*9781SMoriah.Waterland@Sun.COM  *			arguments as appropriate to 'format' specified
104*9781SMoriah.Waterland@Sun.COM  * Returns:	void
105*9781SMoriah.Waterland@Sun.COM  * NOTE:	format of message will be:
106*9781SMoriah.Waterland@Sun.COM  *			# [ aaa bbb ccc ] message
107*9781SMoriah.Waterland@Sun.COM  *		where:	aaa - process i.d.
108*9781SMoriah.Waterland@Sun.COM  *			bbb - zone i.d.
109*9781SMoriah.Waterland@Sun.COM  *			ccc - name of program
110*9781SMoriah.Waterland@Sun.COM  * 		for example:
111*9781SMoriah.Waterland@Sun.COM  *			# [ 25685   0 pkgadd     ] unable to get package list
112*9781SMoriah.Waterland@Sun.COM  */
113*9781SMoriah.Waterland@Sun.COM 
114*9781SMoriah.Waterland@Sun.COM /*PRINTFLIKE1*/
115*9781SMoriah.Waterland@Sun.COM void
echoDebug(char * a_fmt,...)116*9781SMoriah.Waterland@Sun.COM echoDebug(char *a_fmt, ...)
117*9781SMoriah.Waterland@Sun.COM {
118*9781SMoriah.Waterland@Sun.COM 	va_list ap;
119*9781SMoriah.Waterland@Sun.COM 
120*9781SMoriah.Waterland@Sun.COM 	/* output debugging message if debugging is enabled */
121*9781SMoriah.Waterland@Sun.COM 
122*9781SMoriah.Waterland@Sun.COM 	if (debugFlag == B_TRUE) {
123*9781SMoriah.Waterland@Sun.COM 		char	*p = get_prog_name();
124*9781SMoriah.Waterland@Sun.COM 
125*9781SMoriah.Waterland@Sun.COM 		(void) fprintf(stderr, "# [%6d %3d", getpid(), getzoneid());
126*9781SMoriah.Waterland@Sun.COM 
127*9781SMoriah.Waterland@Sun.COM 		if ((p != (char *)NULL) && (*p != '\0')) {
128*9781SMoriah.Waterland@Sun.COM 			fprintf(stderr, " %-11s", p);
129*9781SMoriah.Waterland@Sun.COM 		}
130*9781SMoriah.Waterland@Sun.COM 
131*9781SMoriah.Waterland@Sun.COM 		(void) fprintf(stderr, "] ");
132*9781SMoriah.Waterland@Sun.COM 
133*9781SMoriah.Waterland@Sun.COM 		va_start(ap, a_fmt);
134*9781SMoriah.Waterland@Sun.COM 
135*9781SMoriah.Waterland@Sun.COM 		(void) vfprintf(stderr, a_fmt, ap);
136*9781SMoriah.Waterland@Sun.COM 
137*9781SMoriah.Waterland@Sun.COM 		va_end(ap);
138*9781SMoriah.Waterland@Sun.COM 
139*9781SMoriah.Waterland@Sun.COM 		(void) putc('\n', stderr);
140*9781SMoriah.Waterland@Sun.COM 	}
141*9781SMoriah.Waterland@Sun.COM }
142*9781SMoriah.Waterland@Sun.COM 
143*9781SMoriah.Waterland@Sun.COM /*
144*9781SMoriah.Waterland@Sun.COM  * get the "interactive message enabled" flag
145*9781SMoriah.Waterland@Sun.COM  */
146*9781SMoriah.Waterland@Sun.COM 
147*9781SMoriah.Waterland@Sun.COM boolean_t
echoGetFlag(void)148*9781SMoriah.Waterland@Sun.COM echoGetFlag(void) {
149*9781SMoriah.Waterland@Sun.COM 	return (echoFlag);
150*9781SMoriah.Waterland@Sun.COM }
151*9781SMoriah.Waterland@Sun.COM 
152*9781SMoriah.Waterland@Sun.COM /*
153*9781SMoriah.Waterland@Sun.COM  * set the "interactive message enabled" flag
154*9781SMoriah.Waterland@Sun.COM  */
155*9781SMoriah.Waterland@Sun.COM 
156*9781SMoriah.Waterland@Sun.COM boolean_t
echoSetFlag(boolean_t a_echoFlag)157*9781SMoriah.Waterland@Sun.COM echoSetFlag(boolean_t a_echoFlag)
158*9781SMoriah.Waterland@Sun.COM {
159*9781SMoriah.Waterland@Sun.COM 	boolean_t	oldvalue;
160*9781SMoriah.Waterland@Sun.COM 
161*9781SMoriah.Waterland@Sun.COM 	oldvalue = echoFlag;
162*9781SMoriah.Waterland@Sun.COM 	echoFlag = a_echoFlag;
163*9781SMoriah.Waterland@Sun.COM 	return (oldvalue);
164*9781SMoriah.Waterland@Sun.COM }
165*9781SMoriah.Waterland@Sun.COM 
166*9781SMoriah.Waterland@Sun.COM /*
167*9781SMoriah.Waterland@Sun.COM  * get the "debugging message enabled" flag
168*9781SMoriah.Waterland@Sun.COM  */
169*9781SMoriah.Waterland@Sun.COM 
170*9781SMoriah.Waterland@Sun.COM boolean_t
echoDebugGetFlag(void)171*9781SMoriah.Waterland@Sun.COM echoDebugGetFlag(void) {
172*9781SMoriah.Waterland@Sun.COM 	return (debugFlag);
173*9781SMoriah.Waterland@Sun.COM }
174*9781SMoriah.Waterland@Sun.COM 
175*9781SMoriah.Waterland@Sun.COM /*
176*9781SMoriah.Waterland@Sun.COM  * set the "debugging message enabled" flag
177*9781SMoriah.Waterland@Sun.COM  */
178*9781SMoriah.Waterland@Sun.COM 
179*9781SMoriah.Waterland@Sun.COM boolean_t
echoDebugSetFlag(boolean_t a_debugFlag)180*9781SMoriah.Waterland@Sun.COM echoDebugSetFlag(boolean_t a_debugFlag)
181*9781SMoriah.Waterland@Sun.COM {
182*9781SMoriah.Waterland@Sun.COM 	boolean_t	oldvalue;
183*9781SMoriah.Waterland@Sun.COM 
184*9781SMoriah.Waterland@Sun.COM 	oldvalue = debugFlag;
185*9781SMoriah.Waterland@Sun.COM 	debugFlag = a_debugFlag;
186*9781SMoriah.Waterland@Sun.COM 	return (oldvalue);
187*9781SMoriah.Waterland@Sun.COM }
188