X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FTools.pm;h=ff01ebd88ca74db036db5dc70725b49236332fce;hp=189b55264ea8796728798c255ccc0cebf79c0998;hb=4c28a8bc6954e8783b14b0a01d8a7cb73830754a;hpb=243c4e5892e34d902ff6e9e65d01e8912430dea1 diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 189b552..ff01ebd 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -1384,6 +1384,11 @@ sub parse_host_and_port { return; # nothing } +sub setresuid($$$) { + my ($ruid, $euid, $suid) = @_; + return 0 == syscall(PVE::Syscall::setresuid, $ruid, $euid, $suid); +} + sub unshare($) { my ($flags) = @_; return 0 == syscall(PVE::Syscall::unshare, $flags); @@ -1644,4 +1649,34 @@ sub dev_t_minor($) { return (($dev_t >> 12) & 0xfff00) | ($dev_t & 0xff); } +# Given an array of array refs [ \[a b c], \[a b b], \[e b a] ] +# Returns the intersection of elements as a single array [a b] +sub array_intersect { + my ($arrays) = @_; + + return [] if @$arrays == 0; + return $arrays->[0] if @$arrays == 1; + + my $array_unique = sub { + my %seen = (); + return grep { ! $seen{ $_ }++ } @_; + }; + + my $return_arr; + @$return_arr = $array_unique->(@{$arrays->[0]}); + for my $i (1 .. $#$arrays) { + my %count = (); + foreach my $element (@$return_arr, $array_unique->(@{$arrays->[$i]})) { + $count{$element}++; + } + $return_arr = []; + foreach my $element (keys %count) { + push @$return_arr, $element if $count{$element} > 1; + } + } + + return $return_arr; +} + + 1;