diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2004-09-14 22:43:10 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2004-09-14 22:43:10 +0000 |
commit | be3a907bf23778bb7c0e022dfef64bc41da5e7e4 (patch) | |
tree | c8bd8222cb3112b16d3eebdb47d57b5408a08303 | |
parent | 4856939692a6bc9cbd7940d79190733b08d3e04e (diff) |
basic error wrapper for system and such.
-rw-r--r-- | usr.sbin/pkg_add/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Error.pm | 61 |
2 files changed, 63 insertions, 1 deletions
diff --git a/usr.sbin/pkg_add/Makefile b/usr.sbin/pkg_add/Makefile index 2b70c09b96f..c676260fc74 100644 --- a/usr.sbin/pkg_add/Makefile +++ b/usr.sbin/pkg_add/Makefile @@ -1,8 +1,9 @@ -# $OpenBSD: Makefile,v 1.8 2004/09/14 22:37:39 espie Exp $ +# $OpenBSD: Makefile,v 1.9 2004/09/14 22:43:09 espie Exp $ MAN=pkg_add.1 pkg_info.1 pkg_create.1 pkg_delete.1 pkg.1 PACKAGES= \ + OpenBSD/Error.pm \ OpenBSD/IdCache.pm \ OpenBSD/Logger.pm \ OpenBSD/Mtree.pm \ diff --git a/usr.sbin/pkg_add/OpenBSD/Error.pm b/usr.sbin/pkg_add/OpenBSD/Error.pm new file mode 100644 index 00000000000..eb0f6df4889 --- /dev/null +++ b/usr.sbin/pkg_add/OpenBSD/Error.pm @@ -0,0 +1,61 @@ +# ex:ts=8 sw=4: +# $OpenBSD: Error.pm,v 1.1 2004/09/14 22:43:09 espie Exp $ +# +# Copyright (c) 2004 Marc Espie <espie@openbsd.org> +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# + +use strict; +use warnings; + +package OpenBSD::Error; +our @ISA=qw(Exporter); +our @EXPORT=qw(System VSystem Copy); + +sub System +{ + my $r = system(@_); + if ($r != 0) { + print "system(", join(", ", @_), ") failed: $?\n"; + } + return $r; +} + +sub VSystem +{ + my $verbose = shift; + if (!$verbose) { + &System; + } else { + print "Running ", join(' ', @_); + my $r = system(@_); + if ($r != 0) { + print "... failed: $?\n"; + } else { + print "\n"; + } + } +} + +sub Copy +{ + require File::Copy; + + my $r = File::Copy::copy(@_); + if (!$r) { + print "copy(", join(',', @_),") failed: $!\n"; + } + return $r; +} + +1; |