Bug 895904 - checksums-out fail to compute the checksums of all regular files in directory
Summary: checksums-out fail to compute the checksums of all regular files in directory
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Virtualization Tools
Classification: Community
Component: libguestfs
Version: unspecified
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: ---
Assignee: Richard W.M. Jones
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks: 892275
TreeView+ depends on / blocked
 
Reported: 2013-01-16 09:06 UTC by Richard W.M. Jones
Modified: 2013-01-21 11:15 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of: 892275
Environment:
Last Closed: 2013-01-21 11:15:50 UTC
Embargoed:


Attachments (Terms of Use)

Description Richard W.M. Jones 2013-01-16 09:06:13 UTC
+++ This bug was initially created as a clone of Bug #892275 +++

Description of problem:

checksums-out fail to compute the checksums of all regular files in directo
ry, but the checksum works fine,

><fs> checksums-out crc /test  file
libguestfs: trace: checksums_out "crc" "/test" "file"
libguestfs: send_to_daemon: 64 bytes: 00 00 00 3c | 20 00 f5 f5 | 00 00 00 =
04 | 00 00 00 f4 | 00 00 00 0
0 | ...
guestfsd: main_loop: new request, len 0x3c
cd find && xargs -type f -print0 | /sysroot/testDescription of problem:

libguestfs: recv_from_daemon: 40 bytes: 20 00 f5 f5 | 00 00 00 04 | 00 00 0=
0 f4 | 00 00 00 01 | 00 12 34
 05 | ...
sh: line 0: cd: find: No such file or directory
/test: Success
guestfsd: main_loop: proc 244 (checksums_out) took 0.00 seconds
libguestfs: recv_from_daemon: 8 bytes: 00 00 00 01 | 00 00 00 00 |
libguestfs: error: file receive cancelled by daemon
libguestfs: error: file: error in chunked encoding
libguestfs: trace: checksums_out =3D -1 (error)


the folder test is like below,

><fs> ls /test
libguestfs: trace: ls =3D ["file_ascii", "subdir"]
file_ascii
subdir




Version-Release number of selected component (if applicable):
libguestfs-1.20.1-4.el7.x86_64

How reproducible:
always

Steps to Reproduce:
1. prepare some file like above
2.  checksums-out crc /test  file
3.
 
Actual results:


Expected results:


Additional info:

Comment 1 Richard W.M. Jones 2013-01-21 10:57:23 UTC
A one line reproducer is:

  $ guestfish -N fs -m /dev/sda1 -- mkdir /test : touch /test/file : mkdir /test/subdir : checksums-out crc /test -
  libguestfs: error: file receive cancelled by daemon
  libguestfs: error: /dev/stdout: error in chunked encoding

Adding the -v option shows that we're running a completely
bogus command:

  cd find && xargs -type f -print0 | /sysroot/test -0 cksum
  sh: line 0: cd: find: No such file or directory
  /test: Success

(where did 'cd find' come from ...?)

Comment 2 Richard W.M. Jones 2013-01-21 10:59:54 UTC
The problem is this hunk which is bogus.  (The other problem
being that we have no test that covers this.)

commit 0306c98d319d189281af3c15101c8d343e400f13
Author: Olaf Hering <olaf>
Date:   Thu Aug 30 20:51:27 2012 +0200

    daemon: collect list of called external commands
    
    guestfsd calls many different tools. Keeping track of all of them is
    error prone. This patch introduces a new helper macro to put the command
    string into its own ELF section:
    
    GUESTFSD_EXT_CMD(C_variable, command_name);
    
    This syntax makes it still possible to grep for used command names.
    
    The actual usage of the collected list could be like this:
    
      objcopy -j .guestfsd_ext_cmds -O binary daemon/guestfsd /dev/stdout |
      tr '\0' '\n' | sort -u
    
    The resulting output will be used to tell mkinitrd which programs to
    copy into the initrd.
    
    Signed-off-by: Olaf Hering <olaf>
    
    RWMJ:
     - Move str_vgchange at request of author.
     - Fix snprintf call in daemon/debug.c

[...]
diff --git a/daemon/checksum.c b/daemon/checksum.c
index 2cc4a2b..f2e040d 100644
--- a/daemon/checksum.c
+++ b/daemon/checksum.c
@@ -150,7 +153,8 @@ do_checksums_out (const char *csumtype, const char *dir)
   }
 
   char *cmd;
-  if (asprintf_nowarn (&cmd, "cd %Q && find -type f -print0 | xargs -0 %s",
+  if (asprintf_nowarn (&cmd, "cd %Q && %s -type f -print0 | %s -0 %s",
+                       str_find, str_xargs,
                        sysrootdir, program) == -1) {
     reply_with_perror ("asprintf");
     free (sysrootdir);

Comment 3 Richard W.M. Jones 2013-01-21 11:15:50 UTC
Fixed upstream + regression test:
https://github.com/libguestfs/libguestfs/commit/ebc86ae6d76bab3e09484a039ddffcb323a106a3


Note You need to log in before you can comment on or make changes to this bug.