mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-08-06 17:25:53 +00:00
Change check_cmdline to parse_cmdline
parse_cmdline is required for upcoming changes related to custom CPU types and live migration, and this way we can re-use existing code. Provides the necessary infrastructure to parse QEMU /proc/.../cmdline. Changing the single user (check_running) is trivial too. Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
parent
d036e418a8
commit
24622ebed4
@ -2935,8 +2935,8 @@ sub check_local_storage_availability {
|
|||||||
return $nodehash
|
return $nodehash
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_cmdline {
|
sub parse_cmdline {
|
||||||
my ($pidfile, $pid) = @_;
|
my ($pid) = @_;
|
||||||
|
|
||||||
my $fh = IO::File->new("/proc/$pid/cmdline", "r");
|
my $fh = IO::File->new("/proc/$pid/cmdline", "r");
|
||||||
if (defined($fh)) {
|
if (defined($fh)) {
|
||||||
@ -2948,15 +2948,24 @@ sub check_cmdline {
|
|||||||
my $cmd = $param[0];
|
my $cmd = $param[0];
|
||||||
return if !$cmd || ($cmd !~ m|kvm$| && $cmd !~ m@(?:^|/)qemu-system-[^/]+$@);
|
return if !$cmd || ($cmd !~ m|kvm$| && $cmd !~ m@(?:^|/)qemu-system-[^/]+$@);
|
||||||
|
|
||||||
|
my $phash = {};
|
||||||
|
my $pending_cmd;
|
||||||
for (my $i = 0; $i < scalar (@param); $i++) {
|
for (my $i = 0; $i < scalar (@param); $i++) {
|
||||||
my $p = $param[$i];
|
my $p = $param[$i];
|
||||||
next if !$p;
|
next if !$p;
|
||||||
if (($p eq '-pidfile') || ($p eq '--pidfile')) {
|
|
||||||
my $p = $param[$i+1];
|
if ($p =~ m/^--?(.*)$/) {
|
||||||
return 1 if $p && ($p eq $pidfile);
|
if ($pending_cmd) {
|
||||||
return undef;
|
$phash->{$pending_cmd} = {};
|
||||||
|
}
|
||||||
|
$pending_cmd = $1;
|
||||||
|
} elsif ($pending_cmd) {
|
||||||
|
$phash->{$pending_cmd} = { value => $p };
|
||||||
|
$pending_cmd = undef;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $phash;
|
||||||
}
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -2983,7 +2992,9 @@ sub check_running {
|
|||||||
|
|
||||||
if ($line =~ m/^(\d+)$/) {
|
if ($line =~ m/^(\d+)$/) {
|
||||||
my $pid = $1;
|
my $pid = $1;
|
||||||
if (check_cmdline($pidfile, $pid)) {
|
my $cmdline = parse_cmdline($pid);
|
||||||
|
if ($cmdline && defined($cmdline->{pidfile}) && $cmdline->{pidfile}->{value}
|
||||||
|
&& $cmdline->{pidfile}->{value} eq $pidfile) {
|
||||||
if (my $pinfo = PVE::ProcFSTools::check_process_running($pid)) {
|
if (my $pinfo = PVE::ProcFSTools::check_process_running($pid)) {
|
||||||
return $pid;
|
return $pid;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user