adding a new log-format escape

Andrew Shewmaker agshew at gmail.com
Mon Jun 27 06:07:19 GMT 2005


I'm adding a new escape to log-format, %s, to print out the checksum
of a file, and I've got  a couple problems.  They've got to be simple
bugs, but I haven't been able to figure them out.  The following patch
gives me a broken pipe and a bus error when I test it.  Note that I've
applied the md5 patch beforehand.

diff -Naur rsync-2.6.5-md5/log.c rsync-2.6.5/log.c
--- rsync-2.6.5-md5/log.c       2005-06-26 22:34:17.000000000 -0600
+++ rsync-2.6.5/log.c   2005-06-26 22:38:57.000000000 -0600
@@ -371,7 +371,7 @@
        char buf[MAXPATHLEN+1024], buf2[MAXPATHLEN], fmt[32];
        char *p, *s, *n;
        size_t len, total;
-       int64 b;
+       int64 b, j;
 
        *fmt = '%';
 
@@ -483,6 +483,13 @@
                        snprintf(buf2, sizeof buf2, fmt, (double)b);
                        n = buf2;
                        break;
+               case 's':
+                       strlcat(fmt, "02x", sizeof fmt);
+                       for (j = 0; j < SUM_LENGTH; j++ ) {
+                               snprintf(buf2 + j * 2, sizeof buf2,
fmt, file->u.sum[j]);
+                       }
+                       n = buf2;
+                       break;
                case 'i':
                        if (iflags & ITEM_DELETED) {
                                n = "*deleting";

$ rsync -acv --md5 --log-format="%c %s  %f" rsync-2.6.5 blah
building file list ... done
created directory blah
rsync: writefd_unbuffered failed to write 82 bytes: phase "unknown"
[generator]: Broken pipe (32)
rsync error: error in rsync protocol data stream (code 12) at io.c(1099)
Bus error

I get the same error if I replace SUM_LENGTH with a literal 16. 
Interestingly, when I reuse the code to calculate the number of
checksum bytes received for the file, I don't get an error.

diff -Naur rsync-2.6.5-md5/log.c rsync-2.6.5/log.c
--- rsync-2.6.5-md5/log.c       2005-06-26 22:34:17.000000000 -0600
+++ rsync-2.6.5/log.c   2005-06-26 22:17:12.000000000 -0600
@@ -371,7 +371,7 @@
        char buf[MAXPATHLEN+1024], buf2[MAXPATHLEN], fmt[32];
        char *p, *s, *n;
        size_t len, total;
-       int64 b;
+       int64 b, j;
 
        *fmt = '%';
 
@@ -483,6 +483,20 @@
                        snprintf(buf2, sizeof buf2, fmt, (double)b);
                        n = buf2;
                        break;
+               case 's':
+                       if (!am_sender) {
+                               b = stats.total_written -
+                                       initial_stats->total_written;
+                       } else {
+                               b = stats.total_read -
+                                       initial_stats->total_read;
+                       }
+                       strlcat(fmt, "02x", sizeof fmt);
+                       for (j = 0; j < b; j++ ) {
+                               snprintf(buf2 + j * 2, sizeof buf2,
fmt, file->u.sum[j]);
+                       }
+                       n = buf2;
+                       break;
                case 'i':
                        if (iflags & ITEM_DELETED) {
                                n = "*deleting";

$ rsync -acv --md5 --log-format="%c %s  %f" rsync-2.6.5 blah
building file list ... done
created directory blah
0 0  rsync-2.6.5
16 5709ff6fff66ffff2aff296830ffff2f  rsync-2.6.5/.ignore
16 393a5cff45ffff5873ffff25ff17ff33  rsync-2.6.5/COPYING
16 ffffff3dffff3322ffffffffff7aff77  rsync-2.6.5/Doxyfile
16 ffffff241c784fff274638ff4effffffffff96  rsync-2.6.5/INSTALL
16 ffffff013effffffff6c15ffffff700b  rsync-2.6.5/Makefile
16 6360ffff4d43ffff21ff18ffff3622fffffff4  rsync-2.6.5/Makefile.in
...

As you can see the number of checksum bytes is always 16 for files and
I don't get any errors like I do above.  However, the checksums are
wrong (I can see short segments that are right).  They don't match the
output from md5sum nor the test program in md5.c, which prints the hex
string in nearly the same way.  Also, some of the hex strings are
longer than others even though they have the same number of checksum
bytes.

Any ideas what I'm doing wrong?

BTW, this behaves the same on OS X Tiger w/ GCC 4.0 and Fedora Core 1 x86.

Thanks in advance for any help,


Andrew Shewmaker


More information about the rsync mailing list