1 /* Kernel info for virtual domains.
2 * (C) Copyright 2008-2010 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #define __GNUC_PREREQ(maj,min) 0
30 #define ATTRIBUTE_UNUSED __attribute__((__unused__))
31 #define ATTRIBUTE_FORMAT(args...) __attribute__((__format__ (args)))
32 #define ATTRIBUTE_NORETURN __attribute__((__noreturn__))
33 #define ATTRIBUTE_CONSTRUCTOR __attribute__((__constructor__))
35 #if __GNUC_PREREQ (3, 4)
36 #define ATTRIBUTE_RETURN_CHECK __attribute__((__warn_unused_result__))
38 #define ATTRIBUTE_RETURN_CHECK
42 #define ATTRIBUTE_UNUSED
43 #define ATTRIBUTE_FORMAT(...)
44 #define ATTRIBUTE_NORETURN
45 #error "we must be able to define attribute((constructor)) for this compiler"
46 #define ATTRIBUTE_RETURN_CHECK
51 * PACKAGE (usually the string "virt-kernel-info") should be the same as the
52 * $(DOMAIN) variable declared in po/Makevars.
54 #define _(str) dgettext(PACKAGE, (str))
55 #define N_(str) dgettext(PACKAGE, (str))
57 /* String equality tests, suggested by Jim Meyering. */
58 #define STREQ(a,b) (strcmp((a),(b)) == 0)
59 #define STRCASEEQ(a,b) (strcasecmp((a),(b)) == 0)
60 #define STRNEQ(a,b) (strcmp((a),(b)) != 0)
61 #define STRCASENEQ(a,b) (strcasecmp((a),(b)) != 0)
62 #define STREQLEN(a,b,n) (strncmp((a),(b),(n)) == 0)
63 #define STRCASEEQLEN(a,b,n) (strncasecmp((a),(b),(n)) == 0)
64 #define STRNEQLEN(a,b,n) (strncmp((a),(b),(n)) != 0)
65 #define STRCASENEQLEN(a,b,n) (strncasecmp((a),(b),(n)) != 0)
66 #define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
68 /* Each tool describes itself to the main program by
69 * defining and registering this structure.
71 typedef void (*tool_run_fn) (void); /* XXX */
74 const char *name; /* Tool name, eg. "dmesg" */
76 int external_cmd; /* Is the tool an external command, eg. "virt-dmesg" */
78 const char *summary; /* Tool-specific one line summary. */
79 const char *description; /* Long description. */
81 tool_run_fn run_fn; /* Tool entry point. */
83 /* The main program links tools after they are registered
89 /* Register a tool with the main program. */
90 extern void register_tool (struct tool *me);
92 /* Error printing functions:
94 * error() will print an error and exit. Only use this if the error
95 * really is fatal. NOT usually used inside tools, because they can
96 * be called repeatedly for different domains.
98 * warning() will print a warning message and continue. Use this
99 * inside tools (and return), instead of exiting, because the tool
100 * can be called repeatedly for different domains.
102 * internal_error() is like error() but used for errors that shouldn't
105 * INTERNAL_ERROR is also used for errors which shouldn't happen, but
106 * prints only file and line number.
108 * NOT_IMPL is used to mark functions and code sections which are not
111 * All of these functions append \n after the message.
113 extern void error (const char *fs, ...)
114 ATTRIBUTE_FORMAT(printf, 1, 2) ATTRIBUTE_NORETURN;
115 extern void warning (const char *fs, ...)
116 ATTRIBUTE_FORMAT(printf, 1, 2);
117 extern void internal_error (const char *fs, ...)
118 ATTRIBUTE_FORMAT(printf, 1, 2) ATTRIBUTE_NORETURN;
120 #define INTERNAL_ERROR \
121 internal_error (_("%s:%d: internal error"), \
125 internal_error (_("%s:%d: this feature is not implemented"), \
128 /* Output functions. These handle CSV output automatically, but
129 * must be used with care.
131 * output_heading() is used to write the heading (title) row.
132 * The format string is converted such that any %-sequence which
133 * _isn't_ %s is turned into %s. (So only string fields are
134 * expected in headings).
136 * output_row() is used to write each row of data. The format
137 * string is used directly for non-CSV output, so this is mostly
138 * equivalent to printf(). However for CSV output, the format
139 * string is used to tell the types of each field, other characters
142 * Only fairly simple format strings are understood.
146 * const char *fs = "%-9d %s";
148 * output_heading (fs, _("PID"), _("NAME"));
149 * for (i = 0; i < nr_procs; ++i) {
150 * output_row (fs, proc[i].pid, proc[i].name);
153 * A \n is added automatically after each heading/row.
155 extern void output_heading (const char *fs, ...)
156 /* not ATTRIBUTE_FORMAT */;
157 extern void output_row (const char *fs, ...)
158 ATTRIBUTE_FORMAT(printf, 1, 2);
164 #endif /* INTERNAL_H */