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