imagecompress.in 18.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!/usr/bin/perl -w
#
# Copyright (c) 2016 University of Utah and the Flux Group.
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
#
use English;
use strict;
use Getopt::Std;
use Data::Dumper;
use File::stat;

#
# "Compress" an image.
#
# Locates all versions of an image and creates deltas for intermediate
# versions of the image. The initial version and the latest version are
# left as full images.
#
# To do this, we use the new-style directory representation of an image.
38
# As an example, for an image with multiple versions:
39 40
#
# FBSD102-64-STD.ndz
41 42
# FBSD102-64-STD.ndz.sha1
# FBSD102-64-STD.ndz.sig
43
# FBSD102-64-STD.ndz:1
44 45
# FBSD102-64-STD.ndz:1.sha1
# FBSD102-64-STD.ndz:1.sig
46 47
# ...
# FBSD102-64-STD.ndz:12
48 49
# FBSD102-64-STD.ndz:12.sha1
# FBSD102-64-STD.ndz:12.sig
50
#
51
# We just move them all into a subdirectory, ala:
52 53
#
# FBSD102-64-STD/
54 55 56 57 58 59
#   FBSD102-64-STD.ndz
#   FBSD102-64-STD.ndz.sha1
#   FBSD102-64-STD.ndz.sig
#   FBSD102-64-STD.ndz:1
#   FBSD102-64-STD.ndz:1.sha1
#   FBSD102-64-STD.ndz:1.sig
60
#   ...
61 62 63
#   FBSD102-64-STD.ndz:12
#   FBSD102-64-STD.ndz:12.sha1
#   FBSD102-64-STD.ndz:12.sig
64
#
65 66 67 68 69 70
# The naming convention is awkward and redundant but required the least
# violence to convert to.
#
# Delta files with have a .ddz suffix instead of .ndz and will have their
# own .sig and .sha1 files as well (though the .sig is identical to the
# full image sigfile).
71 72 73 74
#
sub usage()
{
    print("Usage: imagecompress [-dnK] <imageid> ...\n".
75 76
	  "For a complete image history, convert all intermediate versions\n".
	  "(i.e., all but first and last) into delta images.\n".
77 78 79
	  "Options:\n".
	  "       -d      Turn on debug mode\n".
	  "       -n      Just show what would be done\n".
80 81 82 83
	  "       -C      Check hashes/signatures before doing anything\n".
	  "               WARNING: this can take a really long time!\n".
	  "       -K      Keep existing other versions of images as well\n".
	  "       -U      Uncompress; create full images from all deltas instead.\n");
84 85
    exit(-1);
}
86
my $optlist    = "dnCKU";
87 88
my $debug      = 0;
my $impotent   = 0;
89
my $checkem    = 0;
90
my $keepother  = 0;
91
my $uncompress = 0;
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
my @images     = ();
my @rmfull     = ();
my @rmdelta    = ();

#
# Configure variables
#
my $TB		= "@prefix@";
my $SHA1	= "/sbin/sha1";
my $IMAGEHASH   = "$TB/bin/imagehash";

# Protos
sub fatal($);
sub doimage($);
sub createfull($$$);
sub removefull($$);
sub createdelta($$$);
sub removedelta($$);

#
# Untaint the path
#
$ENV{'PATH'} = "$TB/bin:$TB/sbin:/bin:/usr/bin:/usr/bin:/usr/sbin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

#
# Turn off line buffering on output
#
$| = 1;

#
# Load the Testbed support stuff.
#
use lib "@prefix@/lib";
use EmulabConstants;
use Image;
use OSinfo;
use User;
use Project;

#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
if (defined($options{"d"})) {
    $debug = 1;
}
if (defined($options{"n"})) {
    $impotent = 1;
}
146 147 148
if (defined($options{"C"})) {
    $checkem = 1;
}
149 150 151
if (defined($options{"K"})) {
    $keepother = 1;
}
152 153 154
if (defined($options{"U"})) {
    $uncompress = 1;
}
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
if (@ARGV < 1) {
    usage();
}
if ($impotent) {
    print STDERR "Operating in test mode, not changing anything ...\n";
}
@images = @ARGV;

my ($user,$user_uid,$userperm);
if ($UID) {
    $user = User->ThisUser();
    if (!defined($user)) {
	fatal("You ($UID) do not exist!");
    }
    $user_uid = $user->uid();
}
if ($impotent) {
    $userperm = TB_IMAGEID_READINFO();
} else {
    $userperm = TB_IMAGEID_MODIFYINFO();
}

my $errs = 0;
foreach my $pidimage (@images) {
    $errs += doimage($pidimage);
}
exit($errs);

sub doimage($)
{
    my ($pidimage) = @_;

    my $image = Image->Lookup($pidimage);
    if (!defined($image)) {
	print STDERR "$pidimage: no such image\n";
	return 1;
    }
    my $imageid = $image->imageid();

    # If the user is not an admin, must have perm on the image.
    if ($UID && !$user->IsAdmin() && !$image->AccessCheck($user, $userperm)) {
	print STDERR "$pidimage: insufficient privilege\n";
	return 1;
    }

    if (!$image->IsDirPath()) {
	print STDERR "$pidimage: image is not a directory!\n";
	print STDERR "  use 'sudo imagetodir $pidimage' to convert\n";
	return 1;
    }

    #
    # Find all valid (DB) versions of the image.
    # Returned list is ordered highest to lowest version.
    #
    my @iversions;
    $image->AllVersions(\@iversions);

    # Get the canonical name, sans version, for reporting.
    my $iname = $image->pid() . "/" . $image->imagename();

    #
    # Be anal about the image:
    #
    # - make sure there is SOME version of the image
    # - all versions from 0 to current must exist in DB
    # - version 0 must be a full image
    # - all referenced image files must exist
    # - all versions must have a signature
    #
    # This ensures that we have all our ducks in alignment before we
    # make any changes.
    #
    if (@iversions == 0) {
	print STDERR "$pidimage: no version exists!\n";
	return 1;
    }
    my $vers = 0;
    @iversions = reverse @iversions;
    foreach my $imobj (@iversions) {
	my $fqname = "$iname:$vers";
	if ($imobj->version() != $vers) {
	    print STDERR "$iname: version $vers missing!\n";
	    if ($vers == 0) {
		print STDERR "$iname: initial version is " . $imobj->version . "\n";
	    }
	    return 1;
	}

	#
	# At least one of the full and delta images must exist.
	# It is possible that both exist.
	#
	my ($path,$sigfile,$shafile,$size);
	if ($imobj->HaveFullImage()) {
	    $path = $imobj->FullImageFile();
	    $sigfile = $imobj->FullImageSigFile();
	    $shafile = $imobj->FullImageSHA1File();
	    $size = $imobj->size();
	}
	my ($dpath,$dsigfile,$dshafile,$dsize);
	if ($imobj->HaveDeltaImage()) {
	    $dpath = $imobj->DeltaImageFile();
	    $dsigfile = $imobj->DeltaImageSigFile();
	    $dshafile = $imobj->DeltaImageSHA1File();
	    $dsize = $imobj->deltasize();
	}
	if (!$path && !$dpath) {
	    print STDERR "$iname: no image file for version $vers!\n";
	    return 1;
	}
	if (!$path && $vers == 0) {
	    print STDERR "$iname: no full initial version!\n";
	    return 1;
	}
	if (($path && ! -e "$sigfile") || ($dpath && ! -e "$dsigfile")) {
	    print STDERR "$iname: no signature file for version $vers!\n";
	    print STDERR "  use 'sudo imagevalidate -V sig -uU $fqname' to create one\n";
	    return 1;
	}
	if (($path && ! -e "$shafile") || ($dpath && ! -e "$dshafile")) {
	    print STDERR "$iname: no SHA1 file for version $vers!\n";
	    print STDERR "  use 'sudo imagevalidate -V hash -uU $fqname' to create one\n";
	    return 1;
	}
	if (($path && $size == 0) || ($dpath && $dsize == 0)) {
	    print STDERR "$iname: no DB size for version $vers!\n";
	    print STDERR "  use 'sudo imagevalidate -uU $fqname' to correct\n";
	    return 1;
	}

286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
	#
	# Be super paranoid and check hashes and signatures too.
	#
	if ($checkem) {
	    if ($path) {
		my $nhash = `$SHA1 $path`;
		if ($? == 0 && $nhash =~ /^SHA1.*= ([\da-fA-F]+)$/) {
		    $nhash = lc($1);
		    if ($nhash ne $imobj->hash()) {
			print STDERR "$iname: file hash != DB hash for version $vers!\n";
			print STDERR "  use 'sudo imagevalidate -uU -V hash $fqname' to correct\n";
			return 1;

		    }
		} else {
		    print STDERR "$iname: $SHA1 failed!?\n";
		    return 1;
		}
		if (system("$IMAGEHASH -SX $path")) {
		    print STDERR "$iname: signature does not check for version $vers!\n";
		    print STDERR "  use 'sudo imagevalidate -uU -V sig $fqname' to correct\n";
		    return 1;
		}
	    }

	    if ($dpath) {
		my $nhash = `$SHA1 $dpath`;
		if ($? == 0 && $nhash =~ /^SHA1.*= ([\da-fA-F]+)$/) {
		    $nhash = lc($1);
		    if ($nhash ne $imobj->deltahash()) {
			print STDERR "$iname: delta file hash != DB deltahash for version $vers!\n";
			print STDERR "  use 'sudo imagevalidate -uU -V hash $fqname' to correct\n";
			return 1;

		    }
		} else {
		    print STDERR "$iname: $SHA1 failed!?\n";
		    return 1;
		}

		# XXX cannot check signature for delta image
	    }
	}

330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
	if ($debug) {
	    print STDERR "$iname: found full version $vers: $path...\n"
		if ($path);
	    print STDERR "$iname: found delta version $vers: $dpath...\n"
		if ($dpath);
	}
	$vers++;
    }

    #
    # All versions of the image present and accounted for, let's git er done!
    # In the first pass we create all necessary new images and keep track of
    # any full or delta images we need to remove.
    #
    my $curvers = $vers - 1;
    foreach my $imobj (@iversions) {
	my ($path,$dpath);
	if ($imobj->HaveFullImage()) {
	    $path = $imobj->FullImageFile();
	}
	if ($imobj->HaveDeltaImage()) {
	    $dpath = $imobj->DeltaImageFile();
	}
	$vers = $imobj->version();

	#
	# Initial version: we have already verified that it is a full image.
	# Remove any delta if desired.
	#
	if ($vers == 0) {
	    if ($path && $dpath && !$keepother) {
		push(@rmdelta, $imobj);
	    }
	    next;
	}

	#
	# Intermediate version: want a delta, generate it from full image.
368 369
	# For -U, we want a full image, regenerate it from delta image.
	# Also get rid of full (delta) version if desired.
370 371
	#
	if ($vers != $curvers) {
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
	    if ($uncompress) {
		if ($dpath && !$path) {
		    if (createfull($iname, $imobj, 1)) {
			print STDERR "$iname: could not create full for version $vers\n";
		    } else {
			$path = $imobj->FullImageFile();
		    }
		}
		if ($dpath && $path && !$keepother) {
		    push(@rmdelta, $imobj);
		}
	    } else {
		if ($path && !$dpath) {
		    if (createdelta($iname, $imobj, 1)) {
			print STDERR "$iname: could not create delta for version $vers\n";
		    } else {
			$dpath = $imobj->DeltaImageFile();
		    }
		}
		if ($path && $dpath && !$keepother) {
		    push(@rmfull, $imobj);
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
		}
	    }
	    next;
	}

	#
	# Current version: want a full version, create it if necessary.
	# Also remove delta if desired.
	#
	if (!$path && $dpath) {
	    if (createfullchain($iname, $imobj)) {
		print STDERR "$iname: could not create full image for version $vers\n";
	    } else {
		$path = $imobj->FullImageFile();
	    }
	}
	if ($path && $dpath && !$keepother) {
	    push(@rmdelta, $imobj);
	}
    }

    #
    # Clean up
    #
    foreach my $imobj (@rmfull) {
	my $vers = $imobj->version();
	if (removefull($iname, $imobj)) {
	    print STDERR "$iname: could not remove full image for version $vers\n";
	}
    }
    foreach my $imobj (@rmdelta) {
	my $vers = $imobj->version();
	if (removedelta($iname, $imobj)) {
	    print STDERR "$iname: could not remove delta image for version $vers\n";
	}
    }

    exit(0);
}

#
# Create a full image using the previous full image and our delta image.
# N.B. previous image must be a full image!
#
sub createfull($$$)
{
    my ($iname,$image,$hashit) = @_;

    my $vers = $image->version();
    if ($vers == 0) {
	print STDERR "$iname: cannot create full of version 0\n";
	return 1;
    }

    $vers--;
    my $pimage = Image->Lookup("$iname:$vers");
    if (!$pimage) {
	print STDERR "$iname: could not lookup version $vers!?\n";
	return 1;
    }
    $vers++;

    my $file = $image->FullImageFile();
    my $dfile = $image->DeltaImageFile();
    my $pfile = $pimage->FullImageFile();
    my $sfile = $image->FullImageSigFile();
    my $shafile = $image->FullImageSHA1File();

    print "Creating full image '$file' from '$pfile' and '$dfile' ...\n"
	if ($debug);
    if ($impotent) {
	print "Would 'imageundelta -S $pfile $dfile $file' ...\n";
    } elsif (system("imageundelta -S $pfile $dfile $file")) {
	print STDERR "$iname: could not create full image for version $vers\n";
	return 1;
    }

    if ($impotent) {
	if ($hashit) {
	    print "Would create SHA1 file $shafile ...\n";
	}
	print "Would update DB size/hash for full image $file ...\n";
	return 0;
    }

    #
    # Compute the SHA1 hash and gather the image size.
    # XXX since we went through a lot of work to create the delta,
    # we don't fail if we have problems with the hash or stat--they
    # can run imagevalidate later to correctly set them.
    #
    my $hash = "";
    if ($hashit) {
	$hash = `$SHA1 $file`;
	if ($? == 0 && $hash =~ /^SHA1.*= ([\da-fA-F]+)$/) {
	    $hash = lc($1);
	    if (open(FD, ">$shafile")) {
		print FD "$hash\n";
		close(FD);
492
		system("touch -r $file $shafile");
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
	    }
	} else {
	    print("$iname: WARNING: could not generate or parse SHA1 hash of '$file'\n");
	    $hash = "";
	}
    }

    my $size = stat($file)->size;
    if (!defined($size)) {
	print("$iname: WARNING: could not get size of '$file'\n");
	$size = 0;
    }

    if (!$impotent &&
	($image->SetHash($hash) ||
	 $image->SetSize($size))) {
	print STDERR "$iname: could not set database state for full image\n";
	return 1;
    }

    return 0;
}

#
# Create a full image based on the last known full image and the
# intermediate deltas.
#
# XXX This is nasty because the current imageundelta can only apply a
# single delta, so we have to create multiple intermediate full images!
#
sub createfullchain($$)
{
    my ($iname,$image) = @_;

    my $file = $image->FullImageFile();
    my $vers = $image->version();
    my $pvers;

    # Find the most recent version with a full image file
    for ($pvers = $vers - 1; $pvers >= 0; $pvers--) {
	my $pimage = Image->Lookup("$iname:$pvers");
	if (!$pimage) {
	    print STDERR "$iname: could not lookup version $pvers!?\n";
	    return 1;
	}
	if ($pimage->HaveFullImage()) {
	    last;
	}
    }
    if ($pvers < 0) {
	print STDERR "$iname: could not find previous full image!?\n";
	return 1;
    }

    print "Creating full image for version $vers starting at version $pvers ...\n"
	if ($debug);

    while ($pvers != $vers) {
	my $nvers = $pvers + 1;
	my $nimage = Image->Lookup("$iname:$nvers");
	my $keepfull = ($nvers == $vers ? 1 : 0);
	if (createfull($iname, $nimage, $keepfull)) {
	    print STDERR "$iname: could not create intermediate full version $nvers\n";
	    return 1;
	}

	#
	# If we created the one we wanted in the first place, we are done.
	# Otherwise, schedule this intermediate image for destruction.
	#
	if ($keepfull) {
	    last;
	}
	push(@rmfull, $nimage);

	# XXX create an empty SHA1 file so we have something to remove
	my $shafile = $nimage->FullImageSHA1File();
	if ($impotent) {
	    print "Would create empty SHA1 $shafile ...\n";
	} else {
	    if (open(FD, ">$shafile")) {
		close(FD);
	    }
	}

	$pvers++;
    }

    return 0;
}

sub removefull($$)
{
    my ($iname,$image) = @_;

    my $file = $image->FullImageFile();
    my $sfile = $image->FullImageSigFile();
    my $hfile = $image->FullImageSHA1File();

    print "Removing full image '$file' ...\n"
	if ($debug);

    if ($impotent) {
596
	print "Would update DB hash/size for full image $file ...\n";
597 598
    } else {
	if ($image->SetHash(undef) ||
599
	    $image->SetSize(0)) {
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
	    print STDERR "$iname: could not clear database state\n";
	    return 1;
	}
    }

    # XXX don't make these fatal right now
    foreach my $file ($file, $sfile, $hfile) {
	if ($impotent) {
	    print "Would unlink($file) ...\n";
	} elsif (unlink($file) == 0) {
	    print STDERR "$iname: WARNING: could not remove '$file'\n";
	}
    }

    return 0;
}

#
# Create a delta image using the previous full image and our full image.
# N.B. previous image must be a full image!
#
sub createdelta($$$)
{
    my ($iname,$image,$hashit) = @_;

    my $vers = $image->version();
    if ($vers == 0) {
	print STDERR "$iname: cannot create delta of version 0\n";
	return 1;
    }

    $vers--;
    my $pimage = Image->Lookup("$iname:$vers");
    if (!$pimage) {
	print STDERR "$iname: could not lookup version $vers!?\n";
	return 1;
    }
    $vers++;

    my $dfile = $image->DeltaImageFile();
    my $shafile = $image->DeltaImageSHA1File();

    my $file = $image->FullImageFile();
    my $pfile = $pimage->FullImageFile();
    my $sfile = $image->FullImageSigFile();
    my $psfile = $pimage->FullImageSigFile();

    print "Creating delta from '$pfile' and '$file' ...\n"
	if ($debug);
    if ($impotent) {
	print "Would 'imagedelta -SF $pfile $file $dfile' ...\n";
    } elsif (system("imagedelta -SF $pfile $file $dfile")) {
	print STDERR "$iname: could not create delta image for version $vers\n";
	return 1;
    }

    if ($impotent) {
	if ($hashit) {
	    print "Would create SHA1 file $shafile ...\n";
	}
	print "Would update DB size/hash for delta image $dfile ...\n";
	return 0;
    }

    #
    # Compute the SHA1 hash and gather the image size.
    # XXX since we went through a lot of work to create the delta,
    # we don't fail if we have problems with the hash or stat--they
    # can run imagevalidate later to correctly set them.
    #
    my $hash = "";
    if ($hashit) {
	$hash = `$SHA1 $dfile`;
	if ($? == 0 && $hash =~ /^SHA1.*= ([\da-fA-F]+)$/) {
	    $hash = lc($1);
	    if (open(FD, ">$shafile")) {
		print FD "$hash\n";
		close(FD);
678
		system("touch -r $dfile $shafile");
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
	    }
	} else {
	    print("$iname: WARNING: could not generate or parse SHA1 hash of '$dfile'\n");
	    $hash = "";
	}
    }
    my $size = stat($dfile)->size;
    if (!defined($size)) {
	print("$iname: WARNING: could not get size of '$dfile'\n");
	$size = 0;
    }

    if (!$impotent &&
	($image->SetDeltaHash($hash) ||
	 $image->SetDeltaSize($size))) {
	print STDERR "$iname: could not set database state for delta image\n";
	return 1;
    }

    return 0;
}

sub removedelta($$)
{
    my ($iname,$image) = @_;

    my $file = $image->DeltaImageFile();
    my $sfile = $image->DeltaImageSigFile();
    my $hfile = $image->DeltaImageSHA1File();

    print "Removing delta image '$file' ...\n"
	if ($debug);

    if ($impotent) {
713
	print "Would update DB hash/size for delta image $file ...\n";
714 715
    } else {
	if ($image->SetDeltaHash(undef) ||
716
	    $image->SetDeltaSize(0)) {
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741
	    print STDERR "$iname: could not clear database state\n";
	    return 1;
	}
    }

    # XXX don't make these fatal right now
    foreach my $file ($file, $sfile, $hfile) {
	if ($impotent) {
	    print "Would unlink($file) ...\n";
	} elsif (unlink($file) == 0) {
	    print STDERR "$iname: WARNING: could not remove '$file'\n";
	}
    }

    return 0;
}

sub fatal($)
{
    my ($mesg) = @_;

    print STDERR "*** $0:\n".
	         "    $mesg\n";
    exit(-1);
}