Add a macro DUP_RESOLVE_DEVICE_OR_PATH to resolve path or device.
Signed-off-by: Wanlong Gao <gaowanlong(a)cn.fujitsu.com>
---
daemon/daemon.h | 18 ++++++++++++++++++
daemon/mount.c | 13 ++-----------
po/POTFILES | 8 ++++++++
3 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 85eec45..39cc3f3 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -336,6 +336,24 @@ is_zero (const char *buffer, size_t size)
} \
} while (0)
+/* Helper for functions which need either a root(/sysroot) path,
+ * OR a /dev/ device which exists.
+ */
+#define DUP_RESOLVE_DEVICE_OR_PATH(path,buf,cancel_stmt,fail_stmt) \
+ do { \
+ int is_dev; \
+ is_dev = STREQLEN (path, "/dev/", 5); \
+ buf = is_dev ? strdup (path) \
+ : sysroot_path (path); \
+ if (buf == NULL) { \
+ cancel_stmt; \
+ reply_with_perror ("malloc"); \
+ fail_stmt; \
+ } \
+ if (is_dev) \
+ RESOLVE_DEVICE (buf, cancel_stmt, fail_stmt); \
+ } while (0)
+
/* NB:
* (1) You must match CHROOT_IN and CHROOT_OUT even along error paths.
* (2) You must not change directory! cwd must always be "/", otherwise
diff --git a/daemon/mount.c b/daemon/mount.c
index 0661eb8..1bac1a7 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -192,18 +192,9 @@ do_umount (const char *pathordevice)
int r;
char *err;
char *buf;
- int is_dev;
- is_dev = STREQLEN (pathordevice, "/dev/", 5);
- buf = is_dev ? strdup (pathordevice)
- : sysroot_path (pathordevice);
- if (buf == NULL) {
- reply_with_perror ("malloc");
- return -1;
- }
-
- if (is_dev)
- RESOLVE_DEVICE (buf, , { free (buf); return -1; });
+ DUP_RESOLVE_DEVICE_OR_PATH (pathordevice, buf, ,
+ { free (buf); return -1;});
r = command (NULL, &err, "umount", buf, NULL);
free (buf);
diff --git a/po/POTFILES b/po/POTFILES
index 60f8d95..69291fa 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -27,6 +27,7 @@ daemon/du.c
daemon/echo-daemon.c
daemon/errnostring-gperf.c
daemon/errnostring.c
+daemon/errnostring_gperf.c
daemon/ext2.c
daemon/fallocate.c
daemon/file.c
@@ -97,6 +98,7 @@ erlang/erl-guestfs.c
fish/alloc.c
fish/cmds-gperf.c
fish/cmds.c
+fish/cmds_gperf.c
fish/completion.c
fish/config.c
fish/copy.c
@@ -135,6 +137,7 @@ format/format.c
fuse/guestmount.c
gobject/src/optargs-add_domain.c
gobject/src/optargs-add_drive.c
+gobject/src/optargs-add_drive_opts.c
gobject/src/optargs-btrfs_filesystem_resize.c
gobject/src/optargs-btrfs_fsck.c
gobject/src/optargs-compress_device_out.c
@@ -150,12 +153,15 @@ gobject/src/optargs-internal_test.c
gobject/src/optargs-md_create.c
gobject/src/optargs-mkfs.c
gobject/src/optargs-mkfs_btrfs.c
+gobject/src/optargs-mkfs_opts.c
gobject/src/optargs-mount_9p.c
gobject/src/optargs-mount_local.c
gobject/src/optargs-ntfsclone_out.c
gobject/src/optargs-ntfsfix.c
gobject/src/optargs-ntfsresize.c
+gobject/src/optargs-ntfsresize_opts.c
gobject/src/optargs-set_e2attrs.c
+gobject/src/optargs-test0.c
gobject/src/optargs-tune2fs.c
gobject/src/optargs-umount_local.c
gobject/src/session.c
@@ -180,6 +186,7 @@ inspector/virt-inspector.c
java/com_redhat_et_libguestfs_GuestFS.c
ocaml/guestfs-c-actions.c
ocaml/guestfs-c.c
+ocaml/guestfs_c_actions.c
perl/Guestfs.c
perl/bindtests.pl
perl/lib/Sys/Guestfs.pm
@@ -197,6 +204,7 @@ src/bindtests.c
src/dbdump.c
src/errnostring-gperf.c
src/errnostring.c
+src/errnostring_gperf.c
src/events.c
src/filearch.c
src/fuse.c
--
1.7.11.2.249.g31c7954