Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 1914251 - "dnf needs-restarting -r" work incorrectly inside systemd-nspawn containers
Summary: "dnf needs-restarting -r" work incorrectly inside systemd-nspawn containers
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: dnf-plugins-core
Version: 33
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: nsella
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-01-08 13:00 UTC by Gena Makhomed
Modified: 2021-05-03 01:48 UTC (History)
9 users (show)

Fixed In Version: dnf-plugins-core-4.0.21-1.fc33
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-05-03 01:48:19 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 1913962 0 medium VERIFIED "dnf needs-restarting -r" work incorrectly inside systemd-nspawn containers 2023-07-22 08:35:52 UTC

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 nsella 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.


Note You need to log in before you can comment on or make changes to this bug.