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
Bug 1914251 - "dnf needs-restarting -r" work incorrectly inside systemd-nspawn containers
Summary: "dnf needs-restarting -r" work incorrectly inside systemd-nspawn containers
Alias: None
Product: Fedora
Classification: Fedora
Component: dnf-plugins-core
Version: 33
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
Assignee: Nicola Sella
QA Contact: Fedora Extras Quality Assurance
Depends On:
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:
Last Closed: 2021-05-03 01:48:19 UTC
Type: Bug

Attachments (Terms of Use)

System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 1913962 0 medium CLOSED "dnf needs-restarting -r" work incorrectly inside systemd-nspawn containers 2023-05-29 09:31:48 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:


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:

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:


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


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:


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

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

     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)

     def get_sc_clk_tck():

Comment 1 Nicola Sella 2021-01-13 15:14:35 UTC
I added a PR with your patch

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

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:

See also 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.