xref: /titanic_51/usr/src/cmd/rcap/common/utils.h (revision 853389e344087efe23a5cc688693e5301a1cb90d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_UTILS_H
27 #define	_UTILS_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <assert.h>
32 #include <libintl.h>
33 #include <stdarg.h>
34 #include <time.h>
35 #include <libzonecfg.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #define	E_SUCCESS	0		/* Exit status for success */
42 #define	E_ERROR		1		/* Exit status for error */
43 #define	E_USAGE		2		/* Exit status for usage error */
44 
45 /*
46  * Message filter levels by priority
47  */
48 typedef enum rcm_level {
49 	RCM_NONE = 0,			/* No messages */
50 	RCM_ERR,			/* Errors only */
51 	RCM_WARN,			/* Warnings */
52 	RCM_INFO,			/* Information */
53 	RCM_DEBUG,			/* Everything */
54 	RCM_DEBUG_HIGH			/* Fire hose */
55 } rcm_level_t;
56 
57 /*
58  * Message destinations
59  */
60 typedef enum rcm_dst {
61 	RCD_STD = 1,			/* Standard output/error, depending */
62 					/* on level */
63 	RCD_SYSLOG			/* syslog() daemon facility */
64 } rcm_dst_t;
65 
66 typedef struct zone_entry {
67 	zoneid_t	zid;
68 	char		zname[ZONENAME_MAX];
69 } zone_entry_t;
70 
71 #define	LINELEN		256		/* max. message length */
72 
73 #ifdef DEBUG
74 #undef ASSERT
75 #define	ASSERT(x)	(assert(x))
76 #else /* !DEBUG */
77 #undef ASSERT
78 #define	ASSERT(x)	((void)0)
79 #endif /* DEBUG */
80 
81 #ifdef DEBUG_MSG
82 extern void debug(char *, ...);
83 extern void debug_high(char *, ...);
84 #else /* !DEBUG_MSG */
85 /*LINTED: static unused*/
86 static void debug(char *format, ...) /*ARGSUSED*/ {}
87 /*LINTED: static unused*/
88 static void debug_high(char *format, ...) /*ARGSUSED*/ {}
89 #endif /* DEBUG_MSG */
90 
91 extern void die(char *, ...);
92 extern void info(char *, ...);
93 extern rcm_level_t get_message_priority(void);
94 extern rcm_level_t set_message_priority(rcm_level_t);
95 extern rcm_dst_t set_message_destination(rcm_dst_t);
96 extern char *setprogname(char *);
97 extern void warn(const char *, ...);
98 extern int valid_abspath(char *);
99 extern void vdprintfe(int, const char *, va_list);
100 extern void dprintfe(int, char *, ...);
101 extern void hrt2ts(hrtime_t, timestruc_t *);
102 extern int xatoi(char *);
103 extern int get_running_zones(uint_t *, zone_entry_t **);
104 
105 #ifdef	__cplusplus
106 }
107 #endif
108 
109 #endif	/* _UTILS_H */
110