diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-05-05 14:55:03 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-05-05 14:55:03 +0100 |
commit | dd23234f730db7add330bd06f87cab1f08654747 (patch) | |
tree | 6bfcfe6bb49e621d25816b0354d442c6562615d3 /test-tool | |
parent | 3ea36903f26d5a235ec5a20219173e4a16c8ca95 (diff) | |
download | libguestfs-dd23234f730db7add330bd06f87cab1f08654747.tar.gz libguestfs-dd23234f730db7add330bd06f87cab1f08654747.tar.xz libguestfs-dd23234f730db7add330bd06f87cab1f08654747.zip |
test-tool: Implement -V / --version option.
Diffstat (limited to 'test-tool')
-rw-r--r-- | test-tool/libguestfs-test-tool.pod | 6 | ||||
-rw-r--r-- | test-tool/test-tool.c | 46 |
2 files changed, 34 insertions, 18 deletions
diff --git a/test-tool/libguestfs-test-tool.pod b/test-tool/libguestfs-test-tool.pod index c1efb59c..be405cd9 100644 --- a/test-tool/libguestfs-test-tool.pod +++ b/test-tool/libguestfs-test-tool.pod @@ -58,6 +58,12 @@ directory to try it. Set the launch timeout to C<N> seconds. The default is 600 seconds (10 minutes) which does not usually need to be adjusted. +=item B<-V> + +=item B<--version> + +Display the libguestfs version number and exit. + =back =head1 TRYING OUT A DIFFERENT VERSION OF QEMU diff --git a/test-tool/test-tool.c b/test-tool/test-tool.c index 91093d84..f0e3a314 100644 --- a/test-tool/test-tool.c +++ b/test-tool/test-tool.c @@ -74,6 +74,8 @@ usage (void) " --qemu qemu Specify QEMU binary\n" " --timeout n\n" " -t n Set launch timeout (default: %d seconds)\n" + " --version\n" + " -V Display libguestfs version and exit\n" ), DEFAULT_TIMEOUT); } @@ -87,12 +89,13 @@ main (int argc, char *argv[]) bindtextdomain (PACKAGE, LOCALEBASEDIR); textdomain (PACKAGE); - static const char *options = "t:?"; + static const char *options = "t:V?"; static const struct option long_options[] = { { "help", 0, 0, '?' }, { "qemu", 1, 0, 0 }, { "qemudir", 1, 0, 0 }, { "timeout", 1, 0, 't' }, + { "version", 0, 0, 'V' }, { 0, 0, 0, 0 } }; int c; @@ -101,6 +104,20 @@ main (int argc, char *argv[]) struct guestfs_version *vers; char *p; + /* Create the handle. */ + g = guestfs_create (); + if (g == NULL) { + fprintf (stderr, + _("libguestfs-test-tool: failed to create libguestfs handle\n")); + exit (EXIT_FAILURE); + } + guestfs_set_verbose (g, 1); + vers = guestfs_version (g); + if (vers == NULL) { + fprintf (stderr, _("libguestfs-test-tool: guestfs_version failed\n")); + exit (EXIT_FAILURE); + } + for (;;) { c = getopt_long (argc, argv, options, long_options, &option_index); if (c == -1) break; @@ -128,6 +145,13 @@ main (int argc, char *argv[]) } break; + case 'V': + printf ("%s %"PRIi64".%"PRIi64".%"PRIi64"%s\n", + "libguestfs-test-tool", + vers->major, vers->minor, vers->release, vers->extra); + guestfs_set_verbose (g, 0); + exit (EXIT_SUCCESS); + case '?': usage (); exit (EXIT_SUCCESS); @@ -144,9 +168,6 @@ main (int argc, char *argv[]) printf ("===== Test starts here =====\n"); - /* Must set LIBGUESTFS_DEBUG=1 */ - setenv ("LIBGUESTFS_DEBUG", "1", 1); - /* Print out any environment variables which may relate to this test. */ for (i = 0; environ[i] != NULL; ++i) if (STREQLEN (environ[i], "LIBGUESTFS_", 11)) @@ -156,13 +177,7 @@ main (int argc, char *argv[]) printf ("%s\n", environ[i]); printf ("TMPDIR=%s\n", getenv ("TMPDIR") ? : "(not set)"); - /* Create the handle and configure it. */ - g = guestfs_create (); - if (g == NULL) { - fprintf (stderr, - _("libguestfs-test-tool: failed to create libguestfs handle\n")); - exit (EXIT_FAILURE); - } + /* Configure the handle. */ if (guestfs_add_drive_opts (g, tmpf, GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw", -1) == -1) { @@ -173,11 +188,6 @@ main (int argc, char *argv[]) } /* Print any version info etc. */ - vers = guestfs_version (g); - if (vers == NULL) { - fprintf (stderr, _("libguestfs-test-tool: guestfs_version failed\n")); - exit (EXIT_FAILURE); - } printf ("library version: %"PRIi64".%"PRIi64".%"PRIi64"%s\n", vers->major, vers->minor, vers->release, vers->extra); guestfs_free_version (vers); @@ -287,7 +297,7 @@ set_qemu (const char *path, int use_wrapper) exit (EXIT_FAILURE); } - setenv ("LIBGUESTFS_QEMU", path, 1); + guestfs_set_qemu (g, path); return; } @@ -328,7 +338,7 @@ set_qemu (const char *path, int use_wrapper) fclose (fp); - setenv ("LIBGUESTFS_QEMU", qemuwrapper, 1); + guestfs_set_qemu (g, qemuwrapper); atexit (cleanup_wrapper); } |