summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ChangeLog16
-rw-r--r--INSTALL2
-rw-r--r--Makefile.in11
-rw-r--r--NEWS5
-rwxr-xr-xconfigure4
-rw-r--r--doc/zcat.12
-rw-r--r--doc/zcmp.12
-rw-r--r--doc/zdiff.12
-rw-r--r--doc/zgrep.12
-rw-r--r--doc/ztest.12
-rw-r--r--doc/zutils.info18
-rw-r--r--doc/zutils.texinfo6
-rw-r--r--main.cc1
-rwxr-xr-xtestsuite/check.sh51
-rw-r--r--testsuite/test.txt.tarbin0 -> 40960 bytes
-rw-r--r--zcat.cc4
-rw-r--r--zcmp.cc14
-rw-r--r--zgrep.cc18
-rw-r--r--ztest.cc34
-rw-r--r--zutils.cc7
-rw-r--r--zutils.h3
21 files changed, 133 insertions, 71 deletions
diff --git a/ChangeLog b/ChangeLog
index 681e746..9105618 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,12 +1,18 @@
+2010-12-05 Antonio Diaz Diaz <ant_diaz@teleline.es>
+
+ * Version 0.9-rc2 released.
+ * zcmp.cc: Fixed deadlock when files differ.
+ * zgrep.cc: Fixed deadlock when binary file matches.
+
2010-11-20 Antonio Diaz Diaz <ant_diaz@teleline.es>
* Version 0.9-rc1 released.
- * configure: Added new options "DIFF" and "GREP".
+ * configure: Added new options `DIFF' and `GREP'.
2010-11-15 Antonio Diaz Diaz <ant_diaz@teleline.es>
* Version 0.8 released.
- * main.cc: Added new options "--zcat", "--zgrep" and "--ztest".
+ * main.cc: Added new options `--zcat', `--zgrep' and `--ztest'.
* zcat.cc: New file implementing zcat+cat functionality in C++.
* zcmp.cc: New file implementing zcmp+cmp functionality in C++.
* doc/zcmp.1: New file.
@@ -18,7 +24,7 @@
documentation because egrep and fgrep are deprecated.
* ztest.cc: New file implementing ztest functionality in C++.
* Makefile.in: Added quotes to directory names.
- * testsuite/check.sh: Use "test.txt" instead of "COPYING" for testing.
+ * testsuite/check.sh: Use `test.txt' instead of `COPYING' for testing.
* Removed environment safeguards from configure as requested by
Richard Stallman. Now environment variables affect configure.
@@ -26,14 +32,14 @@
* Version 0.7 released.
* Added new utility; ztest.
- * zcat.in: Added new option "--recursive".
+ * zcat.in: Added new option `--recursive'.
2009-10-05 Antonio Diaz Diaz <ant_diaz@teleline.es>
* Version 0.6 released.
* zcat.in, zgrep.in: Removed again default compressor. Format of
data read from stdin is now automatically detected.
- * Makefile.in: Added "--name" option to help2man invocation.
+ * Makefile.in: Added `--name' option to help2man invocation.
2009-10-01 Antonio Diaz Diaz <ant_diaz@teleline.es>
diff --git a/INSTALL b/INSTALL
index 9c7b683..f6350dd 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,7 +1,7 @@
Requirements
------------
You will need a C++ compiler.
-I use gcc 4.3.4 and 3.3.6, but the code should compile with any
+I use gcc 4.3.5 and 3.3.6, but the code should compile with any
standards compliant compiler.
Gcc is available at http://gcc.gnu.org.
diff --git a/Makefile.in b/Makefile.in
index 2fc8ccb..cb987ca 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -26,7 +26,7 @@ $(progname)_profiled : $(objs)
$(CXX) $(LDFLAGS) -pg -o $@ $(objs)
zcat : zcat.in
- cat $(VPATH)/zcat.in > zcat
+ cat $(VPATH)/zcat.in > $@
chmod a+x zcat
zcmp : $(zcmp_objs)
@@ -36,19 +36,19 @@ zdiff : $(zdiff_objs)
$(CXX) $(LDFLAGS) -o $@ $(zdiff_objs)
zegrep : zegrep.in
- cat $(VPATH)/zegrep.in > zegrep
+ cat $(VPATH)/zegrep.in > $@
chmod a+x zegrep
zfgrep : zfgrep.in
- cat $(VPATH)/zfgrep.in > zfgrep
+ cat $(VPATH)/zfgrep.in > $@
chmod a+x zfgrep
zgrep : zgrep.in
- cat $(VPATH)/zgrep.in > zgrep
+ cat $(VPATH)/zgrep.in > $@
chmod a+x zgrep
ztest : ztest.in
- cat $(VPATH)/ztest.in > ztest
+ cat $(VPATH)/ztest.in > $@
chmod a+x ztest
main.o : main.cc
@@ -175,6 +175,7 @@ dist : doc
$(DISTNAME)/doc/$(pkgname).texinfo \
$(DISTNAME)/testsuite/check.sh \
$(DISTNAME)/testsuite/test.txt \
+ $(DISTNAME)/testsuite/test.txt.tar \
$(DISTNAME)/*.h \
$(DISTNAME)/*.cc \
$(DISTNAME)/z*.in
diff --git a/NEWS b/NEWS
index 16d3c00..7d896a7 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
Changes in version 0.9:
Configure now allows the selection of diff and grep programs to use.
+
+A deadlock in zcmp.cc, which happened when files differ, has been fixed.
+
+A deadlock in zgrep.cc, which happened when a binary file matches, has
+been fixed.
diff --git a/configure b/configure
index 4d3753c..0f0b82e 100755
--- a/configure
+++ b/configure
@@ -5,12 +5,12 @@
# This configure script is free software: you have unlimited permission
# to copy, distribute and modify it.
#
-# Date of this version: 2010-11-20
+# Date of this version: 2010-12-05
args=
no_create=
pkgname=zutils
-pkgversion=0.9-rc1
+pkgversion=0.9-rc2
progname=zutils
srctrigger=zutils.h
diff --git a/doc/zcat.1 b/doc/zcat.1
index be5d381..efa2fcb 100644
--- a/doc/zcat.1
+++ b/doc/zcat.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
-.TH ZCAT "1" "November 2010" "Zcat (zutils) 0.9-rc1" "User Commands"
+.TH ZCAT "1" "December 2010" "Zcat (zutils) 0.9-rc2" "User Commands"
.SH NAME
Zcat \- decompress and concatenate files to standard output
.SH SYNOPSIS
diff --git a/doc/zcmp.1 b/doc/zcmp.1
index f1e8472..6098ec2 100644
--- a/doc/zcmp.1
+++ b/doc/zcmp.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
-.TH ZCMP "1" "November 2010" "Zcmp (zutils) 0.9-rc1" "User Commands"
+.TH ZCMP "1" "December 2010" "Zcmp (zutils) 0.9-rc2" "User Commands"
.SH NAME
Zcmp \- decompress and compare two files byte by byte
.SH SYNOPSIS
diff --git a/doc/zdiff.1 b/doc/zdiff.1
index 6ed05de..7d1c747 100644
--- a/doc/zdiff.1
+++ b/doc/zdiff.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
-.TH ZDIFF "1" "November 2010" "Zdiff (zutils) 0.9-rc1" "User Commands"
+.TH ZDIFF "1" "December 2010" "Zdiff (zutils) 0.9-rc2" "User Commands"
.SH NAME
Zdiff \- decompress and compare two files line by line
.SH SYNOPSIS
diff --git a/doc/zgrep.1 b/doc/zgrep.1
index 2ec43dc..233c433 100644
--- a/doc/zgrep.1
+++ b/doc/zgrep.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
-.TH ZGREP "1" "November 2010" "Zgrep (zutils) 0.9-rc1" "User Commands"
+.TH ZGREP "1" "December 2010" "Zgrep (zutils) 0.9-rc2" "User Commands"
.SH NAME
Zgrep \- search compressed files for a regular expression
.SH SYNOPSIS
diff --git a/doc/ztest.1 b/doc/ztest.1
index 8db8692..97f5916 100644
--- a/doc/ztest.1
+++ b/doc/ztest.1
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
-.TH ZTEST "1" "November 2010" "Ztest (zutils) 0.9-rc1" "User Commands"
+.TH ZTEST "1" "December 2010" "Ztest (zutils) 0.9-rc2" "User Commands"
.SH NAME
Ztest \- verify integrity of compressed files
.SH SYNOPSIS
diff --git a/doc/zutils.info b/doc/zutils.info
index 38e6746..910d140 100644
--- a/doc/zutils.info
+++ b/doc/zutils.info
@@ -12,7 +12,7 @@ File: zutils.info, Node: Top, Next: Introduction, Up: (dir)
Zutils Manual
*************
-This manual is for Zutils (version 0.9-rc1, 20 November 2010).
+This manual is for Zutils (version 0.9-rc2, 5 December 2010).
* Menu:
@@ -531,13 +531,13 @@ Concept Index

Tag Table:
Node: Top224
-Node: Introduction991
-Node: Zcat2446
-Node: Zcmp4330
-Node: Zdiff6387
-Node: Zgrep8624
-Node: Ztest11391
-Node: Problems12474
-Node: Concept Index13003
+Node: Introduction990
+Node: Zcat2445
+Node: Zcmp4329
+Node: Zdiff6386
+Node: Zgrep8623
+Node: Ztest11390
+Node: Problems12473
+Node: Concept Index13002

End Tag Table
diff --git a/doc/zutils.texinfo b/doc/zutils.texinfo
index dbae4bb..7121f1d 100644
--- a/doc/zutils.texinfo
+++ b/doc/zutils.texinfo
@@ -5,8 +5,8 @@
@finalout
@c %**end of header
-@set UPDATED 20 November 2010
-@set VERSION 0.9-rc1
+@set UPDATED 5 December 2010
+@set VERSION 0.9-rc2
@dircategory Data Compression
@direntry
@@ -14,6 +14,7 @@
@end direntry
+@ifnothtml
@titlepage
@title Zutils
@subtitle Utilities dealing with compressed files
@@ -24,7 +25,6 @@
@vskip 0pt plus 1filll
@end titlepage
-@ifnothtml
@contents
@end ifnothtml
diff --git a/main.cc b/main.cc
index 56cbf06..d752489 100644
--- a/main.cc
+++ b/main.cc
@@ -19,6 +19,7 @@
#include <cerrno>
#include <climits>
+#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <cstring>
diff --git a/testsuite/check.sh b/testsuite/check.sh
index 073843e..c32c3fe 100755
--- a/testsuite/check.sh
+++ b/testsuite/check.sh
@@ -37,6 +37,9 @@ done
printf "testing zutils-%s..." "$2"
cat "${testdir}"/test.txt > in || framework_failure
+cat "${testdir}"/test.txt.tar > in.tar || framework_failure
+printf "01234567890" > pin.tar || framework_failure
+cat in.tar in.tar in.tar in.tar >> pin.tar || framework_failure
cat in > -in- || framework_failure
cat in.lz > -in-.lz || framework_failure
cat in.lz > lz_only.lz || framework_failure
@@ -84,6 +87,8 @@ for i in ${extensions}; do
printf .
done
+"${ZCMP}" in.tar pin.tar > /dev/null
+if [ $? != 1 ] ; then fail=1 ; printf - ; else printf . ; fi
"${ZCMP}" - || fail=1
printf .
"${ZCMP}" in in || fail=1
@@ -130,6 +135,8 @@ for i in ${extensions}; do
printf .
done
+#"${ZDIFF}" in.tar pin.tar > /dev/null
+#if [ $? != 1 ] ; then fail=1 ; printf - ; else printf . ; fi
"${ZDIFF}" - || fail=1
printf .
"${ZDIFF}" in in || fail=1
@@ -168,44 +175,56 @@ printf .
printf "\ntesting zgrep-%s..." "$2"
for i in ${extensions}; do
- "${ZGREP}" License in.$i > /dev/null || fail=1
- "${ZGREP}" nx_pattern in.$i > /dev/null && fail=1
+ "${ZGREP}" "GNU" in.$i > /dev/null || fail=1
+ "${ZGREP}" "nx_pattern" in.$i > /dev/null && fail=1
printf .
done
-"${ZGREP}" -r License . > /dev/null || fail=1
+"${ZGREP}" "GNU" < pin.tar > /dev/null || fail=1
printf .
-"${ZGREP}" nx_pattern -r . in > /dev/null && fail=1
+"${ZGREP}" "GNU" pin.tar > /dev/null || fail=1
printf .
-"${ZGREP}" License < in > /dev/null || fail=1
+"${ZGREP}" -r "GNU" . > /dev/null || fail=1
printf .
-"${ZGREP}" License < in.gz > /dev/null || fail=1
+"${ZGREP}" "nx_pattern" -r . in > /dev/null && fail=1
printf .
-"${ZGREP}" License < in.bz2 > /dev/null || fail=1
+"${ZGREP}" "GNU" < in > /dev/null || fail=1
printf .
-"${ZGREP}" License < in.lz > /dev/null || fail=1
+"${ZGREP}" "GNU" < in.gz > /dev/null || fail=1
printf .
-"${ZGREP}" License in > /dev/null || fail=1
+"${ZGREP}" "GNU" < in.bz2 > /dev/null || fail=1
printf .
-"${ZGREP}" License -- -in- > /dev/null || fail=1
+"${ZGREP}" "GNU" < in.lz > /dev/null || fail=1
printf .
-"${ZGREP}" License -- -in-.lz > /dev/null || fail=1
+"${ZGREP}" "GNU" in > /dev/null || fail=1
printf .
-"${ZGREP}" License in in.gz in.bz2 in.lz -- -in- > /dev/null || fail=1
+"${ZGREP}" "GNU" -- -in- > /dev/null || fail=1
printf .
-"${ZEGREP}" License in > /dev/null || fail=1
+"${ZGREP}" "GNU" -- -in-.lz > /dev/null || fail=1
printf .
-"${ZFGREP}" License in > /dev/null || fail=1
+"${ZGREP}" "GNU" in in.gz in.bz2 in.lz -- -in- > /dev/null || fail=1
+printf .
+"${ZEGREP}" "GNU" in > /dev/null || fail=1
+printf .
+"${ZFGREP}" "GNU" in > /dev/null || fail=1
printf .
printf "\ntesting ztest-%s..." "$2"
"${ZTEST}" in in.gz in.bz2 in.lz -- -in- || fail=1
printf .
-"${ZTEST}" -r . || fail=1
+"${ZTEST}" < in.gz || fail=1
printf .
-printf "LZIPvs0000000000000000000000" | "${ZTEST}" 2>/dev/null && fail=1
+"${ZTEST}" < in.bz2 || fail=1
+printf .
+"${ZTEST}" < in.lz || fail=1
+printf .
+"${ZTEST}" -r . || fail=1
printf .
+"${ZTEST}" < in 2>/dev/null
+if [ $? = 0 ] ; then fail=1 ; printf - ; else printf . ; fi
+printf "LZIPvs0000000000000000000000" | "${ZTEST}" 2>/dev/null
+if [ $? = 0 ] ; then fail=1 ; printf - ; else printf . ; fi
echo
if [ ${fail} = 0 ] ; then
diff --git a/testsuite/test.txt.tar b/testsuite/test.txt.tar
new file mode 100644
index 0000000..4937a77
--- /dev/null
+++ b/testsuite/test.txt.tar
Binary files differ
diff --git a/zcat.cc b/zcat.cc
index 1ead9f4..cb29db9 100644
--- a/zcat.cc
+++ b/zcat.cc
@@ -198,13 +198,13 @@ int cat( int infd, const std::string & input_filename,
int retval = 0;
if( !set_data_feeder( &infd, &pid ) ) retval = 1;
else
- {
retval = do_cat( infd, buffer_size, inbuf, outbuf,
input_filename, cat_options );
+ if( retval == 0 )
if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 1;
+ if( retval == 0 )
if( close( infd ) != 0 )
{ show_close_error( "data feeder" ); retval = 1; }
- }
delete[] inbuf; delete[] outbuf;
return retval;
}
diff --git a/zcmp.cc b/zcmp.cc
index a2779b9..7951046 100644
--- a/zcmp.cc
+++ b/zcmp.cc
@@ -20,6 +20,7 @@
#include <cctype>
#include <cerrno>
#include <climits>
+#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <cstring>
@@ -469,10 +470,15 @@ int main( const int argc, const char * const argv[] )
int retval = cmp( max_size, infd, filenames, print_bytes );
- if( ( ( pid[0] && wait_for_child( pid[0], "data feeder" ) != 0 ) ||
- ( pid[1] && wait_for_child( pid[1], "data feeder" ) != 0 ) ) &&
- retval == 0 )
- retval = 2;
+ if( retval != 0 )
+ {
+ if( pid[0] ) kill( pid[0], SIGTERM );
+ if( pid[1] ) kill( pid[1], SIGTERM );
+ }
+ else
+ if( ( pid[0] && wait_for_child( pid[0], "data feeder" ) != 0 ) ||
+ ( pid[1] && wait_for_child( pid[1], "data feeder" ) != 0 ) )
+ retval = 2;
for( int i = 0; i < 2; ++i )
{
diff --git a/zgrep.cc b/zgrep.cc
index 41317a5..d0e69e3 100644
--- a/zgrep.cc
+++ b/zgrep.cc
@@ -84,9 +84,12 @@ int zgrep_stdin( int infd, const std::vector< const char * > & grep_args )
// parent
if( grep_pid < 0 )
{ show_fork_error( GREP ); return 2; }
- int retval = 0;
- if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2;
- if( wait_for_child( grep_pid, GREP ) != 0 ) retval = 2;
+
+ int retval = wait_for_child( grep_pid, GREP );
+ if( retval != 1 )
+ { if( pid ) kill( pid, SIGTERM ); }
+ else
+ if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2;
if( close( infd ) != 0 )
{ show_close_error( "data feeder" ); return 2; }
return retval;
@@ -146,9 +149,12 @@ int zgrep_file( int infd, const std::string & input_filename,
}
if( size < buffer_size ) break;
}
- int retval = 0;
- if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2;
- if( wait_for_child( grep_pid, GREP ) != 0 ) retval = 2;
+
+ int retval = wait_for_child( grep_pid, GREP );
+ if( retval != 1 )
+ { if( pid ) kill( pid, SIGTERM ); }
+ else
+ if( pid && wait_for_child( pid, "data feeder" ) != 0 ) retval = 2;
if( grep_list && retval == 0 )
std::printf( "%s\n", input_filename.c_str() );
if( close( infd ) != 0 )
diff --git a/ztest.cc b/ztest.cc
index 3672aa8..0193bfa 100644
--- a/ztest.cc
+++ b/ztest.cc
@@ -42,12 +42,12 @@ int ztest_stdin( const int infd,
int magic_size = 0;
if( !test_format( infd, file_type, &magic_data, &magic_size ) )
{ show_error( "Unknown data format read from stdin." ); return 2; }
- int fda[2];
+ int fda[2]; // pipe from feeder
if( pipe( fda ) < 0 )
{ show_error( "Can't create pipe", errno ); return 1; }
- const pid_t pid = fork();
- if( pid == 0 ) // child (decompressor)
+ const pid_t pid = fork();
+ if( pid == 0 ) // child1 (decompressor)
{
if( dup2( fda[0], STDIN_FILENO ) >= 0 &&
close( fda[0] ) == 0 && close( fda[1] ) == 0 )
@@ -66,11 +66,26 @@ int ztest_stdin( const int infd,
// parent
if( pid < 0 )
{ show_fork_error( file_type.c_str() ); return 1; }
- close( fda[0] );
- if( !feed_data( infd, fda[1], magic_data, magic_size ) ) return 1;
- if( close( fda[1] ) != 0 )
- { show_close_error( "data feeder" ); return 1; }
- return wait_for_child( pid, file_type.c_str() );
+
+ const pid_t pid2 = fork();
+ if( pid2 == 0 ) // child2 (decompressor feeder)
+ {
+ if( close( fda[0] ) != 0 ||
+ !feed_data( infd, fda[1], magic_data, magic_size ) )
+ _exit( 1 );
+ if( close( fda[1] ) != 0 )
+ { show_close_error( "decompressor feeder" ); _exit( 1 ); }
+ _exit( 0 );
+ }
+ // parent
+ if( pid2 < 0 )
+ { show_fork_error( "decompressor feeder" ); return 1; }
+
+ close( fda[0] ); close( fda[1] );
+ int retval = wait_for_child( pid, file_type.c_str(), 1 );
+ if( retval == 0 && wait_for_child( pid2, "decompressor feeder" ) != 0 )
+ retval = 1;
+ return retval;
}
@@ -101,5 +116,6 @@ int ztest_file( const int infd, const std::string & input_filename,
// parent
if( pid < 0 )
{ show_fork_error( file_type.c_str() ); return 1; }
- return wait_for_child( pid, file_type.c_str() );
+
+ return wait_for_child( pid, file_type.c_str(), 1 );
}
diff --git a/zutils.cc b/zutils.cc
index 01a0152..7b86c7d 100644
--- a/zutils.cc
+++ b/zutils.cc
@@ -305,7 +305,8 @@ bool test_format( const int infd, std::string & file_type,
}
-int wait_for_child( const pid_t pid, const char * const name )
+int wait_for_child( const pid_t pid, const char * const name,
+ const int eretval )
{
int status;
while( waitpid( pid, &status, 0 ) == -1 )
@@ -315,10 +316,10 @@ int wait_for_child( const pid_t pid, const char * const name )
if( verbosity >= 0 )
std::fprintf( stderr, "%s: Error waiting termination of `%s': %s.\n",
util_name, name, std::strerror( errno ) );
- _exit( 1 );
+ _exit( eretval );
}
}
if( WIFEXITED( status ) ) return WEXITSTATUS( status );
- else return 1;
+ return eretval;
}
diff --git a/zutils.h b/zutils.h
index 87eddca..5a2f167 100644
--- a/zutils.h
+++ b/zutils.h
@@ -54,4 +54,5 @@ void internal_error( const char * const msg );
bool test_format( const int infd, std::string & file_type,
const uint8_t ** magic_data, int * magic_sizep );
-int wait_for_child( const pid_t pid, const char * const name );
+int wait_for_child( const pid_t pid, const char * const name,
+ const int eretval = 2 );