summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2004-09-14 22:46:13 +0000
committerMarc Espie <espie@cvs.openbsd.org>2004-09-14 22:46:13 +0000
commit2618e97f09a87a26a32e68a89cf3d909ed3f05fc (patch)
tree505f7a067b720e823fc36659d143e21cdc5c3998 /usr.sbin
parent39178c030e096d30c88c21b816ac118a9a756158 (diff)
use chown/chmod system calls directly where possible.
some System instead of system.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/pkg_add36
1 files changed, 27 insertions, 9 deletions
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index f28948c4e12..8600fdc9dd1 100644
--- a/usr.sbin/pkg_add/pkg_add
+++ b/usr.sbin/pkg_add/pkg_add
@@ -1,7 +1,7 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_add,v 1.50 2004/08/12 19:18:03 brad Exp $
+# $OpenBSD: pkg_add,v 1.51 2004/09/14 22:46:12 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -27,6 +27,7 @@ use OpenBSD::PackageName;
use OpenBSD::PkgCfl;
use OpenBSD::Vstat;
use Getopt::Std;
+use OpenBSD::Error;
use File::Copy;
our %forced = ();
@@ -38,12 +39,15 @@ sub ensure_ldconfig
return unless defined $OpenBSD::PackingElement::Lib::todo;
print "running ldconfig -m ", join(' ', keys %$OpenBSD::PackingElement::Lib::todo), "\n"
if $verbose;
- system(@OpenBSD::PackingElement::Lib::ldconfig, "-m",
+ VSystem($verbose, @OpenBSD::PackingElement::Lib::ldconfig, "-m",
keys %$OpenBSD::PackingElement::Lib::todo);
undef $OpenBSD::PackingElement::Lib::todo;
}
package OpenBSD::PackingElement;
+use OpenBSD::Error;
+
+my ($uidcache, $gidcache);
sub install
{
@@ -53,15 +57,29 @@ sub set_modes
{
my ($self, $name) = @_;
- if (defined $self->{owner} && defined $self->{group}) {
- system('chown', $self->{owner}.':'.$self->{group}, $name);
- } elsif (defined $self->{owner}) {
- system('chown', $self->{owner}, $name);
- } elsif (defined $self->{group}) {
- system('chown', ':'.$self->{group}, $name);
+ if (defined $self->{owner} || defined $self->{group}) {
+ require OpenBSD::IdCache;
+
+ if (!defined $uidcache) {
+ $uidcache = OpenBSD::UidCache->new();
+ $gidcache = OpenBSD::GidCache->new();
+ }
+ my ($uid, $gid) = (stat $name)[4,5];
+ if (defined $self->{owner}) {
+ $uid = $uidcache->lookup($self->{owner}, $uid);
+ }
+ if (defined $self->{group}) {
+ $gid = $gidcache->lookup($self->{group}, $gid);
+ }
+ chown $uid, $gid, $name;
}
if (defined $self->{mode}) {
- system('chmod', $self->{mode}, $name);
+ my $v = $self->{mode};
+ if ($v =~ m/^\d+$/) {
+ chmod oct($v), $name;
+ } else {
+ System('chmod', $self->{mode}, $name);
+ }
}
}