+sub upid_wait {
+ my ($upid, $waitfunc, $sleep_intervall) = @_;
+
+ my $task = PVE::Tools::upid_decode($upid);
+
+ $sleep_intervall = $sleep_intervall ? $sleep_intervall : 1;
+
+ my $next_time = time + $sleep_intervall;
+
+ while (check_process_running($task->{pid}, $task->{pstart})) {
+
+ if (time >= $next_time && $waitfunc && ref($waitfunc) eq 'CODE'){
+ &$waitfunc($task);
+ $next_time = time + $sleep_intervall;
+ }
+
+ CORE::sleep(1);
+ }
+}
+
+# struct ifreq { // FOR SIOCGIFFLAGS:
+# char ifrn_name[IFNAMSIZ]
+# short ifru_flags
+# };
+my $STRUCT_IFREQ_SIOCGIFFLAGS = 'Z' . IFNAMSIZ . 's1';
+sub get_active_network_interfaces {
+ # Use the interface name list from /proc/net/dev
+ open my $fh, '<', '/proc/net/dev'
+ or die "failed to open /proc/net/dev: $!\n";
+ # And filter by IFF_UP flag fetched via a PF_INET6 socket ioctl:
+ my $sock;
+ socket($sock, PF_INET6, SOCK_DGRAM, &IPPROTO_IP)
+ or socket($sock, PF_INET, SOCK_DGRAM, &IPPROTO_IP)
+ or return [];
+
+ my $ifaces = [];
+ while(defined(my $line = <$fh>)) {
+ next if $line !~ /^\s*([^:\s]+):/;
+ my $ifname = $1;
+ my $ifreq = pack($STRUCT_IFREQ_SIOCGIFFLAGS, $ifname, 0);
+ if (!defined(ioctl($sock, SIOCGIFFLAGS, $ifreq))) {
+ warn "failed to get interface flags for: $ifname\n";
+ next;
+ }
+ my ($name, $flags) = unpack($STRUCT_IFREQ_SIOCGIFFLAGS, $ifreq);
+ push @$ifaces, $ifname if ($flags & IFF_UP);
+ }
+ close $fh;
+ close $sock;
+ return $ifaces;
+}
+