[PATCH v2 1/2] daemon: glob: add optarg to control trailing slash for dirs
by Pino Toscano
Add a new optional bool "directoryslash" to indicate whether the caller
wants trailing slashes in names of directories, defaulting to true (the
current behaviour); this helps with interoperability with other tools
(such as rm).
Related to RHBZ#1293271.
---
daemon/glob.c | 11 +++++++++--
generator/actions.ml | 21 ++++++++++++++++-----
gobject/Makefile.inc | 2 ++
po/POTFILES | 1 +
4 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/daemon/glob.c b/daemon/glob.c
index 45fb30f..a22fd33 100644
--- a/daemon/glob.c
+++ b/daemon/glob.c
@@ -26,14 +26,21 @@
#include "actions.h"
char **
-do_glob_expand (const char *pattern)
+do_glob_expand (const char *pattern, int directoryslash)
{
int r;
glob_t buf = { .gl_pathc = 0, .gl_pathv = NULL, .gl_offs = 0 };
+ int flags = GLOB_BRACE | GLOB_MARK;
+
+ /* GLOB_MARK is default, unless the user explicitly disabled it. */
+ if ((optargs_bitmask & GUESTFS_GLOB_EXPAND_DIRECTORYSLASH_BITMASK)
+ && !directoryslash) {
+ flags &= ~GLOB_MARK;
+ }
/* glob(3) in glibc never calls chdir, so this seems to be safe: */
CHROOT_IN;
- r = glob (pattern, GLOB_MARK|GLOB_BRACE, NULL, &buf);
+ r = glob (pattern, flags, NULL, &buf);
CHROOT_OUT;
if (r == GLOB_NOMATCH) { /* Return an empty list instead of an error. */
diff --git a/generator/actions.ml b/generator/actions.ml
index 0755fef..36b8680 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -5969,27 +5969,34 @@ See also: C<guestfs_command_lines>" };
* start with "/". There is no concept of "cwd" in libguestfs,
* hence no "."-relative names.
*)
- style = RStringList "paths", [Pathname "pattern"], [];
+ style = RStringList "paths", [Pathname "pattern"], [OBool "directoryslash"];
proc_nr = Some 113;
+ once_had_no_optargs = true;
tests = [
InitScratchFS, Always, TestResult (
[["mkdir_p"; "/glob_expand/b/c"];
["touch"; "/glob_expand/b/c/d"];
["touch"; "/glob_expand/b/c/e"];
- ["glob_expand"; "/glob_expand/b/c/*"]],
+ ["glob_expand"; "/glob_expand/b/c/*"; ""]],
"is_string_list (ret, 2, \"/glob_expand/b/c/d\", \"/glob_expand/b/c/e\")"), [];
InitScratchFS, Always, TestResult (
[["mkdir_p"; "/glob_expand2/b/c"];
["touch"; "/glob_expand2/b/c/d"];
["touch"; "/glob_expand2/b/c/e"];
- ["glob_expand"; "/glob_expand2/*/c/*"]],
+ ["glob_expand"; "/glob_expand2/*/c/*"; ""]],
"is_string_list (ret, 2, \"/glob_expand2/b/c/d\", \"/glob_expand2/b/c/e\")"), [];
InitScratchFS, Always, TestResult (
[["mkdir_p"; "/glob_expand3/b/c"];
["touch"; "/glob_expand3/b/c/d"];
["touch"; "/glob_expand3/b/c/e"];
- ["glob_expand"; "/glob_expand3/*/x/*"]],
- "is_string_list (ret, 0)"), []
+ ["glob_expand"; "/glob_expand3/*/x/*"; ""]],
+ "is_string_list (ret, 0)"), [];
+ InitScratchFS, Always, TestResult (
+ [["mkdir_p"; "/glob_expand4/b/c"];
+ ["touch"; "/glob_expand4/b1"];
+ ["touch"; "/glob_expand4/c1"];
+ ["glob_expand"; "/glob_expand4/b*"; "false"]],
+ "is_string_list (ret, 2, \"/glob_expand4/b\", \"/glob_expand4/b1\")"), [];
];
shortdesc = "expand a wildcard path";
longdesc = "\
@@ -6004,6 +6011,10 @@ It is just a wrapper around the C L<glob(3)> function
with flags C<GLOB_MARK|GLOB_BRACE>.
See that manual page for more details.
+C<directoryslash> controls whether use the C<GLOB_MARK> flag for
+L<glob(3)>, and it defaults to true. It can be explicitly set as
+off to return no trailing slashes in filenames of directories.
+
Notice that there is no equivalent command for expanding a device
name (eg. F</dev/sd*>). Use C<guestfs_list_devices>,
C<guestfs_list_partitions> etc functions instead." };
diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc
index 3522eb2..5ba0fc9 100644
--- a/gobject/Makefile.inc
+++ b/gobject/Makefile.inc
@@ -68,6 +68,7 @@ guestfs_gobject_headers= \
include/guestfs-gobject/optargs-disk_create.h \
include/guestfs-gobject/optargs-e2fsck.h \
include/guestfs-gobject/optargs-fstrim.h \
+ include/guestfs-gobject/optargs-glob_expand.h \
include/guestfs-gobject/optargs-grep.h \
include/guestfs-gobject/optargs-hivex_open.h \
include/guestfs-gobject/optargs-inspect_get_icon.h \
@@ -154,6 +155,7 @@ guestfs_gobject_sources= \
src/optargs-disk_create.c \
src/optargs-e2fsck.c \
src/optargs-fstrim.c \
+ src/optargs-glob_expand.c \
src/optargs-grep.c \
src/optargs-hivex_open.c \
src/optargs-inspect_get_icon.c \
diff --git a/po/POTFILES b/po/POTFILES
index aca174d..2a1e313 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -195,6 +195,7 @@ gobject/src/optargs-cpio_out.c
gobject/src/optargs-disk_create.c
gobject/src/optargs-e2fsck.c
gobject/src/optargs-fstrim.c
+gobject/src/optargs-glob_expand.c
gobject/src/optargs-grep.c
gobject/src/optargs-hivex_open.c
gobject/src/optargs-inspect_get_icon.c
--
2.5.0
8 years, 10 months
[PATCH 1/3] sysprep, get-kernel: explicit the Guestfs parameter
by Pino Toscano
Help the OCaml compiler by expliciting Guestfs.guestfs as type for 'g'
in some functions.
---
get-kernel/get_kernel.ml | 2 +-
sysprep/sysprep_operation_abrt_data.ml | 2 +-
sysprep/sysprep_operation_bash_history.ml | 2 +-
sysprep/sysprep_operation_ca_certificates.ml | 2 +-
sysprep/sysprep_operation_crash_data.ml | 2 +-
sysprep/sysprep_operation_dhcp_client_state.ml | 2 +-
sysprep/sysprep_operation_dhcp_server_state.ml | 2 +-
sysprep/sysprep_operation_dovecot_data.ml | 2 +-
sysprep/sysprep_operation_firewall_rules.ml | 2 +-
sysprep/sysprep_operation_kerberos_data.ml | 2 +-
sysprep/sysprep_operation_logfiles.ml | 2 +-
sysprep/sysprep_operation_mail_spool.ml | 2 +-
sysprep/sysprep_operation_net_hostname.ml | 2 +-
sysprep/sysprep_operation_net_hwaddr.ml | 2 +-
sysprep/sysprep_operation_pacct_log.ml | 2 +-
sysprep/sysprep_operation_package_manager_cache.ml | 2 +-
sysprep/sysprep_operation_pam_data.ml | 2 +-
sysprep/sysprep_operation_puppet_data_log.ml | 2 +-
sysprep/sysprep_operation_rh_subscription_manager.ml | 2 +-
sysprep/sysprep_operation_rpm_db.ml | 2 +-
sysprep/sysprep_operation_samba_db_log.ml | 2 +-
sysprep/sysprep_operation_ssh_hostkeys.ml | 2 +-
sysprep/sysprep_operation_ssh_userdir.ml | 2 +-
sysprep/sysprep_operation_sssd_db_log.ml | 2 +-
sysprep/sysprep_operation_tmp_files.ml | 2 +-
25 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/get-kernel/get_kernel.ml b/get-kernel/get_kernel.ml
index 812138f..6f26ca4 100644
--- a/get-kernel/get_kernel.ml
+++ b/get-kernel/get_kernel.ml
@@ -149,7 +149,7 @@ let rec do_fetch ~transform_fn ~outputdir g root =
g#umount_all ()
-and pick_kernel_files_linux g root =
+and pick_kernel_files_linux (g : Guestfs.guestfs) root =
(* Get all kernels and initramfses. *)
let glob w = Array.to_list (g#glob_expand w) in
let kernels = glob "/boot/vmlinuz-*" in
diff --git a/sysprep/sysprep_operation_abrt_data.ml b/sysprep/sysprep_operation_abrt_data.ml
index d950270..0d94271 100644
--- a/sysprep/sysprep_operation_abrt_data.ml
+++ b/sysprep/sysprep_operation_abrt_data.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let abrt_data_perform g root side_effects =
+let abrt_data_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ <> "windows" then (
let paths = g#glob_expand "/var/spool/abrt/*" in
diff --git a/sysprep/sysprep_operation_bash_history.ml b/sysprep/sysprep_operation_bash_history.ml
index 67eb4e3..5ddd515 100644
--- a/sysprep/sysprep_operation_bash_history.ml
+++ b/sysprep/sysprep_operation_bash_history.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let bash_history_perform g root side_effects =
+let bash_history_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ <> "windows" then (
let files = g#glob_expand "/home/*/.bash_history" in
diff --git a/sysprep/sysprep_operation_ca_certificates.ml b/sysprep/sysprep_operation_ca_certificates.ml
index 213f4ac..1d85fda 100644
--- a/sysprep/sysprep_operation_ca_certificates.ml
+++ b/sysprep/sysprep_operation_ca_certificates.ml
@@ -22,7 +22,7 @@ open Common_gettext.Gettext
module StringSet = Set.Make (String)
module G = Guestfs
-let ca_certificates_perform g root side_effects =
+let ca_certificates_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ <> "windows" then (
let paths = [ "/etc/pki/CA/certs/*.crt";
diff --git a/sysprep/sysprep_operation_crash_data.ml b/sysprep/sysprep_operation_crash_data.ml
index 79f3d7f..70633fc 100644
--- a/sysprep/sysprep_operation_crash_data.ml
+++ b/sysprep/sysprep_operation_crash_data.ml
@@ -26,7 +26,7 @@ let globs = [
"/var/log/dump/*";
]
-let crash_data_perform g root side_effects =
+let crash_data_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ = "linux" then (
List.iter (fun glob -> Array.iter g#rm_rf (g#glob_expand glob)) globs
diff --git a/sysprep/sysprep_operation_dhcp_client_state.ml b/sysprep/sysprep_operation_dhcp_client_state.ml
index 3ee91df..bf5361f 100644
--- a/sysprep/sysprep_operation_dhcp_client_state.ml
+++ b/sysprep/sysprep_operation_dhcp_client_state.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let dhcp_client_state_perform g root side_effects =
+let dhcp_client_state_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ = "linux" then (
List.iter (
diff --git a/sysprep/sysprep_operation_dhcp_server_state.ml b/sysprep/sysprep_operation_dhcp_server_state.ml
index dfc71b2..b9fe936 100644
--- a/sysprep/sysprep_operation_dhcp_server_state.ml
+++ b/sysprep/sysprep_operation_dhcp_server_state.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let dhcp_server_state_perform g root side_effects =
+let dhcp_server_state_perform (g : Guestfs.guestfs) root side_effects =
Array.iter g#rm_rf (g#glob_expand "/var/lib/dhcpd/*")
let op = {
diff --git a/sysprep/sysprep_operation_dovecot_data.ml b/sysprep/sysprep_operation_dovecot_data.ml
index 976d483..3ca8bf5 100644
--- a/sysprep/sysprep_operation_dovecot_data.ml
+++ b/sysprep/sysprep_operation_dovecot_data.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let dovecot_data_perform g root side_effects =
+let dovecot_data_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ <> "windows" then (
let files = g#glob_expand "/var/lib/dovecot/*" in
diff --git a/sysprep/sysprep_operation_firewall_rules.ml b/sysprep/sysprep_operation_firewall_rules.ml
index f5967fc..0a70169 100644
--- a/sysprep/sysprep_operation_firewall_rules.ml
+++ b/sysprep/sysprep_operation_firewall_rules.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let firewall_rules_perform g root side_effects =
+let firewall_rules_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ <> "windows" then (
let paths = [ "/etc/sysconfig/iptables";
diff --git a/sysprep/sysprep_operation_kerberos_data.ml b/sysprep/sysprep_operation_kerberos_data.ml
index 449d604..9dc794f 100644
--- a/sysprep/sysprep_operation_kerberos_data.ml
+++ b/sysprep/sysprep_operation_kerberos_data.ml
@@ -22,7 +22,7 @@ open Common_gettext.Gettext
module StringSet = Set.Make (String)
module G = Guestfs
-let kerberos_data_perform g root side_effects =
+let kerberos_data_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ <> "windows" then (
let excepts = [ "/var/kerberos/krb5kdc/kadm5.acl";
diff --git a/sysprep/sysprep_operation_logfiles.ml b/sysprep/sysprep_operation_logfiles.ml
index 7b81959..0a9e054 100644
--- a/sysprep/sysprep_operation_logfiles.ml
+++ b/sysprep/sysprep_operation_logfiles.ml
@@ -132,7 +132,7 @@ let globs = List.sort compare [
]
let globs_as_pod = String.concat "\n" (List.map ((^) " ") globs)
-let logfiles_perform g root side_effects =
+let logfiles_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ = "linux" then (
List.iter (fun glob -> Array.iter g#rm_rf (g#glob_expand glob)) globs
diff --git a/sysprep/sysprep_operation_mail_spool.ml b/sysprep/sysprep_operation_mail_spool.ml
index 0db831c..873f753 100644
--- a/sysprep/sysprep_operation_mail_spool.ml
+++ b/sysprep/sysprep_operation_mail_spool.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let mail_spool_perform g root side_effects =
+let mail_spool_perform (g : Guestfs.guestfs) root side_effects =
List.iter (
fun glob -> Array.iter g#rm_rf (g#glob_expand glob)
) [
diff --git a/sysprep/sysprep_operation_net_hostname.ml b/sysprep/sysprep_operation_net_hostname.ml
index 9b13ffd..3824d42 100644
--- a/sysprep/sysprep_operation_net_hostname.ml
+++ b/sysprep/sysprep_operation_net_hostname.ml
@@ -22,7 +22,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let net_hostname_perform g root side_effects =
+let net_hostname_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
let distro = g#inspect_get_distro root in
match typ, distro with
diff --git a/sysprep/sysprep_operation_net_hwaddr.ml b/sysprep/sysprep_operation_net_hwaddr.ml
index 9052fcb..439da6d 100644
--- a/sysprep/sysprep_operation_net_hwaddr.ml
+++ b/sysprep/sysprep_operation_net_hwaddr.ml
@@ -22,7 +22,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let net_hwaddr_perform g root side_effects =
+let net_hwaddr_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
let distro = g#inspect_get_distro root in
match typ, distro with
diff --git a/sysprep/sysprep_operation_pacct_log.ml b/sysprep/sysprep_operation_pacct_log.ml
index 355198d..1f9f0be 100644
--- a/sysprep/sysprep_operation_pacct_log.ml
+++ b/sysprep/sysprep_operation_pacct_log.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let pacct_log_perform g root side_effects =
+let pacct_log_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
let distro = g#inspect_get_distro root in
match typ, distro with
diff --git a/sysprep/sysprep_operation_package_manager_cache.ml b/sysprep/sysprep_operation_package_manager_cache.ml
index 5eb0453..f35764a 100644
--- a/sysprep/sysprep_operation_package_manager_cache.ml
+++ b/sysprep/sysprep_operation_package_manager_cache.ml
@@ -22,7 +22,7 @@ open Common_utils
module G = Guestfs
-let package_manager_cache_perform g root side_effects =
+let package_manager_cache_perform (g : Guestfs.guestfs) root side_effects =
let packager = g#inspect_get_package_management root in
let cache_dirs =
match packager with
diff --git a/sysprep/sysprep_operation_pam_data.ml b/sysprep/sysprep_operation_pam_data.ml
index c3b988f..698a052 100644
--- a/sysprep/sysprep_operation_pam_data.ml
+++ b/sysprep/sysprep_operation_pam_data.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let pam_data_perform g root side_effects =
+let pam_data_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ <> "windows" then (
let paths = [ "/var/run/console/*";
diff --git a/sysprep/sysprep_operation_puppet_data_log.ml b/sysprep/sysprep_operation_puppet_data_log.ml
index f00e4a9..b8cb244 100644
--- a/sysprep/sysprep_operation_puppet_data_log.ml
+++ b/sysprep/sysprep_operation_puppet_data_log.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let puppet_data_log_perform g root side_effects =
+let puppet_data_log_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ <> "windows" then (
let paths = [ "/var/log/puppet/*";
diff --git a/sysprep/sysprep_operation_rh_subscription_manager.ml b/sysprep/sysprep_operation_rh_subscription_manager.ml
index d6c38b2..443feac 100644
--- a/sysprep/sysprep_operation_rh_subscription_manager.ml
+++ b/sysprep/sysprep_operation_rh_subscription_manager.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let rh_subscription_manager_perform g root side_effects =
+let rh_subscription_manager_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
let distro = g#inspect_get_distro root in
diff --git a/sysprep/sysprep_operation_rpm_db.ml b/sysprep/sysprep_operation_rpm_db.ml
index 55e50fe..81190e0 100644
--- a/sysprep/sysprep_operation_rpm_db.ml
+++ b/sysprep/sysprep_operation_rpm_db.ml
@@ -22,7 +22,7 @@ open Common_gettext.Gettext
module StringSet = Set.Make (String)
module G = Guestfs
-let rpm_db_perform g root side_effects =
+let rpm_db_perform (g : Guestfs.guestfs) root side_effects =
let pf = g#inspect_get_package_format root in
if pf = "rpm" then (
let paths = g#glob_expand "/var/lib/rpm/__db.*" in
diff --git a/sysprep/sysprep_operation_samba_db_log.ml b/sysprep/sysprep_operation_samba_db_log.ml
index 126a7ac..19fdbf4 100644
--- a/sysprep/sysprep_operation_samba_db_log.ml
+++ b/sysprep/sysprep_operation_samba_db_log.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let samba_db_log_perform g root side_effects =
+let samba_db_log_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ <> "windows" then (
let paths = [ "/var/log/samba/old/*";
diff --git a/sysprep/sysprep_operation_ssh_hostkeys.ml b/sysprep/sysprep_operation_ssh_hostkeys.ml
index 417e792..fbbf4a6 100644
--- a/sysprep/sysprep_operation_ssh_hostkeys.ml
+++ b/sysprep/sysprep_operation_ssh_hostkeys.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let ssh_hostkeys_perform g root side_effects =
+let ssh_hostkeys_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ <> "windows" then (
let files = g#glob_expand "/etc/ssh/*_host_*" in
diff --git a/sysprep/sysprep_operation_ssh_userdir.ml b/sysprep/sysprep_operation_ssh_userdir.ml
index 19f8890..2ff9581 100644
--- a/sysprep/sysprep_operation_ssh_userdir.ml
+++ b/sysprep/sysprep_operation_ssh_userdir.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let ssh_userdir_perform g root side_effects =
+let ssh_userdir_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ <> "windows" then (
let dirs = g#glob_expand "/home/*/.ssh" in
diff --git a/sysprep/sysprep_operation_sssd_db_log.ml b/sysprep/sysprep_operation_sssd_db_log.ml
index 8f1bc88..9e35679 100644
--- a/sysprep/sysprep_operation_sssd_db_log.ml
+++ b/sysprep/sysprep_operation_sssd_db_log.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let sssd_db_log_perform g root side_effects =
+let sssd_db_log_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ <> "windows" then (
let paths = [ "/var/log/sssd/*";
diff --git a/sysprep/sysprep_operation_tmp_files.ml b/sysprep/sysprep_operation_tmp_files.ml
index af600db..1892d63 100644
--- a/sysprep/sysprep_operation_tmp_files.ml
+++ b/sysprep/sysprep_operation_tmp_files.ml
@@ -21,7 +21,7 @@ open Common_gettext.Gettext
module G = Guestfs
-let tmp_files_perform g root side_effects =
+let tmp_files_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ <> "windows" then (
let paths = [ "/tmp";
--
2.5.0
8 years, 10 months
[PATCH 1/2] daemon: glob: do not return directories with trailing slash
by Pino Toscano
Do not pass GLOB_MARK as flag for glob(3) in the daemon implementation
of glob, so names of directories will not have a trailing slash.
This allows users to have filenames that can be used with other tools,
such as rm. Add a new test to check this (based on RHBZ#1293271).
A mild behaviour change is that users of the glob API now need to append
the slash when building paths using its results. The test-glob.sh test
of guestfish is adapted to this.
Related to RHBZ#1293271.
---
daemon/glob.c | 2 +-
fish/test-glob.sh | 2 +-
tests/regressions/Makefile.am | 2 ++
tests/regressions/rhbz1293271.sh | 70 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 74 insertions(+), 2 deletions(-)
create mode 100755 tests/regressions/rhbz1293271.sh
diff --git a/daemon/glob.c b/daemon/glob.c
index 45fb30f..0e646bd 100644
--- a/daemon/glob.c
+++ b/daemon/glob.c
@@ -33,7 +33,7 @@ do_glob_expand (const char *pattern)
/* glob(3) in glibc never calls chdir, so this seems to be safe: */
CHROOT_IN;
- r = glob (pattern, GLOB_MARK|GLOB_BRACE, NULL, &buf);
+ r = glob (pattern, GLOB_BRACE, NULL, &buf);
CHROOT_OUT;
if (r == GLOB_NOMATCH) { /* Return an empty list instead of an error. */
diff --git a/fish/test-glob.sh b/fish/test-glob.sh
index c520319..854d898 100755
--- a/fish/test-glob.sh
+++ b/fish/test-glob.sh
@@ -64,7 +64,7 @@ echo end
EOF
if [ "$(cat test-glob.out)" != "files
-/foo/
+/foo
/foo/bar1
/foo/bar2
/foo/not*
diff --git a/tests/regressions/Makefile.am b/tests/regressions/Makefile.am
index 3aae57b..27ad118 100644
--- a/tests/regressions/Makefile.am
+++ b/tests/regressions/Makefile.am
@@ -48,6 +48,7 @@ EXTRA_DIST = \
rhbz1232192.sh \
rhbz1232192.xml \
rhbz1285847.sh \
+ rhbz1293271.sh \
test-noexec-stack.pl
TESTS = \
@@ -77,6 +78,7 @@ TESTS = \
rhbz1175196.sh \
rhbz1232192.sh \
rhbz1285847.sh \
+ rhbz1293271.sh \
test-big-heap \
test-noexec-stack.pl
diff --git a/tests/regressions/rhbz1293271.sh b/tests/regressions/rhbz1293271.sh
new file mode 100755
index 0000000..bbd334e
--- /dev/null
+++ b/tests/regressions/rhbz1293271.sh
@@ -0,0 +1,70 @@
+#!/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.
+
+# Regression test for:
+# https://bugzilla.redhat.com/show_bug.cgi?id=1293271
+# rm-rf does not remove symlinks to directories
+
+set -e
+export LANG=C
+
+if [ -n "$SKIP_TEST_RHBZ1293271_SH" ]; then
+ echo "$0: test skipped because environment variable is set."
+ exit 77
+fi
+
+rm -f rhbz1293271.img rhbz1293271.out
+
+guestfish -N rhbz1293271.img=fs -m /dev/sda1 > rhbz1293271.out <<EOF
+touch /hello
+touch /test-file
+touch /world
+mkdir /somedir
+touch /somedir/file
+ln-s somedir /test-link
+
+ls / | sort
+
+echo -----
+
+glob rm-rf /*test*
+
+ls / | sort
+
+echo ----- END
+
+EOF
+
+if [ "$(cat rhbz1293271.out)" != "hello
+lost+found
+somedir
+test-file
+test-link
+world
+-----
+hello
+lost+found
+somedir
+world
+----- END" ]; then
+ echo "$0: unexpected output:"
+ cat rhbz1293271.out
+ exit 1
+fi
+
+rm rhbz1293271.img rhbz1293271.out
--
2.5.0
8 years, 10 months
[PATCH] generator: simplify generated code for always-available features
by Pino Toscano
Just refer to the dummy function directly, instead of using #define's.
---
generator/daemon.ml | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/generator/daemon.ml b/generator/daemon.ml
index 7ffea7b..d1689e1 100644
--- a/generator/daemon.ml
+++ b/generator/daemon.ml
@@ -732,19 +732,15 @@ and generate_daemon_optgroups_c () =
pr " return 1;\n";
pr "}\n";
pr "\n";
-
- List.iter (
- fun group ->
- pr "#define optgroup_%s_available dummy_available\n" group;
- ) optgroups_retired;
-
- pr "\n";
);
pr "struct optgroup optgroups[] = {\n";
List.iter (
fun group ->
- pr " { \"%s\", optgroup_%s_available },\n" group group
+ if List.mem group optgroups_retired then
+ pr " { \"%s\", dummy_available },\n" group
+ else
+ pr " { \"%s\", optgroup_%s_available },\n" group group
) optgroups_names_all;
pr " { NULL, NULL }\n";
pr "};\n"
--
2.5.0
8 years, 10 months
[PATCH 1/3] launch: add internal helper for socket paths creation
by Pino Toscano
Introduce an internal helper to create paths for sockets; will be useful
for changing later the logic for placing sockets.
---
src/guestfs-internal.h | 1 +
src/launch-direct.c | 4 +++-
src/launch-libvirt.c | 10 ++++++----
src/launch.c | 15 +++++++++++++++
4 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 5ecd322..bff9f64 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -782,6 +782,7 @@ extern void guestfs_int_launch_send_progress (guestfs_h *g, int perdozen);
extern char *guestfs_int_appliance_command_line (guestfs_h *g, const char *appliance_dev, int flags);
#define APPLIANCE_COMMAND_LINE_IS_TCG 1
const char *guestfs_int_get_cpu_model (int kvm);
+int guestfs_int_create_socketname (guestfs_h *g, const char *filename, char (*sockname)[UNIX_PATH_MAX]);
extern void guestfs_int_register_backend (const char *name, const struct backend_ops *);
extern int guestfs_int_set_backend (guestfs_h *g, const char *method);
diff --git a/src/launch-direct.c b/src/launch-direct.c
index b8e453d..a81d4b3 100644
--- a/src/launch-direct.c
+++ b/src/launch-direct.c
@@ -295,7 +295,9 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
/* Using virtio-serial, we need to create a local Unix domain socket
* for qemu to connect to.
*/
- snprintf (data->guestfsd_sock, sizeof data->guestfsd_sock, "%s/guestfsd.sock", g->tmpdir);
+ if (guestfs_int_create_socketname (g, "guestfsd.sock",
+ &data->guestfsd_sock) == -1)
+ goto cleanup0;
daemon_accept_sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
if (daemon_accept_sock == -1) {
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
index 8a5d93e..376bd80 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -395,8 +395,9 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
/* Using virtio-serial, we need to create a local Unix domain socket
* for qemu to connect to.
*/
- snprintf (data->guestfsd_path, sizeof data->guestfsd_path,
- "%s/guestfsd.sock", g->tmpdir);
+ if (guestfs_int_create_socketname (g, "guestfsd.sock",
+ &data->guestfsd_path) == -1)
+ goto cleanup;
set_socket_create_context (g);
@@ -421,8 +422,9 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri)
}
/* For the serial console. */
- snprintf (data->console_path, sizeof data->console_path,
- "%s/console.sock", g->tmpdir);
+ if (guestfs_int_create_socketname (g, "console.sock",
+ &data->console_path) == -1)
+ goto cleanup;
console_sock = socket (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
if (console_sock == -1) {
diff --git a/src/launch.c b/src/launch.c
index f59818f..ec061e3 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -418,6 +418,21 @@ guestfs_int_get_cpu_model (int kvm)
#endif
}
+/* Create the path for a socket with the selected filename in the
+ * tmpdir.
+ */
+int
+guestfs_int_create_socketname (guestfs_h *g, const char *filename,
+ char (*sockpath)[UNIX_PATH_MAX])
+{
+ char *path = g->tmpdir;
+
+ snprintf (*sockpath, UNIX_PATH_MAX-1, "%s/%s", path, filename);
+ (*sockpath)[UNIX_PATH_MAX-1] = '\0';
+
+ return 0;
+}
+
/* glibc documents, but does not actually implement, a 'getumask(3)'
* call. This implements a thread-safe way to get the umask. Note
* this is only called when g->verbose is true and after g->tmpdir
--
2.5.0
8 years, 10 months
virsh, virt-filesystems, guestmount, virt-install not working well with ceph rbd yet?
by Jelle de Jong
Hello everybody,
This is a cross post to libvirt-users, libguestfs and ceph-users.
I came back from FOSDEM 2016 and this was my 7th year or so and seen the
awesome development around visualization going on and want to thank
everybody for there contributions.
I seen presentations from oVirt, OpenStack and quite a few great Redhat
people, just like the last previous years.
I personally been supporting Linux-HA (pacemaker) DRBD/iSCSI/KVM
platform for years now and last year I started supporting Ceph RBD
clusters with KVM hosts.
But I keep hitting some “pains” and I been wondering why they have not
been solved and how I can best request help around this?
Tools that don't seem to fully work with Ceph RBD yet:
- virsh snapshot-create --quiesce --disk-only $quest
- virt-filesystems ${array_volume[@]}
- guestmount --ro ${array_volume[@]} -m $mount /mnt/$name-$disk
- virt-install also doesn't have Ceph RBD and I currently use virsh edit
to add the RBD storage disks.
My request is to get these tools working as well with Ceph RBD and maybe
not only integrate oVirt or OpenStack alike systems. I use several types
of back-up strategies depending on the size on the data storage use. I
am not sure how oVirt and alike create secure encrypted incremental
off-site back-ups of large data sets but I use(d) combinations of
rdiff-backup, duplicity and full guest dumps with dd, rbd export, xz.
Are these issues known and important enough, roadmap, bug reports?
Should I start working for Redhat as I don't have the resources myself,
but I can help with some money towards a crowed fund or bounty.
Maybe my software is outdated?
virsh 1.2.9
ceph version 0.80.10
libguestfs-tools 1:1.28.1-1
3.16.7-ckt20-1+deb8u2
My current workarounds for full storage exports:
virsh domfsfreeze $quest
sleep 2
virsh domblklist $quest
rbd snap create --snap snapshot $blkdevice
virsh domfsthaw $quest
rbd export $blkdevice@snapshot - | xz -1 | ssh -p 222 $user@$server "dd
of=/$location/$blkdevice$snapshot-$daystamp.dd.disk.gz"
rbd snap rm $blkdevice@snapshot
Kind regards,
Jelle de Jong
irc: #tuxcrafter
8 years, 10 months
[PATCH 1/6] launch: unix: check for length of sockets
by Pino Toscano
Error out early if the path to the socket will not fit into
sockaddr_un::sun_path, as we will not be able to connect to it.
---
src/launch-unix.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/launch-unix.c b/src/launch-unix.c
index 740c554..973e14b 100644
--- a/src/launch-unix.c
+++ b/src/launch-unix.c
@@ -47,6 +47,12 @@ launch_unix (guestfs_h *g, void *datav, const char *sockpath)
return -1;
}
+ if (strlen (sockpath) > UNIX_PATH_MAX-1) {
+ error (g, _("socket filename too long (more than %d characters): %s"),
+ UNIX_PATH_MAX-1, sockpath);
+ return -1;
+ }
+
if (g->verbose)
guestfs_int_print_timestamped_message (g, "connecting to %s", sockpath);
--
2.5.0
8 years, 10 months