Skip to content

Commit

Permalink
[Core] Use ImVirt for virtualization detection if not running on syst…
Browse files Browse the repository at this point in the history
…emd (Debian Bug#984789 by Patrik Schindler <poc@pocnet.net>).
  • Loading branch information
liske committed May 17, 2022
1 parent 8476627 commit f54d85c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ needrestart 3.6
(github issue #205 by @HumanG33k)
- [Core] Output user sessions in batch mode.
(github pull request #232 by @anarcat)
- [Core] Use ImVirt for virtualization detection if not running on systemd.
(Debian Bug#984789 by Patrik Schindler <poc@pocnet.net>)
- [Interp] Add tolerance when checking script file ctimes to avoid false positives.
(github pull request #233 by Corey Hickey @bugfood)
- [Kernel] Replace strings(1) by GNU grep to drop binutils dependency.
Expand Down
1 change: 1 addition & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Perl
- Sort::Naturally
- Term::ReadKey
- Parent (for legacy Perl versions, i.e. on CentOS 6)
- ImVirt (optional; highly recommended if not running on systemd)

Misc
----
Expand Down
10 changes: 9 additions & 1 deletion needrestart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ my $is_tty = (-t *STDERR || -t *STDOUT || -t *STDIN);
my $is_vm;
my $is_container;

if($is_systemd && -x q(/usr/bin/systemd-detect-virt)) {
if($is_systemd && -x q(/usr/bin/systemds-detect-virt)) {
# check if we are inside of a vm
my $ret = system(qw(/usr/bin/systemd-detect-virt --vm --quiet));
unless($? == -1 || $? & 127) {
Expand All @@ -64,6 +64,14 @@ if($is_systemd && -x q(/usr/bin/systemd-detect-virt)) {
$is_container = ($? >> 8) == 0;
}
}
elsif(eval "use ImVirt; 1;") {
require ImVirt;
ImVirt->import();
my $imvirt = ImVirt::imv_get(ImVirt->IMV_PROB_DEFAULT);

$is_vm = $imvirt ne ImVirt->IMV_PHYSICAL;
$is_container = $imvirt eq ImVirt->IMV_CONTAINER;
}
elsif (-r "/proc/1/environ") {
# check if we are inside of a container (fallback)
local $/;
Expand Down

0 comments on commit f54d85c

Please sign in to comment.