sync upstream patch

(cherry picked from commit 2f05a5ccc561ca16a40487c7b4f5d35decd2bf44)
This commit is contained in:
sun_hai_10 2023-08-12 16:46:53 +08:00 committed by openeuler-sync-bot
parent 47b1c808a4
commit 8c2b81ae7b
2 changed files with 121 additions and 2 deletions

View File

@ -0,0 +1,112 @@
From 0a6a991342d9ac798ba4d91c04028161e726ec81 Mon Sep 17 00:00:00 2001
From: zengwei2000 <102871671+zengwei2000@users.noreply.github.com>
Date: Thu, 6 Jul 2023 05:23:18 +0000
Subject: [PATCH] Add provide exception handling
Conflict:NA
Reference:https://github.com/rpm-software-management/dnf/commit/0a6a991342d9ac798ba4d91c04028161e726ec81
---
dnf/cli/utils.py | 90 +++++++++++++++++++++++++-----------------------
1 file changed, 47 insertions(+), 43 deletions(-)
diff --git a/dnf/cli/utils.py b/dnf/cli/utils.py
index 1c3db758a1..f00e33530f 100644
--- a/dnf/cli/utils.py
+++ b/dnf/cli/utils.py
@@ -60,49 +60,53 @@ def seconds_to_ui_time(seconds):
def get_process_info(pid):
"""Return info dict about a process."""
- pid = int(pid)
-
- # Maybe true if /proc isn't mounted, or not Linux ... or something.
- if (not os.path.exists("/proc/%d/status" % pid) or
- not os.path.exists("/proc/stat") or
- not os.path.exists("/proc/%d/stat" % pid)):
- return
-
- ps = {}
- with open("/proc/%d/status" % pid) as status_file:
- for line in status_file:
- if line[-1] != '\n':
- continue
- data = line[:-1].split(':\t', 1)
- if len(data) < 2:
- continue
- data[1] = dnf.util.rtrim(data[1], ' kB')
- ps[data[0].strip().lower()] = data[1].strip()
- if 'vmrss' not in ps:
- return
- if 'vmsize' not in ps:
- return
-
- boot_time = None
- with open("/proc/stat") as stat_file:
- for line in stat_file:
- if line.startswith("btime "):
- boot_time = int(line[len("btime "):-1])
- break
- if boot_time is None:
- return
-
- with open('/proc/%d/stat' % pid) as stat_file:
- ps_stat = stat_file.read().split()
- ps['start_time'] = boot_time + jiffies_to_seconds(ps_stat[21])
- ps['state'] = {'R' : _('Running'),
- 'S' : _('Sleeping'),
- 'D' : _('Uninterruptible'),
- 'Z' : _('Zombie'),
- 'T' : _('Traced/Stopped')
- }.get(ps_stat[2], _('Unknown'))
-
- return ps
+ try:
+ pid = int(pid)
+
+ # Maybe true if /proc isn't mounted, or not Linux ... or something.
+ if (not os.path.exists("/proc/%d/status" % pid) or
+ not os.path.exists("/proc/stat") or
+ not os.path.exists("/proc/%d/stat" % pid)):
+ return None
+
+ ps = {}
+ with open("/proc/%d/status" % pid) as status_file:
+ for line in status_file:
+ if line[-1] != '\n':
+ continue
+ data = line[:-1].split(':\t', 1)
+ if len(data) < 2:
+ continue
+ data[1] = dnf.util.rtrim(data[1], ' kB')
+ ps[data[0].strip().lower()] = data[1].strip()
+ if 'vmrss' not in ps:
+ return None
+ if 'vmsize' not in ps:
+ return None
+
+ boot_time = None
+ with open("/proc/stat") as stat_file:
+ for line in stat_file:
+ if line.startswith("btime "):
+ boot_time = int(line[len("btime "):-1])
+ break
+ if boot_time is None:
+ return None
+
+ with open('/proc/%d/stat' % pid) as stat_file:
+ ps_stat = stat_file.read().split()
+ ps['start_time'] = boot_time + jiffies_to_seconds(ps_stat[21])
+ ps['state'] = {'R' : _('Running'),
+ 'S' : _('Sleeping'),
+ 'D' : _('Uninterruptible'),
+ 'Z' : _('Zombie'),
+ 'T' : _('Traced/Stopped')
+ }.get(ps_stat[2], _('Unknown'))
+
+ return ps
+ except (OSError, ValueError) as e:
+ logger.error("Failed to get process info: %s", e)
+ return None
def show_lock_owner(pid):

View File

@ -3,9 +3,9 @@
Name: dnf
Version: 4.14.0
Release: 15
Release: 16
Summary: A software package manager that manages packages on Linux distributions.
License: GPLv2+ and GPLv2 and GPL
License: GPL-2.0-or-later AND GPL-1.0-only
URL: https://github.com/rpm-software-management/dnf
Source0: https://github.com/rpm-software-management/dnf/archive/%{version}/%{name}-%{version}.tar.gz
@ -28,6 +28,7 @@ Patch6004: backport-add-support-for-rollback-of-group-upgrade-rollbac
Patch6005: backport-ignore-processing-variable-files-with-unsupported-encoding.patch
Patch6006: backport-fix-AttributeError-when-IO-busy-and-press-ctrl-c.patch
Patch6007: backport-cli-allow-=in-setopt-values.patch
Patch6008: backport-Add-provide-exception-handling.patch
BuildArch: noarch
BuildRequires: cmake gettext systemd bash-completion python3-sphinx
@ -252,6 +253,12 @@ popd
%{_mandir}/man8/%{name}-automatic.8*
%changelog
* Sat Aug 12 2023 sunhai <sunhai10@huawei.com> - 4.14.0-16
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:dnf:Add provide exception handling
* Fri Jul 14 2023 chenhaixing <chenhaixing@huawei.com> - 4.14.0-15
- Type:bugfix
- CVE:NA