xref: /titanic_50/usr/src/cmd/rcap/common/utils.h (revision d362b7492b8bcb5ed70f92aa0a6a39bc93b059de)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50209230bSgjelinek  * Common Development and Distribution License (the "License").
60209230bSgjelinek  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*d362b749Svk199839  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_UTILS_H
277c478bd9Sstevel@tonic-gate #define	_UTILS_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <assert.h>
327c478bd9Sstevel@tonic-gate #include <libintl.h>
337c478bd9Sstevel@tonic-gate #include <stdarg.h>
347c478bd9Sstevel@tonic-gate #include <time.h>
350209230bSgjelinek #include <libzonecfg.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #define	E_SUCCESS	0		/* Exit status for success */
427c478bd9Sstevel@tonic-gate #define	E_ERROR		1		/* Exit status for error */
437c478bd9Sstevel@tonic-gate #define	E_USAGE		2		/* Exit status for usage error */
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * Message filter levels by priority
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate typedef enum rcm_level {
497c478bd9Sstevel@tonic-gate 	RCM_NONE = 0,			/* No messages */
507c478bd9Sstevel@tonic-gate 	RCM_ERR,			/* Errors only */
517c478bd9Sstevel@tonic-gate 	RCM_WARN,			/* Warnings */
527c478bd9Sstevel@tonic-gate 	RCM_INFO,			/* Information */
537c478bd9Sstevel@tonic-gate 	RCM_DEBUG,			/* Everything */
547c478bd9Sstevel@tonic-gate 	RCM_DEBUG_HIGH			/* Fire hose */
557c478bd9Sstevel@tonic-gate } rcm_level_t;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate  * Message destinations
597c478bd9Sstevel@tonic-gate  */
607c478bd9Sstevel@tonic-gate typedef enum rcm_dst {
617c478bd9Sstevel@tonic-gate 	RCD_STD = 1,			/* Standard output/error, depending */
627c478bd9Sstevel@tonic-gate 					/* on level */
637c478bd9Sstevel@tonic-gate 	RCD_SYSLOG			/* syslog() daemon facility */
647c478bd9Sstevel@tonic-gate } rcm_dst_t;
657c478bd9Sstevel@tonic-gate 
660209230bSgjelinek typedef struct zone_entry {
670209230bSgjelinek 	zoneid_t	zid;
680209230bSgjelinek 	char		zname[ZONENAME_MAX];
690209230bSgjelinek } zone_entry_t;
700209230bSgjelinek 
717c478bd9Sstevel@tonic-gate #define	LINELEN		256		/* max. message length */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #ifdef DEBUG
747c478bd9Sstevel@tonic-gate #undef ASSERT
757c478bd9Sstevel@tonic-gate #define	ASSERT(x)	(assert(x))
767c478bd9Sstevel@tonic-gate #else /* !DEBUG */
777c478bd9Sstevel@tonic-gate #undef ASSERT
787c478bd9Sstevel@tonic-gate #define	ASSERT(x)	((void)0)
797c478bd9Sstevel@tonic-gate #endif /* DEBUG */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #ifdef DEBUG_MSG
827c478bd9Sstevel@tonic-gate extern void debug(char *, ...);
837c478bd9Sstevel@tonic-gate extern void debug_high(char *, ...);
847c478bd9Sstevel@tonic-gate #else /* !DEBUG_MSG */
857c478bd9Sstevel@tonic-gate /*LINTED: static unused*/
867c478bd9Sstevel@tonic-gate static void debug(char *format, ...) /*ARGSUSED*/ {}
877c478bd9Sstevel@tonic-gate /*LINTED: static unused*/
887c478bd9Sstevel@tonic-gate static void debug_high(char *format, ...) /*ARGSUSED*/ {}
897c478bd9Sstevel@tonic-gate #endif /* DEBUG_MSG */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate extern void die(char *, ...);
927c478bd9Sstevel@tonic-gate extern void info(char *, ...);
937c478bd9Sstevel@tonic-gate extern rcm_level_t get_message_priority(void);
947c478bd9Sstevel@tonic-gate extern rcm_level_t set_message_priority(rcm_level_t);
957c478bd9Sstevel@tonic-gate extern rcm_dst_t set_message_destination(rcm_dst_t);
967c478bd9Sstevel@tonic-gate extern char *setprogname(char *);
97*d362b749Svk199839 extern void warn(const char *, ...);
987c478bd9Sstevel@tonic-gate extern int valid_abspath(char *);
99*d362b749Svk199839 extern void vdprintfe(int, const char *, va_list);
1007c478bd9Sstevel@tonic-gate extern void dprintfe(int, char *, ...);
1017c478bd9Sstevel@tonic-gate extern void hrt2ts(hrtime_t, timestruc_t *);
1027c478bd9Sstevel@tonic-gate extern int xatoi(char *);
1030209230bSgjelinek extern int get_running_zones(uint_t *, zone_entry_t **);
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1067c478bd9Sstevel@tonic-gate }
1077c478bd9Sstevel@tonic-gate #endif
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate #endif	/* _UTILS_H */
110