Bug 2092033

Summary: needs-restarting should require a reboot for the update of zlib
Product: Red Hat Enterprise Linux 8 Reporter: jcastran
Component: dnf-plugins-coreAssignee: Nicola Sella <nsella>
Status: CLOSED ERRATA QA Contact: Tomáš Bajer <tbajer>
Severity: medium Docs Contact: Mariya Pershina <mpershin>
Priority: medium    
Version: 8.6CC: james.antill, jrohel, mbanas, mblaha, mcurlej, mpershin, nsella, pkratoch, ppisar, tbajer
Target Milestone: rcKeywords: Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: All   
OS: Unspecified   
Whiteboard:
Fixed In Version: dnf-plugins-core-4.0.21-23.el8 Doc Type: Bug Fix
Doc Text:
.The `needs-restarting` plug-in now correctly requires the system restart when a file owned by `dbus` is updated by `zlib` Previously, when you ran the YUM `needs-restarting` plug-in, it did not prompt to restart the system when a file owned by the `dbus` package was updated by the dependent `zlib` package. With this update, the issue has been fixed, and the `needs-restarting` plug-in now displays a message that you must restart `dbus` when `zlib` is updated.
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-11-14 15:49:47 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 jcastran 2022-05-31 15:02:37 UTC
Description of problem:


Version-Release number of selected component (if applicable):
yum-utils-4.0.21-11.el8.noarch



Steps to Reproduce:
1. yum update zlib
2. needs-restarting -s
3.

Actual results:
# needs-restarting -s
Updating Subscription Management repositories.
Failed to read PID 4813's smaps.
systemd-udevd.service
rsyslog.service
auditd.service
pmie.service
pmlogger.service
systemd-journald.service
sssd.service
dbus.service            <<<<<<<
pmcd.service
NetworkManager.service
firewalld.service
pmlogger_farm.service
rpcbind.service
sshd.service
gssproxy.service
pmie_farm.service
user
rngd.service
systemd-logind.service

Expected results:
If dbus must be restarted, the system should be rebooted. 

Additional info:

Comment 1 Pavla Kratochvilova 2022-06-06 12:51:51 UTC
The option `-s` only reports affected systemd services, but doesn't report whether a reboot is required. What does `dnf needs-restarting -r` report?

Comment 2 jcastran 2022-06-06 13:03:50 UTC
I should have included that at the start.

~~~~~~~~~~~~~~~~
[root@r8 ~]# needs-restarting -r
Updating Subscription Management repositories.
No core libraries or services have been updated since boot-up.
Reboot should not be necessary.

[root@r8 ~]# needs-restarting -s
Updating Subscription Management repositories.
rsyslog.service
sshd.service
pmlogger.service
gssproxy.service
rpcbind.service
firewalld.service
rngd.service
auditd.service
sssd.service
systemd-logind.service
NetworkManager.service
pmcd.service
systemd-journald.service
pmie_farm.service
pmlogger_farm.service
systemd-udevd.service
pmie.service
~~~~~~~~~~~~~~~~

The reboot will only show when certain packages are updated.

REBOOTPKGS = ['kernel', 'kernel-rt', 'glibc', 'linux-firmware', 'systemd', 'udev', 'openssl-libs', 'gnutls', 'dbus']

In this case, zlib is triggering a need to restart dbus, but not saying it needs to reboot.

Comment 3 Marek Blaha 2022-06-13 12:43:26 UTC
Reproduces (using expat instead ov zlib, though - unlike zlib, expat is direct dependency of dbus):

# dnf repoquery --requires dbus-daemon
Updating Subscription Management repositories.
Last metadata expiration check: 0:17:16 ago on Mon Jun 13 08:18:55 2022.
--------------------- 8< ----------------------
libexpat.so.1()(64bit)
--------------------- 8< ----------------------


# dnf downgrade expat
--------------------- 8< ----------------------
Downgraded:
  expat-2.2.5-4.el8_5.3.x86_64

# dnf needs-restarting -s
Updating Subscription Management repositories.
polkit.service
tuned.service
dbus.service

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

# echo $?
0

Comment 4 Petr Pisar 2022-06-13 12:48:13 UTC
The binary package is built from dnf-plugins-core. Moving a component there.

Comment 5 Petr Pisar 2022-06-13 13:08:51 UTC
I think there is a flaw in a logic for the "-r" option in needs_restarting.py:

    def run(self):
        process_start = ProcessStart()
        owning_pkg_fn = functools.partial(owning_package, self.base.sack)
        owning_pkg_fn = memoize(owning_pkg_fn)

        opt = get_options_from_dir(os.path.join(
            self.base.conf.installroot,
            "etc/dnf/plugins/needs-restarting.d/"),
            self.base)
        NEED_REBOOT.extend(opt)
        if self.opts.reboothint:
            need_reboot = set()
            installed = self.base.sack.query().installed()
            for pkg in installed.filter(name=NEED_REBOOT):
→               if pkg.installtime > process_start.boot_time:
                    need_reboot.add(pkg.name)
            if need_reboot:
                print(_('Core libraries or services have been updated '
                        'since boot-up:'))
                for name in sorted(need_reboot):
                    print('  * %s' % name)
                print()
                print(_('Reboot is required to fully utilize these updates.'))
                print(_('More information:'),
                      'https://access.redhat.com/solutions/27943')
                raise dnf.exceptions.Error()  # Sets exit code 1
            else:
                print(_('No core libraries or services have been updated '
                        'since boot-up.'))

The current code ends up with "No core libraries or services have been updated since boot-up." message because all it does is checking an installation time of the very few packages listed in NEED_REBOOT array against uptime of the system.

In this case a library used by dbus program was updated. But that library is not part of dbus RPM package. It's comes from a different package (e.g. zlib) which is not on the list.

A proper fix needs to enumerate affected processes, locate their programs, map them to binary RPM package, consult the packages against the NEED_REBOOT array.

needs-restaring without options already locates the program ("needs-restarting | grep dbus"). All you need is query a sack for a package providing the program file and then match NEED_REBOOT without checking any installation times.

Comment 6 Petr Pisar 2022-06-13 15:41:16 UTC
Now I realize that replacing the original approach would introduce regressions like "I upgraded linux-firmware and it does report to reboot because on process holds open firmware file". I think we need to combine both approaches. Checking for open files and checking for installation time, do union on both sets.

Comment 8 Nicola Sella 2022-11-08 12:40:07 UTC
Hello, unfortunately, we are postponing this fix to 8.9. The risk of this bugfix having collateral side effects is high. Therefore, we would like to have more time to test it in Fedora.

Comment 23 errata-xmlrpc 2023-11-14 15:49:47 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (dnf-plugins-core bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:7125