From 3cba6545b7a1b9bb7d048e3d4e3003a1ccbeebb9 Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Sun, 18 Mar 2007 18:48:21 +0000 Subject: handle more errors during package creation. - if archiving discovers issues, then go into high speed mode where stuff doesn't get written. - in case of errors or fatal signals, make sure to remove a partially written archive. --- usr.sbin/pkg_add/pkg_create | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'usr.sbin/pkg_add/pkg_create') diff --git a/usr.sbin/pkg_add/pkg_create b/usr.sbin/pkg_add/pkg_create index d522677d868..67053c880db 100644 --- a/usr.sbin/pkg_add/pkg_create +++ b/usr.sbin/pkg_add/pkg_create @@ -1,6 +1,6 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_create,v 1.50 2006/12/10 23:15:00 steven Exp $ +# $OpenBSD: pkg_create,v 1.51 2007/03/18 18:48:20 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie # @@ -45,17 +45,16 @@ sub archive if (defined $arc) { my $o = $arc->prepare_long($self); - $o->write(); if (!defined $self->{owner} && !$o->isSymLink()) { if ($o->{uname} ne 'root' && $o->{uname} ne 'bin') { print STDERR "Warning: no \@owner for ", - $self->fullname(), " (", $o->{uname}, ")\n"; + $self->fullname(), " (", $o->{uname}, ")\n"; } } if (!defined $self->{group} && !$o->isSymLink()) { if ($o->{gname} ne 'bin' && $o->{gname} ne 'wheel') { print STDERR "Warning: no \@group for ", - $self->fullname(), " (", $o->{gname}, ")\n"; + $self->fullname(), " (", $o->{gname}, ")\n"; } } if (!defined $self->{mode} && $o->isFile()) { @@ -65,6 +64,7 @@ sub archive sprintf("%4o", $o->{mode} & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID)), "\n"; } } + $o->write() unless $main::errors; } if ($verbose) { print "Adding ", $self->{name}, "\n"; @@ -592,6 +592,18 @@ if ($opt_n) { $plist->archive(undef, $base, 1); } else { print "Creating gzip'd tar ball in '$wname'\n" if $opt_v; + my $h = sub { + unlink $wname; + my $caught = shift; + $SIG{$caught} = 'DEFAULT'; + kill $caught, $$; + }; + + local $SIG{'INT'} = $h; + local $SIG{'QUIT'} = $h; + local $SIG{'HUP'} = $h; + local $SIG{'KILL'} = $h; + local $SIG{'TERM'} = $h; open(my $fh, "|gzip >$wname"); my $wrarc = OpenBSD::Ustar->new($fh, $dir); for my $special (@extra_files) { @@ -603,6 +615,10 @@ if ($opt_n) { $plist->archive($wrarc, $base, $opt_v); $wrarc->pad(); close($fh); + if ($errors) { + unlink($wname); + exit(1); + } } } catch { print STDERR "$0: $_\n"; -- cgit v1.2.3