summaryrefslogtreecommitdiffstats
path: root/list_lz.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2019-02-24 20:21:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2019-02-24 20:21:09 +0000
commit72abeec91e77c0d5b7e89d4731b2c7dcbbbbc87a (patch)
tree1dcb40a71bd451fffd591722799041b29cb2793d /list_lz.cc
parentAdding upstream version 0.11. (diff)
downloadtarlz-72abeec91e77c0d5b7e89d4731b2c7dcbbbbc87a.tar.xz
tarlz-72abeec91e77c0d5b7e89d4731b2c7dcbbbbc87a.zip
Adding upstream version 0.12.upstream/0.12
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'list_lz.cc')
-rw-r--r--list_lz.cc16
1 files changed, 9 insertions, 7 deletions
diff --git a/list_lz.cc b/list_lz.cc
index 23b6e7c..8e5f5fc 100644
--- a/list_lz.cc
+++ b/list_lz.cc
@@ -605,7 +605,7 @@ done:
/* Get from courier the processed and sorted packets, and print
the member lines on stdout or the diagnostics on stderr. */
-bool muxer( Packet_courier & courier )
+void muxer( Packet_courier & courier )
{
while( true )
{
@@ -613,15 +613,14 @@ bool muxer( Packet_courier & courier )
if( !opacket ) break; // queue is empty. all workers exited
if( opacket->status == Packet::error )
- { show_error( opacket->line.c_str() ); return false; }
+ { show_error( opacket->line.c_str() ); cleanup_and_fail( 2 ); }
if( opacket->line.size() )
{ std::fputs( opacket->line.c_str(), stdout );
std::fflush( stdout ); }
delete opacket;
}
if( !courier.mastership_granted() ) // no worker found EOF blocks
- { show_error( "Archive ends unexpectedly." ); return false; }
- return true;
+ { show_error( "Archive ends unexpectedly." ); cleanup_and_fail( 2 ); }
}
} // end namespace
@@ -634,6 +633,9 @@ int list_lz( const Arg_parser & parser, std::vector< char > & name_pending,
const bool missing_crc, const bool permissive )
{
const int out_slots = 65536; // max small files (<=512B) in 64 MiB
+
+ /* If an error happens after any threads have been started, exit must be
+ called before courier goes out of scope. */
Packet_courier courier( num_workers, out_slots );
Worker_arg * worker_args = new( std::nothrow ) Worker_arg[num_workers];
@@ -654,16 +656,16 @@ int list_lz( const Arg_parser & parser, std::vector< char > & name_pending,
const int errcode =
pthread_create( &worker_threads[i], 0, tworker, &worker_args[i] );
if( errcode )
- { show_error( "Can't create worker threads", errcode ); return 1; }
+ { show_error( "Can't create worker threads", errcode ); cleanup_and_fail(); }
}
- if( !muxer( courier ) ) return 2;
+ muxer( courier );
for( int i = num_workers - 1; i >= 0; --i )
{
const int errcode = pthread_join( worker_threads[i], 0 );
if( errcode )
- { show_error( "Can't join worker threads", errcode ); return 1; }
+ { show_error( "Can't join worker threads", errcode ); cleanup_and_fail(); }
}
delete[] worker_threads;
delete[] worker_args;