[PATCH libguestfs] guestfish: detect a few more failed syscalls
by Jim Meyering
There were a few unchecked syscalls in fish.c
>From ba8b8b0684a03b6e6fbb939ed7e1cbf5e1000092 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Wed, 19 Aug 2009 10:01:07 +0200
Subject: [PATCH libguestfs] guestfish: detect a few more failed syscalls
* fish/fish.c (issue_command): Detect/diagnose more failed syscalls.
---
fish/fish.c | 26 +++++++++++++++++++++-----
1 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/fish/fish.c b/fish/fish.c
index 830617b..e6cd270 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -750,8 +750,14 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd)
if (pipecmd) {
int fd[2];
- fflush (stdout);
- pipe (fd);
+ if (fflush (stdout)); {
+ perror ("failed to flush standard output");
+ return -1;
+ }
+ if (pipe (fd)) {
+ perror ("pipe failed");
+ return -1;
+ }
pid = fork ();
if (pid == -1) {
perror ("fork");
@@ -760,7 +766,10 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd)
if (pid == 0) { /* Child process. */
close (fd[1]);
- dup2 (fd[0], 0);
+ if (dup2 (fd[0], 0) < 0) {
+ perror ("dup2 of stdin failed");
+ _exit (1);
+ }
r = system (pipecmd);
if (r == -1) {
@@ -770,9 +779,16 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd)
_exit (WEXITSTATUS (r));
}
- stdout_saved_fd = dup (1);
+ if ((stdout_saved_fd = dup (1)) < 0) {
+ perror ("failed to dup stdout");
+ return -1;
+ }
close (fd[0]);
- dup2 (fd[1], 1);
+ if (dup2 (fd[1], 1)) {
+ perror ("failed to dup stdout");
+ close (stdout_saved_fd);
+ return -1;
+ }
close (fd[1]);
}
--
1.6.4.378.g88f2f
15 years, 4 months
[PATCH] Add boot/grub_fs to output
by Matthew Booth
If present, this gives the mount point of the filesystem which contains grub.
All entries in grub.conf will be relative to this filesystem.
---
perl/lib/Sys/Guestfs/Lib.pm | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/perl/lib/Sys/Guestfs/Lib.pm b/perl/lib/Sys/Guestfs/Lib.pm
index 89f2aa6..1f84bc6 100644
--- a/perl/lib/Sys/Guestfs/Lib.pm
+++ b/perl/lib/Sys/Guestfs/Lib.pm
@@ -1330,7 +1330,11 @@ The kernel command line.
=item default
-The index of the default configuration in the configs array
+The index of the default configuration in the configs array.
+
+=item grub_fs
+
+The path of the filesystem containing the grub partition.
=back
@@ -1506,6 +1510,7 @@ sub _check_for_kernels
# ->{cmdline} = "ro root=/dev/mapper/vg_mbooth-lv_root rhgb"
# ->{initrd} = \initrd
# ->{default} = \config
+ # ->{grub_fs} = "/boot"
# Initialise augeas
$g->aug_init("/", 16);
@@ -1576,6 +1581,7 @@ sub _check_for_kernels
# Create the top level boot entry
my %boot;
$boot{configs} = \@configs;
+ $boot{grub_fs} = $grub;
# Add the default configuration
eval {
--
1.6.2.5
15 years, 4 months
src/ is now warning-free, too
by Jim Meyering
These patches first make src/ warning free, and then
turn on the strict warning options.
75 0001-build-suppress-an-ignored-write-return-value-warning.patch
38 0002-build-suppress-an-ignored-dup-return-value-warning.patch
27 0003-generator.ml-suppress-signed-unsigned-compare-warnin.patch
48 0004-build-don-t-perform-arithmetic-on-void-pointers.patch
30 0005-suppress-signed-unsigned-comparison-warnings.patch
28 0006-suppress-a-warning-from-Wswitch-default.patch
36 0007-suppress-warnings-from-Wmissing-noreturn.patch
102 0008-build-new-configure-time-option-enable-gcc-warnings.patch
$ diffstat 000*
b/bootstrap | 1
b/configure.ac | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++
b/src/Makefile.am | 4 ++-
b/src/generator.ml | 3 --
b/src/guestfs.c | 4 +--
src/Makefile.am | 5 ++--
src/guestfs.c | 32 +++++++++++++++++----------
7 files changed, 91 insertions(+), 19 deletions(-)
15 years, 4 months
[PATCH] guestfs_modprobe: explicitly load a kernel module in the appliance
by Matthew Booth
---
daemon/Makefile.am | 1 +
daemon/modprobe.c | 43 +++++++++++++++++++++++++++++++++++++++++++
po/POTFILES.in | 1 +
src/MAX_PROC_NR | 2 +-
src/generator.ml | 7 +++++++
5 files changed, 53 insertions(+), 1 deletions(-)
create mode 100644 daemon/modprobe.c
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 097d89d..83ee408 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -54,6 +54,7 @@ guestfsd_SOURCES = \
lvm.c \
mkfs.c \
mknod.c \
+ modprobe.c \
mount.c \
names.c \
ntfs.c \
diff --git a/daemon/modprobe.c b/daemon/modprobe.c
new file mode 100644
index 0000000..8f92eca
--- /dev/null
+++ b/daemon/modprobe.c
@@ -0,0 +1,43 @@
+/* libguestfs - the guestfsd daemon
+ * Copyright (C) 2009 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "daemon.h"
+
+int
+do_modprobe (const char *module)
+{
+ const char *argv[] = {
+ "/sbin/modprobe",
+ NULL,
+ NULL
+ };
+
+ argv[1] = module;
+
+ char *out, *err;
+ int r = commandv (&out, &err, (char **) argv);
+
+ if (r == -1) {
+ reply_with_error ("%s", err);
+ }
+
+ free (out);
+ free (err);
+
+ return r;
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 33bf6e6..19eef99 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -30,6 +30,7 @@ daemon/ls.c
daemon/lvm.c
daemon/mkfs.c
daemon/mknod.c
+daemon/modprobe.c
daemon/mount.c
daemon/names.c
daemon/ntfs.c
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 2455a46..205a12b 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-193
+194
diff --git a/src/generator.ml b/src/generator.ml
index cc97dd5..41a78fe 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -3560,6 +3560,13 @@ an external journal on the journal with UUID C<uuid>.
See also C<guestfs_mke2journal_U>.");
+ ("modprobe", (RErr, [String "module"]), 194, [],
+ [InitNone, Always, TestRun [["modprobe"; "ext2"]]],
+ "load a kernel module",
+ "\
+This loads a kernel module in the appliance. The kernel module must be available
+in the appliance.");
+
]
let all_functions = non_daemon_functions @ daemon_functions
--
1.6.2.5
15 years, 4 months
[PATCH] Load the ext2 module so mkinitrd works on RHEL 3
by Matthew Booth
---
appliance/init | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/appliance/init b/appliance/init
index fe135b4..053ef36 100755
--- a/appliance/init
+++ b/appliance/init
@@ -39,6 +39,9 @@ fi
modprobe dm_mod ||:
+# For mkinitrd on RHEL 3
+modprobe ext2
+
ifconfig lo 127.0.0.1
ifconfig eth0 10.0.2.10
route add default gw 10.0.2.2
--
1.6.2.5
15 years, 4 months
CHROOT_IN and CHROOT_OUT
by Matthew Booth
I hit the following weirdness in guestfish:
><fs> ll /../proc/modules
-r--r--r-- 1 root root 0 Aug 18 10:37 /sysroot/../proc/modules
><fs> cat /../proc/modules
libguestfs: error: open: /../proc/modules: No such file or directory
The underlying reason for this seems to be that ll uses sysroot_path to
establish a path before operating on it, whereas cat uses CHROOT_IN and
CHROOT_OUT to open() inside a chroot. It seems to me that wherever a
path is used directly by a command, there should never be a reason to
use chroot because the real path can always be worked out. The only
place I see for using a chroot is in command and sh.
Is it worth making a bulk CHROOT_IN and CHROOT_OUT removal patch?
Matt
--
Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team
M: +44 (0)7977 267231
GPG ID: D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
15 years, 4 months
[PATCH libguestfs] avoid compiler warnings about unused vars in generated code
by Jim Meyering
Very similar to the one for protocol.c...
>From b5896dfb673a6f8dfd536ae86a6ea3d2925d2af5 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Tue, 18 Aug 2009 10:15:57 +0200
Subject: [PATCH libguestfs] avoid compiler warnings about unused vars in generated code
* fish/Makefile.am: Compile rc_protocol.c into a convenience library,
so it can have its own CFLAGS, and link that into guestfish.
generator.ml: Use TABs, not spaces for indentation.
---
fish/Makefile.am | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/fish/Makefile.am b/fish/Makefile.am
index 8c289dc..5bf3fbd 100644
--- a/fish/Makefile.am
+++ b/fish/Makefile.am
@@ -35,12 +35,15 @@ guestfish_SOURCES = \
lcd.c \
more.c \
rc.c \
- rc_protocol.c \
- rc_protocol.h \
reopen.c \
tilde.c \
time.c
+# This convenience library is solely to avoid compiler warnings
+# in its generated sources.
+librc_protocol_la_SOURCES = rc_protocol.c
+librc_protocol_la_CFLAGS = -Wall -Wno-unused
+
BUILT_SOURCES = \
rc_protocol.c \
rc_protocol.h
@@ -50,8 +53,13 @@ guestfish_CFLAGS = \
-I$(top_srcdir)/fish -I$(top_builddir)/fish \
-Wall \
-DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"'
+
guestfish_LDADD = $(top_builddir)/src/libguestfs.la $(LIBREADLINE)
+# Make libguestfs use the convenience library.
+noinst_LTLIBRARIES = librc_protocol.la
+guestfish_LDADD += librc_protocol.la
+
if HAVE_RPCGEN
rc_protocol.c: rc_protocol.x
rm -f $@-t $@-t2
--
1.6.4.378.g88f2f
15 years, 4 months
two more warning-avoidance patches
by Jim Meyering
>From 9e99a1c6cb655a56d7f09dabd10a77a3802bf96d Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 17 Aug 2009 18:44:37 +0200
Subject: [PATCH libguestfs 1/2] avoid compiler warnings about unused vars in generated code
* src/Makefile.am: Compile protocol.c into a convenience library, so it
can have its own CFLAGS, and link that with the destination one.
---
src/Makefile.am | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index c6006d2..9eb71b9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -48,6 +48,14 @@ BUILT_SOURCES = \
guestfs-actions.c \
guestfs-bindtests.c
+# This convenience library is solely to avoid compiler warnings
+# in its generated sources.
+libprotocol_la_SOURCES = \
+ guestfs_protocol.c \
+ guestfs_protocol.h
+
+libprotocol_la_CFLAGS = -Wall -Wno-unused
+
$(BUILT_SOURCES): stamp-generator
CLEANFILES = guestfs_protocol.c guestfs_protocol.h
@@ -98,13 +106,15 @@ libguestfs_la_LDFLAGS = -version-info $(MAX_PROC_NR):0:$(MAX_PROC_NR)
libguestfs_la_SOURCES = \
guestfs.c \
guestfs.h \
- guestfs_protocol.c \
- guestfs_protocol.h \
guestfs-actions.h \
guestfs-actions.c \
guestfs-bindtests.c \
gettext.h
+# Make libguestfs include the convenience library.
+noinst_LTLIBRARIES = libprotocol.la
+libguestfs_la_LIBADD = libprotocol.la
+
libguestfs_la_CFLAGS = -Wall -DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"'
if HAVE_RPCGEN
--
1.6.4.378.g88f2f
>From ab84f9a78034249f37861e00e474018b8f750df2 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 17 Aug 2009 18:47:46 +0200
Subject: [PATCH libguestfs 2/2] generator.ml: avoid warnings in generated tests.c
* src/generator.ml: Avoid warnings in generated tests.c, regarding
print_strings, and in exercising any function that takes a StringList
or DeviceList parameter.
(print_strings): Change param type to "char *const *s".
Declare fully-const initializer for each list-taking function use.
Cast *List argument to "(char **)".
---
src/generator.ml | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/generator.ml b/src/generator.ml
index ad4c0cb..ac01a98 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -5274,7 +5274,7 @@ static void print_error (guestfs_h *g, void *data, const char *msg)
}
/* FIXME: nearly identical code appears in fish.c */
-static void print_strings (char const *const *argv)
+static void print_strings (char *const *argv)
{
int argc;
@@ -5869,7 +5869,7 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd =
fun i str ->
pr " const char *%s_%d = \"%s\";\n" n i (c_quote str);
) strs;
- pr " const char *%s[] = {\n" n;
+ pr " const char *const %s[] = {\n" n;
iteri (
fun i _ -> pr " %s_%d,\n" n i
) strs;
@@ -5912,7 +5912,7 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd =
| FileIn _, arg | FileOut _, arg ->
pr ", \"%s\"" (c_quote arg)
| StringList n, _ | DeviceList n, _ ->
- pr ", %s" n
+ pr ", (char **) %s" n
| Int _, arg ->
let i =
try int_of_string arg
@@ -9019,7 +9019,7 @@ and generate_bindtests () =
#define safe_malloc guestfs_safe_malloc
static void
-print_strings (char * const* const argv)
+print_strings (char *const *argv)
{
int argc;
--
1.6.4.378.g88f2f
15 years, 4 months
[PATCH libguestfs] generator.ml: do not emit unused print_* functions
by Jim Meyering
One final set:
cmds.c:968:13: warning: 'print_lvm_pv' defined but not used
cmds.c:1012:13: warning: 'print_lvm_vg' defined but not used
cmds.c:1055:13: warning: 'print_lvm_lv' defined but not used
cmds.c:1142:13: warning: 'print_dirent' defined but not used
cmds.c:1196:13: warning: 'print_xattr' defined but not used
cmds.c:1220:13: warning: 'print_inotify_event' defined but not used
Don't generate them:
>From 66e9d6832a19140c8b79b6be4c16c1fcac22207c Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 17 Aug 2009 20:44:01 +0200
Subject: [PATCH libguestfs] generator.ml: do not emit unused print_* functions
* src/generator.ml: Do not emit functions like print_xattr,
print_lvm_vg, print_inotify_event, that are not used.
---
src/generator.ml | 17 ++++++++++++-----
1 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/src/generator.ml b/src/generator.ml
index 1e717db..9f2b8cf 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -6129,11 +6129,6 @@ and generate_fish_cmds () =
) cols;
pr "}\n";
pr "\n";
- pr "static void print_%s (struct guestfs_%s *%s)\n" typ typ typ;
- pr "{\n";
- pr " print_%s_indent (%s, \"\");\n" typ typ;
- pr "}\n";
- pr "\n";
) structs;
(* Emit a print_TYPE_list function definition only if that function is used. *)
@@ -6145,6 +6140,18 @@ and generate_fish_cmds () =
| typ, _ -> () (* empty *)
) rstructs_used;
+ (* Emit a print_TYPE function definition only if that function is used. *)
+ List.iter (
+ function
+ | typ, RStructOnly ->
+ pr "static void print_%s (struct guestfs_%s *%s)\n" typ typ typ;
+ pr "{\n";
+ pr " print_%s_indent (%s, \"\");\n" typ typ;
+ pr "}\n";
+ pr "\n";
+ | typ, _ -> () (* empty *)
+ ) rstructs_used;
+
(* run_<action> actions *)
List.iter (
fun (name, style, _, flags, _, _, _) ->
--
1.6.4.378.g88f2f
15 years, 4 months