factorization would be nice
by Jim Meyering
Hi Rich,
I've changed part of generator.ml to look like this:
(match snd style with
| [] -> ()
| args ->
pr " memset (&args, 0, sizeof args);\n";
pr "\n";
pr " if (!xdr_guestfs_%s_args (xdr_in, &args)) {\n" name;
pr " reply_with_error (\"%%s: daemon failed to decode procedure arguments\", \"%s\");\n" name;
pr " return;\n";
pr " }\n";
List.iter (
function
| Pathname n ->
pr " char *%s = args.%s;\n" n n;
pr " ABS_PATH (%s, goto done);\n" n;
| Device n ->
pr " char *%s = args.%s;\n" n n;
pr " RESOLVE_DEVICE (%s, goto done);" n;
| Dev_or_Path n ->
pr " char *%s = args.%s;\n" n n;
pr " REQUIRE_ROOT_OR_RESOLVE_DEVICE (%s, goto done);" n;
| String n -> pr " char *%s = args.%s;\n" n n
| OptString n -> pr " %s = args.%s ? *args.%s : NULL;\n" n n n
| StringList n ->
pr " %s = realloc (args.%s.%s_val,\n" n n n;
pr " sizeof (char *) * (args.%s.%s_len+1));\n" n n;
pr " if (%s == NULL) {\n" n;
pr " reply_with_perror (\"realloc\");\n";
pr " goto done;\n";
pr " }\n";
pr " %s[args.%s.%s_len] = NULL;\n" n n n;
pr " args.%s.%s_val = %s;\n" n n n;
| Bool n -> pr " %s = args.%s;\n" n n
| Int n -> pr " %s = args.%s;\n" n n
| FileIn _ | FileOut _ -> ()
) args;
pr "\n"
);
Note the 4-x repeated statement:
pr " char *%s = args.%s;\n" n n;
What's the best way to avoid that?
15 years, 3 months
do_umount adjustment
by Jim Meyering
Here's one final (I hope) question without a complete patch.
Given that I already ensure that stubs.c invokes
REQUIRE_ROOT_OR_RESOLVE_DEVICE just before calling do_umount,
does this new version of do_umount look ok?
/* Again, use the external /bin/umount program, so that /etc/mtab
* is kept updated.
*/
int
do_umount (const char *pathordevice)
{
int r;
char *err;
char *buf = sysroot_path (pathordevice);
if (buf == NULL) {
reply_with_perror ("malloc");
return -1;
}
r = command (NULL, &err, "umount", buf, NULL);
if (r == -1) {
reply_with_error ("umount: %s: %s", pathordevice, err);
free (err);
free (buf);
return -1;
}
free (err);
/* update root_mounted? */
return 0;
}
15 years, 3 months
[PATCH libguestfs] generator.ml: constify do_mkdtemp
by Jim Meyering
Not useful from a testing standpoint (since this presumes
a metric ton of other changes), but mostly a heads-up where I'm going.
>From 62cbebffe9859046019b500e4bcdb0e44e575755 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Tue, 11 Aug 2009 17:17:08 +0200
Subject: [PATCH libguestfs] generator.ml: constify do_mkdtemp
* daemon/dir.c (do_mkdtemp): Rewrite for a "const" parameter.
* src/generator.ml (mkdtemp): Declare parameter to be of type Pathname.
---
daemon/dir.c | 27 ++++++++-------------------
src/generator.ml | 8 +++-----
2 files changed, 11 insertions(+), 24 deletions(-)
diff --git a/daemon/dir.c b/daemon/dir.c
index ad1c7c9..21ae07e 100644
--- a/daemon/dir.c
+++ b/daemon/dir.c
@@ -185,31 +185,20 @@ do_is_dir (const char *path)
}
char *
-do_mkdtemp (char *template)
+do_mkdtemp (const char *template)
{
- char *r;
-
- NEED_ROOT (return NULL);
- ABS_PATH (template, return NULL);
+ char *r = strdup (template);
+ if (r == NULL) {
+ reply_with_perror ("strdup");
+ return NULL;
+ }
CHROOT_IN;
- r = mkdtemp (template);
+ r = mkdtemp (r);
CHROOT_OUT;
- if (r == NULL) {
+ if (r == NULL)
reply_with_perror ("mkdtemp: %s", template);
- return NULL;
- }
- /* The caller will free template AND try to free the return value,
- * so we must make a copy here.
- */
- if (r == template) {
- r = strdup (template);
- if (r == NULL) {
- reply_with_perror ("strdup");
- return NULL;
- }
- }
return r;
}
diff --git a/src/generator.ml b/src/generator.ml
index 8dc9261..3c7512f 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -2594,8 +2594,7 @@ containing C<dir>.
It is an interface to the L<scrub(1)> program. See that
manual page for more details.");
-(* FIXME: make this a WritableString? *)
- ("mkdtemp", (RString "dir", [String "template"]), 117, [],
+ ("mkdtemp", (RString "dir", [Pathname "template"]), 117, [],
[InitBasicFS, Always, TestRun (
[["mkdir"; "/tmp"];
["mkdtemp"; "/tmp/tmpXXXXXX"]])],
15 years, 3 months
[PATCH libguestfs] daemon/ls: make do_ll require root, like all the rest
by Jim Meyering
per IRC discussion,
>From a1d982bf49e166341096902fc4c103d4397ce0e3 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Tue, 11 Aug 2009 13:16:27 +0200
Subject: [PATCH libguestfs] daemon/ls: make do_ll require root, like all the rest
* ls.c (do_ll): Do invoke "NEED_ROOT" here, and add a FIXME to
provide a "debug ll" command with the semantics we're removing.
---
daemon/ls.c | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/daemon/ls.c b/daemon/ls.c
index 4d4714e..90db3e3 100644
--- a/daemon/ls.c
+++ b/daemon/ls.c
@@ -74,6 +74,14 @@ do_ls (char *path)
return r;
}
+/* FIXME: eventually, provide a "debug ll" command that would
+ * expose the /sysroot, because we can't chroot and run the ls
+ * command (since 'ls' won't necessarily exist in the chroot). This
+ * command is not meant for serious use anyway, just for quick
+ * interactive sessions. For the same reason, you can also "escape"
+ * the sysroot (eg. 'll /..').
+ */
+
char *
do_ll (char *path)
{
@@ -81,15 +89,9 @@ do_ll (char *path)
char *out, *err;
char *spath;
- //NEED_ROOT
+ NEED_ROOT (NULL);
ABS_PATH (path, NULL);
- /* This exposes the /sysroot, because we can't chroot and run the ls
- * command (since 'ls' won't necessarily exist in the chroot). This
- * command is not meant for serious use anyway, just for quick
- * interactive sessions. For the same reason, you can also "escape"
- * the sysroot (eg. 'll /..').
- */
spath = sysroot_path (path);
if (!spath) {
reply_with_perror ("malloc");
--
1.6.4.337.g5420e
15 years, 3 months
[PATCH libguestfs] doc: improve emacs snippets
by Jim Meyering
I've made some local commits that introduce TABs as indentation,
and thus provoke a "make syntax-check" failure.
This would have prevented it:
>From 4740b66adc5985d9a72a7648aa60c5389ffc31af Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Tue, 11 Aug 2009 09:53:16 +0200
Subject: [PATCH libguestfs] doc: improve emacs snippets
* HACKING: Make (setq indent-tabs-mode nil) apply to nearly all
files, not just C-mode ones.
---
HACKING | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/HACKING b/HACKING
index cb339bd..860726d 100644
--- a/HACKING
+++ b/HACKING
@@ -35,16 +35,24 @@ indentation level, and other than that, follow the K&R style.
If you use Emacs, add the following to one of one of your start-up files
(e.g., ~/.emacs), to help ensure that you get indentation right:
+ ;;; In libguestfs, indent with spaces everywhere (not TABs).
+ ;;; Exceptions: Makefile and ChangeLog modes.
+ (add-hook 'find-file-hook
+ '(lambda () (if (and buffer-file-name
+ (string-match "/libguestfs\\>" (buffer-file-name))
+ (not (string-equal mode-name "Change Log"))
+ (not (string-equal mode-name "Makefile")))
+ (setq indent-tabs-mode nil))))
+
;;; When editing C sources in libguestfs, use this style.
(defun libguestfs-c-mode ()
"C mode with adjusted defaults for use with libguestfs."
(interactive)
(c-set-style "K&R")
- (setq indent-tabs-mode nil) ; indent using spaces, not TABs
(setq c-indent-level 2)
(setq c-basic-offset 2))
(add-hook 'c-mode-hook
- '(lambda () (if (string-match "/libguestfs" (buffer-file-name))
+ '(lambda () (if (string-match "/libguestfs\\>" (buffer-file-name))
(libguestfs-c-mode))))
Directories
--
1.6.4.337.g5420e
15 years, 3 months
/config.status
by Richard W.M. Jones
If you just git clone, ./autogen.sh, make, then the first time you get
this error:
Making all in po
make[2]: Entering directory `/home/rjones/d/libguestfs/po'
make[2]: *** No rule to make target `/config.status', needed by `Makefile'. Stop.
make[2]: Leaving directory `/home/rjones/d/libguestfs/po'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/rjones/d/libguestfs'
make: *** [all] Error 2
However rerunning autogen.sh fixes it. Any ideas why?
Rich.
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v
15 years, 3 months
[PATCH libguestfs] build: daemon/do_debug: parameters aren't always unused
by Jim Meyering
Thanks to the reminder from Dan Berrange,
here's a patch to make build output less verbose, by default.
E.g., instead of the redundant multi-line compilation/linking commands,
you'll see something like this by default:
CC guestfsd-fsck.o
CC guestfsd-grep.o
CC guestfsd-grub.o
CC guestfsd-glob.o
CC guestfsd-guestfsd.o
CC guestfsd-headtail.o
CC guestfsd-hexdump.o
CC guestfsd-initrd.o
CC guestfsd-inotify.o
...
CC guestfsd-zero.o
CC guestfsd-zerofree.o
CCLD guestfsd
If you want to diagnose a problem, or just prefer to see
full commands, build with "make V=1".
>From 4a2e4d21c49ed47dea15a2ccf3cb06e210626742 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 10 Aug 2009 12:44:09 +0200
Subject: [PATCH libguestfs] build: enable automake's silent rules option
* configure.ac: Use AM_SILENT_RULES([yes]).
Those who want verbose build output may configure with
--disable-silent-rules or use "make V=1".
* daemon/configure.ac: Likewise.
---
configure.ac | 1 +
daemon/configure.ac | 1 +
2 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac
index cf0591d..f2d05dd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,6 +25,7 @@ m4_define([libguestfs_extra], [])
AC_INIT([libguestfs],libguestfs_major.libguestfs_minor.libguestfs_release[]libguestfs_extra)
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign])
+AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
AC_CONFIG_MACRO_DIR([m4])
diff --git a/daemon/configure.ac b/daemon/configure.ac
index b038d17..3abc306 100644
--- a/daemon/configure.ac
+++ b/daemon/configure.ac
@@ -18,6 +18,7 @@
AC_INIT([libguestfs-daemon],[1.0.0])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([foreign])
+AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
AC_CONFIG_MACRO_DIR([m4])
--
1.6.4.300.gc9df
15 years, 3 months
daemon/ warnings
by Jim Meyering
Here are a few warning-removal changes for daemon/:
>From eea38a1937ccd396603ed899d829d2982755ea4a Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Thu, 6 Aug 2009 15:25:03 +0200
Subject: [PATCH 1/4] define ATTRIBUTE_UNUSED
* daemon/daemon.h (__attribute__, ATTRIBUTE_UNUSED): Define.
---
daemon/daemon.h | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 70a2351..a6bbb73 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -213,4 +213,14 @@ extern void reply (xdrproc_t xdrp, char *ret);
} \
while (0)
+#ifndef __attribute__
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
+# define __attribute__(x) /* empty */
+# endif
+#endif
+
+#ifndef ATTRIBUTE_UNUSED
+# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
+#endif
+
#endif /* GUESTFSD_DAEMON_H */
--
1.6.4.174.gc193a
>From af4e98c3371f6008188fb3ef7136c1ebda008933 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Thu, 6 Aug 2009 15:26:13 +0200
Subject: [PATCH 2/4] build: avoid warnings in daemon/debug.c
* daemon/debug.c (do_debug): Mark parameters as unused.
---
daemon/debug.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/daemon/debug.c b/daemon/debug.c
index 13b7240..5b3b5fa 100644
--- a/daemon/debug.c
+++ b/daemon/debug.c
@@ -61,7 +61,7 @@ static struct cmd cmds[] = {
#endif
char *
-do_debug (char *subcmd, char **argv)
+do_debug (char *subcmd ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
{
#if ENABLE_DEBUG_COMMAND
int argc, i;
--
1.6.4.174.gc193a
>From a174e20227e5299a172934d9f60023ac55530a1f Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Thu, 6 Aug 2009 15:28:48 +0200
Subject: [PATCH 3/4] build: avoid warnings in daemon/guestfsd.c
* daemon/guestfsd.c (print_arginfo, print_shell_quote): Mark each
"info" parameter as unused.
---
daemon/guestfsd.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 07a1c5e..07a952f 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -718,7 +718,7 @@ split_lines (char *str)
*/
static int
print_shell_quote (FILE *stream,
- const struct printf_info *info,
+ const struct printf_info *info ATTRIBUTE_UNUSED,
const void *const *args)
{
#define SAFE(c) (isalnum((c)) || \
@@ -751,7 +751,7 @@ print_sysroot_shell_quote (FILE *stream,
#ifdef HAVE_REGISTER_PRINTF_SPECIFIER
static int
-print_arginfo (const struct printf_info *info,
+print_arginfo (const struct printf_info *info ATTRIBUTE_UNUSED,
size_t n, int *argtypes, int *size)
{
if (n > 0) {
--
1.6.4.174.gc193a
>From b9842a2ca010bf89b11b4b640bbdee5df58f8341 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Thu, 6 Aug 2009 16:05:44 +0200
Subject: [PATCH 4/4] build: avoid warnings in daemon/inotify.c
Avoid "comparison between signed and unsigned integer expressions"
warnings. If it's at all hard or risky to avoid this type of warning,
then it's not worthwhile. Here, it's easy and safe.
* daemon/inotify.c (inotify_posn): Declare local to be of unsigned type.
(do_inotify_read, do_inotify_files): Likewise.
---
daemon/inotify.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/daemon/inotify.c b/daemon/inotify.c
index 1b90f2b..8bb8ed2 100644
--- a/daemon/inotify.c
+++ b/daemon/inotify.c
@@ -33,7 +33,7 @@
static int inotify_fd = -1;
static char inotify_buf[64*1024*1024]; /* Event buffer, [0..posn-1] is valid */
-static int inotify_posn = 0;
+static size_t inotify_posn = 0;
/* Because inotify_init does NEED_ROOT, NEED_INOTIFY implies NEED_ROOT. */
#define NEED_INOTIFY(errcode) \
@@ -184,7 +184,8 @@ do_inotify_read (void)
while (space > 0) {
struct inotify_event *event;
- int n, r;
+ int r;
+ size_t n;
r = read (inotify_fd, inotify_buf + inotify_posn,
sizeof (inotify_buf) - inotify_posn);
@@ -274,7 +275,7 @@ do_inotify_files (void)
{
char **ret = NULL;
int size = 0, alloc = 0;
- int i;
+ unsigned int i;
FILE *fp;
guestfs_int_inotify_event_list *events;
char buf[PATH_MAX];
--
1.6.4.174.gc193a
15 years, 3 months
[PATCH] daemon/file.c: remove duplicate absolute-path check
by Jim Meyering
minor clean-up:
>From cac2ce53aec6d3aaca83e4bbc3551d452c29c0b2 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Fri, 7 Aug 2009 20:07:03 +0200
Subject: [PATCH] daemon/file.c: remove duplicate absolute-path check
* daemon/file.c (do_file): Remove redundant use of ABS_PATH.
It's redundant because the preceding line invokes NEED_ROOT_OR_IS_DEVICE,
which also invokes ABS_PATH.
---
daemon/file.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/daemon/file.c b/daemon/file.c
index 63d8dd2..cd477e5 100644
--- a/daemon/file.c
+++ b/daemon/file.c
@@ -392,7 +392,6 @@ do_file (char *path)
int len;
NEED_ROOT_OR_IS_DEVICE (path, NULL);
- ABS_PATH (path, NULL);
if (strncmp (path, "/dev/", 5) == 0)
buf = (char *) path;
--
1.6.4.161.gc0b1
15 years, 3 months
fedoostrap or deboostrap requirement
by Piavlo
Hi,
While trying to ./configure libguestfs on gentoo fails since it requires
feboostrap or deboostrap
Can this be made optional and not as necessary requirement, since there
are still many useful uses for libguestfs
besides bootstrapping, which can be used on distros like gentoo.
Thanks
Alex
15 years, 3 months