[PATCH] format: Remove unimplemented virt-format -c, -d and -q options.
by Richard W.M. Jones
These options just give errors because they appear in the short
options list but not in the case statement.
---
format/format.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/format/format.c b/format/format.c
index 5026aff..2dbaa4d 100644
--- a/format/format.c
+++ b/format/format.c
@@ -104,7 +104,7 @@ main (int argc, char *argv[])
enum { HELP_OPTION = CHAR_MAX + 1 };
- static const char *options = "a:c:d:qvVx";
+ static const char *options = "a:vVx";
static const struct option long_options[] = {
{ "add", 1, 0, 'a' },
{ "filesystem", 1, 0, 0 },
--
2.7.4
8 years, 5 months
[PATCH 1/2] build: Fix dependencies on mllib and customize.
by Richard W.M. Jones
Binaries should be rebuilt if mllib.cma/mllib.cmxa or
customize.cma/customize.cmxa change.
Fixes commit 1e2877c6f4d1d254026d38b1cac4895d8dba7d5d.
---
builder/Makefile.am | 12 ++++++++++--
customize/Makefile.am | 3 ++-
dib/Makefile.am | 5 ++++-
get-kernel/Makefile.am | 5 ++++-
mllib/Makefile.am | 15 ++++++++++++---
resize/Makefile.am | 5 ++++-
sparsify/Makefile.am | 6 ++++--
subdir-rules.mk | 6 ++++++
sysprep/Makefile.am | 6 +++++-
v2v/Makefile.am | 9 +++++++--
10 files changed, 58 insertions(+), 14 deletions(-)
diff --git a/builder/Makefile.am b/builder/Makefile.am
index 4e77f52..b2d5ad3 100644
--- a/builder/Makefile.am
+++ b/builder/Makefile.am
@@ -167,7 +167,11 @@ BEST = opt
OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa customize.cmxa
endif
-virt_builder_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh
+virt_builder_DEPENDENCIES = \
+ $(OBJECTS) \
+ ../mllib/mllib.$(MLARCHIVE) \
+ ../customize/customize.$(MLARCHIVE) \
+ $(top_srcdir)/ocaml-link.sh
virt_builder_LINK = \
$(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLLINKFLAGS) \
@@ -236,7 +240,11 @@ yajl_tests_THEOBJECTS = $(yajl_tests_BOBJECTS)
yajl_tests.cmo: OCAMLPACKAGES += $(OCAMLPACKAGES_TESTS)
endif
-yajl_tests_DEPENDENCIES = $(yajl_tests_THEOBJECTS) $(top_srcdir)/ocaml-link.sh
+yajl_tests_DEPENDENCIES = \
+ $(yajl_tests_THEOBJECTS) \
+ ../mllib/mllib.$(MLARCHIVE) \
+ ../customize/customize.$(MLARCHIVE) \
+ $(top_srcdir)/ocaml-link.sh
yajl_tests_LINK = \
$(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLPACKAGES_TESTS) $(OCAMLLINKFLAGS) \
diff --git a/customize/Makefile.am b/customize/Makefile.am
index 4befc75..dd35cdc 100644
--- a/customize/Makefile.am
+++ b/customize/Makefile.am
@@ -165,7 +165,8 @@ OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_ERROR)
virt_customize_DEPENDENCIES = \
$(top_srcdir)/ocaml-link.sh \
$(CUSTOMIZE_THEOBJECTS) \
- $(CUSTOMIZE_CMA)
+ $(CUSTOMIZE_CMA) \
+ ../mllib/mllib.$(MLARCHIVE)
virt_customize_LINK = \
$(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLLINKFLAGS) \
diff --git a/dib/Makefile.am b/dib/Makefile.am
index 4cf052f..a57d89d 100644
--- a/dib/Makefile.am
+++ b/dib/Makefile.am
@@ -89,7 +89,10 @@ BEST = opt
OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa
endif
-virt_dib_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh
+virt_dib_DEPENDENCIES = \
+ $(OBJECTS) \
+ ../mllib/mllib.$(MLARCHIVE) \
+ $(top_srcdir)/ocaml-link.sh
virt_dib_LINK = \
$(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLLINKFLAGS) \
diff --git a/get-kernel/Makefile.am b/get-kernel/Makefile.am
index 2ad3ad0..e145972 100644
--- a/get-kernel/Makefile.am
+++ b/get-kernel/Makefile.am
@@ -86,7 +86,10 @@ BEST = opt
OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa
endif
-virt_get_kernel_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh
+virt_get_kernel_DEPENDENCIES = \
+ $(OBJECTS) \
+ ../mllib/mllib.$(MLARCHIVE) \
+ $(top_srcdir)/ocaml-link.sh
virt_get_kernel_LINK = \
$(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLLINKFLAGS) \
diff --git a/mllib/Makefile.am b/mllib/Makefile.am
index dc36f26..8a02c1f 100644
--- a/mllib/Makefile.am
+++ b/mllib/Makefile.am
@@ -202,21 +202,30 @@ BEST = opt
OCAMLLINKFLAGS = mlguestfs.cmxa
endif
-common_utils_tests_DEPENDENCIES = $(common_utils_tests_THEOBJECTS) $(top_srcdir)/ocaml-link.sh
+common_utils_tests_DEPENDENCIES = \
+ $(common_utils_tests_THEOBJECTS) \
+ $(MLLIB_CMA) \
+ $(top_srcdir)/ocaml-link.sh
common_utils_tests_LINK = \
$(top_srcdir)/ocaml-link.sh -cclib '-lutils $(LIBXML2_LIBS) -lgnu' -- \
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLLINKFLAGS) \
$(OCAMLPACKAGES) $(OCAMLPACKAGES_TESTS) \
$(common_utils_tests_THEOBJECTS) -o $@
-getopt_tests_DEPENDENCIES = $(getopt_tests_THEOBJECTS) $(top_srcdir)/ocaml-link.sh
+getopt_tests_DEPENDENCIES = \
+ $(getopt_tests_THEOBJECTS) \
+ $(MLLIB_CMA) \
+ $(top_srcdir)/ocaml-link.sh
getopt_tests_LINK = \
$(top_srcdir)/ocaml-link.sh -cclib '-lutils $(LIBXML2_LIBS) -lgnu' -- \
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLLINKFLAGS) \
$(OCAMLPACKAGES) $(OCAMLPACKAGES_TESTS) \
$(getopt_tests_THEOBJECTS) -o $@
-JSON_tests_DEPENDENCIES = $(JSON_tests_THEOBJECTS) $(top_srcdir)/ocaml-link.sh
+JSON_tests_DEPENDENCIES = \
+ $(JSON_tests_THEOBJECTS) \
+ $(MLLIB_CMA) \
+ $(top_srcdir)/ocaml-link.sh
JSON_tests_LINK = \
$(top_srcdir)/ocaml-link.sh -- \
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLLINKFLAGS) \
diff --git a/resize/Makefile.am b/resize/Makefile.am
index 20d264b..96604b6 100644
--- a/resize/Makefile.am
+++ b/resize/Makefile.am
@@ -83,7 +83,10 @@ BEST = opt
OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa
endif
-virt_resize_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh
+virt_resize_DEPENDENCIES = \
+ $(OBJECTS) \
+ ../mllib/mllib.$(MLARCHIVE) \
+ $(top_srcdir)/ocaml-link.sh
virt_resize_LINK = \
$(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLLINKFLAGS) \
diff --git a/sparsify/Makefile.am b/sparsify/Makefile.am
index 5c03394..847825a 100644
--- a/sparsify/Makefile.am
+++ b/sparsify/Makefile.am
@@ -87,8 +87,10 @@ BEST = opt
OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa
endif
-virt_sparsify_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh
-
+virt_sparsify_DEPENDENCIES = \
+ $(OBJECTS) \
+ ../mllib/mllib.$(MLARCHIVE) \
+ $(top_srcdir)/ocaml-link.sh
virt_sparsify_LINK = \
$(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLLINKFLAGS) \
diff --git a/subdir-rules.mk b/subdir-rules.mk
index dd59349..525d210 100644
--- a/subdir-rules.mk
+++ b/subdir-rules.mk
@@ -47,6 +47,12 @@ LOG_DRIVER = env $(SHELL) $(top_srcdir)/build-aux/guestfs-test-driver
# See also:
# guestfs-hacking(1) section "HOW OCAML PROGRAMS ARE COMPILED AND LINKED"
+if !HAVE_OCAMLOPT
+MLARCHIVE = cma
+else
+MLARCHIVE = cmxa
+endif
+
.mli.cmi:
$(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
.ml.cmo:
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
index 25193b2..1504df2 100644
--- a/sysprep/Makefile.am
+++ b/sysprep/Makefile.am
@@ -135,7 +135,11 @@ BEST = opt
OCAMLLINKFLAGS = mlguestfs.cmxa mllib.cmxa customize.cmxa
endif
-virt_sysprep_DEPENDENCIES = $(OBJECTS) $(top_srcdir)/ocaml-link.sh
+virt_sysprep_DEPENDENCIES = \
+ $(OBJECTS) \
+ ../mllib/mllib.$(MLARCHIVE) \
+ ../customize/customize.$(MLARCHIVE) \
+ $(top_srcdir)/ocaml-link.sh
virt_sysprep_LINK = \
$(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLLINKFLAGS) \
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index d5d4c04..988cba5 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -189,7 +189,9 @@ COPY_TO_LOCAL_OBJECTS = $(COPY_TO_LOCAL_XOBJECTS)
endif
virt_v2v_copy_to_local_DEPENDENCIES = \
- $(COPY_TO_LOCAL_OBJECTS) $(top_srcdir)/ocaml-link.sh
+ $(COPY_TO_LOCAL_OBJECTS) \
+ ../mllib/mllib.$(MLARCHIVE) \
+ $(top_srcdir)/ocaml-link.sh
virt_v2v_copy_to_local_LINK = \
$(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLPACKAGES) $(OCAMLLINKFLAGS) \
@@ -405,7 +407,10 @@ v2v_unit_tests_THEOBJECTS = $(v2v_unit_tests_XOBJECTS)
v2v_unit_tests.cmx: OCAMLPACKAGES += -package oUnit
endif
-v2v_unit_tests_DEPENDENCIES = $(v2v_unit_tests_THEOBJECTS) $(top_srcdir)/ocaml-link.sh
+v2v_unit_tests_DEPENDENCIES = \
+ $(v2v_unit_tests_THEOBJECTS) \
+ ../mllib/mllib.$(MLARCHIVE) \
+ $(top_srcdir)/ocaml-link.sh
v2v_unit_tests_LINK = \
$(top_srcdir)/ocaml-link.sh -cclib '$(OCAMLCLIBS)' -- \
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) \
--
2.7.4
8 years, 5 months
[PATCH 1/3] mllib: Getopt: point to man page as additional help
by Pino Toscano
On error, point also to the man page of the current tool in addition to
'$TOOL --help'.
---
mllib/getopt-c.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mllib/getopt-c.c b/mllib/getopt-c.c
index bf40f91..3efd5d3 100644
--- a/mllib/getopt-c.c
+++ b/mllib/getopt-c.c
@@ -69,8 +69,8 @@ cleanup_option_list (void *ptr)
static void __attribute__((noreturn))
show_error (int status)
{
- fprintf (stderr, _("Try `%s --help' for more information.\n"),
- guestfs_int_program_name);
+ fprintf (stderr, _("Try `%s --help' or consult %s(1) for more information.\n"),
+ guestfs_int_program_name, guestfs_int_program_name);
exit (status);
}
--
2.7.4
8 years, 5 months
[PATCH v1 INCOMPLETE] tests: Implement script to check documented tool options match actual options.
by Richard W.M. Jones
pod-arg-check.pl is run as part of the tests to ensure the
documentation matches the options that the tool implements and vice
versa.
This commit includes scripts to run the tests and various fixes to the
manual pages to ensure that the tests pass.
---
cat/Makefile.am | 5 +-
cat/test-docs.sh | 26 ++++++++
cat/virt-cat.pod | 4 +-
cat/virt-ls.pod | 4 +-
df/Makefile.am | 3 +-
df/test-virt-df-docs.sh | 22 +++++++
df/virt-df.pod | 10 ++--
pod-arg-check.pl | 155 ++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 218 insertions(+), 11 deletions(-)
create mode 100755 cat/test-docs.sh
create mode 100755 df/test-virt-df-docs.sh
create mode 100755 pod-arg-check.pl
diff --git a/cat/Makefile.am b/cat/Makefile.am
index 1a3482b..a831fa4 100644
--- a/cat/Makefile.am
+++ b/cat/Makefile.am
@@ -201,8 +201,11 @@ stamp-virt-ls.pod: virt-ls.pod
TESTS_ENVIRONMENT = $(top_builddir)/run --test
-if ENABLE_APPLIANCE
TESTS = \
+ test-docs.sh
+
+if ENABLE_APPLIANCE
+TESTS += \
test-virt-cat.sh \
test-virt-filesystems.sh \
test-virt-log.sh \
diff --git a/cat/test-docs.sh b/cat/test-docs.sh
new file mode 100755
index 0000000..dea7362
--- /dev/null
+++ b/cat/test-docs.sh
@@ -0,0 +1,26 @@
+#!/bin/bash -
+# libguestfs
+# Copyright (C) 2016 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+export LANG=C
+set -e
+
+$srcdir/../pod-arg-check.pl virt-cat.pod virt-cat
+$srcdir/../pod-arg-check.pl virt-filesystems.pod virt-filesystems
+$srcdir/../pod-arg-check.pl virt-log.pod virt-log
+$srcdir/../pod-arg-check.pl virt-ls.pod virt-ls \
+ -ignore=--checksums,--extra-stat,--time,--uid
diff --git a/cat/virt-cat.pod b/cat/virt-cat.pod
index acd43e0..87b0e13 100644
--- a/cat/virt-cat.pod
+++ b/cat/virt-cat.pod
@@ -126,9 +126,9 @@ security problem with malicious guests (CVE-2010-3851).
Read key or passphrase parameters from stdin. The default is
to try to read passphrases from the user by opening F</dev/tty>.
-=item B<-m dev[:mountpoint[:options[:fstype]]]>
+=item B<-m> dev[:mountpoint[:options[:fstype]]]
-=item B<--mount dev[:mountpoint[:options[:fstype]]]>
+=item B<--mount> dev[:mountpoint[:options[:fstype]]]
Mount the named partition or logical volume on the given mountpoint.
diff --git a/cat/virt-ls.pod b/cat/virt-ls.pod
index b90fb51..4957075 100644
--- a/cat/virt-ls.pod
+++ b/cat/virt-ls.pod
@@ -357,9 +357,9 @@ L</RECURSIVE LONG LISTING> above.
Read key or passphrase parameters from stdin. The default is
to try to read passphrases from the user by opening F</dev/tty>.
-=item B<-m dev[:mountpoint[:options[:fstype]]]>
+=item B<-m> dev[:mountpoint[:options[:fstype]]]
-=item B<--mount dev[:mountpoint[:options[:fstype]]]>
+=item B<--mount> dev[:mountpoint[:options[:fstype]]]
Mount the named partition or logical volume on the given mountpoint.
diff --git a/df/Makefile.am b/df/Makefile.am
index 2cf487d..3919397 100644
--- a/df/Makefile.am
+++ b/df/Makefile.am
@@ -95,7 +95,8 @@ stamp-virt-df.pod: virt-df.pod
TESTS_ENVIRONMENT = $(top_builddir)/run --test
-TESTS =
+TESTS = \
+ test-virt-df-docs.sh
if ENABLE_APPLIANCE
TESTS += \
diff --git a/df/test-virt-df-docs.sh b/df/test-virt-df-docs.sh
new file mode 100755
index 0000000..aabe8d8
--- /dev/null
+++ b/df/test-virt-df-docs.sh
@@ -0,0 +1,22 @@
+#!/bin/bash -
+# libguestfs
+# Copyright (C) 2016 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+export LANG=C
+set -e
+
+$srcdir/../pod-arg-check.pl virt-df.pod virt-df
diff --git a/df/virt-df.pod b/df/virt-df.pod
index 6419237..57f9fd0 100644
--- a/df/virt-df.pod
+++ b/df/virt-df.pod
@@ -76,20 +76,20 @@ not do this with unrelated guest disks.>
Display brief help.
-=item B<-a> file
+=item B<-a> FILE
-=item B<--add> file
+=item B<--add> FILE
-Add I<file> which should be a disk image from a virtual machine. If
+Add C<FILE> which should be a disk image from a virtual machine. If
the virtual machine has multiple block devices, you must supply all of
them with separate I<-a> options.
The format of the disk image is auto-detected. To override this and
force a particular format use the I<--format=..> option.
-=item B<-a URI>
+=item B<-a> URI
-=item B<--add URI>
+=item B<--add> URI
Add a remote disk. See L<guestfish(1)/ADDING REMOTE STORAGE>.
diff --git a/pod-arg-check.pl b/pod-arg-check.pl
new file mode 100755
index 0000000..3e9680b
--- /dev/null
+++ b/pod-arg-check.pl
@@ -0,0 +1,155 @@
+#!/usr/bin/env perl
+# pod-arg-check.pl
+# Copyright (C) 2016 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use warnings;
+use strict;
+
+use Pod::Usage;
+use Getopt::Long;
+use Pod::Man;
+
+=head1 NAME
+
+pod-arg-check.pl - Compare man page and tools to check all arguments are documented
+
+=head1 SYNOPSIS
+
+ pod-arg-check.pl virt-foo.pod ./virt-foo [--ignore=--arg,--arg,...]
+
+=head1 DESCRIPTION
+
+This script compares a manual page (eg. C<virt-foo.pod>) and the
+corresponding tool (eg. C<./virt-foo>) and checks that each command
+line argument is documented in the manual, and that there is no rogue
+documentation for arguments which do not exist. It works by running
+the tool with the standard C<--long-options> and C<--short-options>
+parameters and comparing their output with the man page.
+
+You can also ignore options, in case this script gets things wrong or
+if there are options that you don't intend to document.
+
+=head1 OPTIONS
+
+=over 4
+
+=cut
+
+my $help;
+
+=item B<--help>
+
+Display brief help.
+
+=cut
+
+my $ignore = "";
+
+=item B<--ignore=--arg,--arg,...>
+
+Ignore the comma-separated list of arguments given.
+
+=cut
+
+# Clean up the program name.
+my $progname = $0;
+$progname =~ s{.*/}{};
+
+# Parse options.
+GetOptions ("help|?" => \$help,
+ "ignore=s" => \$ignore,
+ ) or pod2usage (2);
+pod2usage (1) if $help;
+
+die "$progname: missing argument: pod-arg-check.pl input.pod tool\n"
+ unless @ARGV == 2;
+my $pod = $ARGV[0];
+my $tool = $ARGV[1];
+
+my %ignore = ();
+$ignore{$_} = 1 foreach (split /,/, $ignore);
+
+# Open the man page and slurp it in.
+my $pod_content = "";
+open MAN, $pod or die "$progname: $pod: $!";
+{
+ local $/ = undef;
+ $pod_content = <MAN>;
+}
+close MAN;
+
+# Run the tool with --long-options and --short-options.
+my @tool_options = ();
+open PIPE, "$tool --long-options |"
+ or die "$progname: $tool --long-options: $!";
+while (<PIPE>) {
+ chomp;
+ push @tool_options, $_;
+}
+close PIPE;
+open PIPE, "$tool --short-options |"
+ or die "$progname: $tool --short-options: $!";
+while (<PIPE>) {
+ chomp;
+ push @tool_options, $_;
+}
+close PIPE;
+
+my %tool_option_exists = ();
+$tool_option_exists{$_} = 1 foreach @tool_options;
+
+# Check each option exists in the manual.
+my $tool_options_checked = 0;
+
+foreach (sort keys %tool_option_exists) {
+ unless ($ignore{$_}) {
+ $tool_options_checked++;
+ die "$progname: $pod does not define $_\n"
+ unless $pod_content =~ /^=item B<$_>/m;
+ }
+}
+
+# Check there are no extra options defined in the manual which
+# don't exist in the tool.
+my $pod_options_checked = 0;
+
+my %pod_options = ();
+$pod_options{$_} = 1 foreach ( $pod_content =~ /^=item B<(-[-\w]+)>/gm );
+foreach (sort keys %pod_options) {
+ unless ($ignore{$_}) {
+ $pod_options_checked++;
+ die "$progname: $pod defines option $_ which does not exist in the tool\n"
+ unless exists $tool_option_exists{$_};
+ }
+}
+
+printf "$progname: $tool: checked $tool_options_checked tool options against $pod_options_checked documented options\n";
+
+exit 0;
+
+=head1 SEE ALSO
+
+L<podwrapper(1)>,
+libguestfs.git/README.
+
+=head1 AUTHOR
+
+Richard W.M. Jones.
+
+=head1 COPYRIGHT
+
+Copyright (C) 2016 Red Hat Inc.
--
2.7.4
8 years, 5 months
[PATCH] mllib: Getopt: fix integer parsing
by Pino Toscano
Since we are using gnulib already, make use of xstrtol to parse the
integer arguments to avoid extra suffixes, etc.
Fixes commit 0f7bf8f714898c606e5d5015fff5b7803dcd1aee.
---
mllib/getopt-c.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/mllib/getopt-c.c b/mllib/getopt-c.c
index 1f129a7..2d3f9b6 100644
--- a/mllib/getopt-c.c
+++ b/mllib/getopt-c.c
@@ -30,6 +30,8 @@
#include <error.h>
#include <assert.h>
+#include "xstrtol.h"
+
#include <caml/alloc.h>
#include <caml/fail.h>
#include <caml/memory.h>
@@ -117,6 +119,26 @@ do_call1 (value funv, value paramv)
CAMLreturn0;
}
+static int
+strtoint (const char *arg)
+{
+ long int num;
+
+ if (xstrtol (arg, NULL, 0, &num, NULL) != LONGINT_OK) {
+ fprintf (stderr, _("%s: '%s' is not a numeric value.\n"),
+ guestfs_int_program_name, arg);
+ show_error (EXIT_FAILURE);
+ }
+
+ if (num <= INT_MIN || num >= INT_MAX) {
+ fprintf (stderr, _("%s: %s: integer out of range\n"),
+ guestfs_int_program_name, arg);
+ show_error (EXIT_FAILURE);
+ }
+
+ return (int) num;
+}
+
value
guestfs_int_mllib_getopt_parse (value argsv, value specsv, value anon_funv, value usage_msgv)
{
@@ -274,21 +296,13 @@ guestfs_int_mllib_getopt_parse (value argsv, value specsv, value anon_funv, valu
break;
case 5: /* Int of string * (int -> unit) */
- if (sscanf (optarg, "%d", &num) != 1) {
- fprintf (stderr, _("'%s' is not a numeric value.\n"),
- guestfs_int_program_name);
- show_error (EXIT_FAILURE);
- }
+ num = strtoint (optarg);
v = Field (actionv, 1);
do_call1 (v, Val_int (num));
break;
case 6: /* Set_int of string * int ref */
- if (sscanf (optarg, "%d", &num) != 1) {
- fprintf (stderr, _("'%s' is not a numeric value.\n"),
- guestfs_int_program_name);
- show_error (EXIT_FAILURE);
- }
+ num = strtoint (optarg);
caml_modify (&Field (Field (actionv, 1), 0), Val_int (num));
break;
--
2.7.4
8 years, 5 months