Bug 1914251

Summary: "dnf needs-restarting -r" work incorrectly inside systemd-nspawn containers
Product: [Fedora] Fedora Reporter: Gena Makhomed <makhomed>
Component: dnf-plugins-coreAssignee: Nicola Sella <nsella>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 33CC: dmach, jmracek, mblaha, nsella, packaging-team-maint, pkratoch, praiskup, rpm-software-management, vmukhame
Target Milestone: ---Keywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: dnf-plugins-core-4.0.21-1.fc33 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-05-03 01:48:19 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Gena Makhomed 2021-01-08 13:00:12 UTC
Description of problem:

"dnf needs-restarting -r" work incorrectly inside systemd-nspawn containers

Version-Release number of selected component (if applicable):

source: dnf-plugins-core-4.0.18-1.fc33.src.rpm
binary: python3-dnf-plugins-core-4.0.18-1.fc33.noarch.rpm

How reproducible:

always

1. Install Fedora Server 33 on host, install systemd-container package on host:

dnf install systemd-container

2. Install Fedora Server 33 inside systemd-nspawn container:

dnf --installroot=/var/lib/machines/test --releasever=33 install dnf python3-dnf-plugins-core systemd

3. start container test:

machinectl start test

4. enter inside container test:

machinectl shell test

5. check if container needs restarting:

dnf needs-restarting -r

Actual results:

# dnf needs-restarting -r
Core libraries or services have been updated since boot-up:
  * dbus
  * dbus-broker
  * glibc
  * systemd

Reboot is required to fully utilize these updates.
More information: https://access.redhat.com/solutions/27943

Expected results:

# dnf needs-restarting -r
No core libraries or services have been updated since boot-up.
Reboot should not be necessary.

Additional info:

Cause of bug located in file:

/usr/lib/python3.6/site-packages/dnf-plugins/needs_restarting.py

Linus Torvalds say: "Talk is cheap. Show me the code".

Ok.

Patch to solve this bug:

After this patch - command "dnf needs-restarting -r" will work correctly
inside and outside systemd-nspawn containers.

The first process start time could be used as container/host start time:

 int(os.stat('/proc/1/cmdline').st_mtime)

/proc/1/cmdline is a virtual file in the procfs, whose creation date is the same 
as the container creation date or linux host boot time, if no containers is used.

--- needs_restarting.py.orig    2020-10-06 19:54:52.000000000 +0300
+++ needs_restarting.py 2021-01-08 14:13:39.465000000 +0200
@@ -174,11 +174,7 @@

     @staticmethod
     def get_boot_time():
-        with open('/proc/stat') as stat_file:
-            for line in stat_file.readlines():
-                if not line.startswith('btime '):
-                    continue
-                return int(line[len('btime '):].strip())
+        return int(os.stat('/proc/1/cmdline').st_mtime)

     @staticmethod
     def get_sc_clk_tck():

Comment 1 Nicola Sella 2021-01-13 15:14:35 UTC
I added a PR with your patch
https://github.com/rpm-software-management/dnf-plugins-core/pull/422

Comment 3 Fedora Update System 2021-04-19 16:12:51 UTC
FEDORA-2021-447fb19490 has been submitted as an update to Fedora 33. https://bodhi.fedoraproject.org/updates/FEDORA-2021-447fb19490

Comment 4 Fedora Update System 2021-04-19 18:33:41 UTC
FEDORA-2021-447fb19490 has been pushed to the Fedora 33 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2021-447fb19490`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2021-447fb19490

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 5 Fedora Update System 2021-05-03 01:48:19 UTC
FEDORA-2021-447fb19490 has been pushed to the Fedora 33 stable repository.
If problem still persists, please make note of it in this bug report.