Handle the HUGETLB_VERBOSE and HUGETLB_DEBUG flags such that we will emit
messages at the same levels as defined for the library. Use the common
header to define the levels. Convert all existing errors to use the new
macros.
Signed-off-by: Andy Whitcroft <[EMAIL PROTECTED]>
Acked-by: Mel Gorman <[EMAIL PROTECTED]>
Acked-by: Adam Litke <[EMAIL PROTECTED]>
Acked-by: Eric B Munson <[EMAIL PROTECTED]>
---
hugectl.c | 29 +++++++++++++++++++++++++++--
1 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/hugectl.c b/hugectl.c
index 8ba794c..ffbd260 100644
--- a/hugectl.c
+++ b/hugectl.c
@@ -36,6 +36,15 @@
#include <unistd.h>
#include <getopt.h>
+#define REPORT(level, prefix, format, ...) \
+ do { \
+ if (verbose_level >= level) \
+ fprintf(stderr, "hugectl: " prefix ": " format, \
+ ##__VA_ARGS__); \
+ } while (0);
+
+#include "libhugetlbfs_debug.h"
+
extern int errno;
extern int optind;
extern char *optarg;
@@ -51,6 +60,20 @@ void print_usage()
OPTION("--help, -h", "Prints this message");
}
+int verbose_level = VERBOSITY_DEFAULT;
+
+void verbose_init(void)
+{
+ char *env;
+
+ env = getenv("HUGETLB_VERBOSE");
+ if (env)
+ verbose_level = atoi(env);
+ env = getenv("HUGETLB_DEBUG");
+ if (env)
+ verbose_level = VERBOSITY_MAX;
+}
+
int main(int argc, char** argv)
{
char opts[] = "+h";
@@ -60,6 +83,8 @@ int main(int argc, char** argv)
{0},
};
+ verbose_init();
+
while (ret != -1) {
ret = getopt_long(argc, argv, opts, long_opts, &index);
switch (ret) {
@@ -72,7 +97,7 @@ int main(int argc, char** argv)
exit(EXIT_SUCCESS);
default:
- fprintf(stderr, "unparsed option %08x\n", ret);
+ WARNING("unparsed option %08x\n", ret);
ret = -1;
break;
}
@@ -85,6 +110,6 @@ int main(int argc, char** argv)
}
execvp(argv[index], &argv[index]);
- fprintf(stderr, "Error calling execvp: '%s'\n", strerror(errno));
+ ERROR("exec failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
--
1.5.6.GIT
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Libhugetlbfs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel