Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
b4c377502e
!221 dnf:Remove --duplicates and --oldinstallonly exit with 0 when nothing to remove and Add all candidates for reinstall to solver
From: @han_hui_hui 
Reviewed-by: @anonymous_z 
Signed-off-by: @anonymous_z
2024-06-17 01:38:36 +00:00
hanhuihui
7c12c1cfd6 dnf:Remove --duplicates and --oldinstallonly exit with 0 when nothing to remove and Add all candidates for reinstall to solver
Signed-off-by: hanhuihui <hanhuihui5@huawei.com>
2024-06-15 10:16:15 +00:00
openeuler-ci-bot
bed04e57be
!212 [sync] PR-210: dnf:Fix bash completion due to sqlite changes and When parsing over a KVP list, do not return till the whole list is parsed
From: @openeuler-sync-bot 
Reviewed-by: @anonymous_z 
Signed-off-by: @anonymous_z
2024-01-02 06:55:34 +00:00
chenhaixing
c16ef50131 dnf:Fix bash completion due to sqlite changes and When parsing over a KVP list, do not return till the whole list is parsed
(cherry picked from commit bab4d99aebed759e6b58d1f45a07439ab7e71804)
2023-12-29 15:41:55 +08:00
openeuler-ci-bot
7f4fe271d3
!208 [sync] PR-206: 重新修订龙芯和申威架构补丁
From: @openeuler-sync-bot 
Reviewed-by: @anonymous_z 
Signed-off-by: @anonymous_z
2023-12-29 01:39:34 +00:00
herengui
0abac8e8d9 删除无用的LA架构补丁,重新修订SW补丁
Signed-off-by: herengui <herengui@kylinsec.com.cn>
(cherry picked from commit c747cf23c8d0bd93bb61467c038abb207b3adaa6)
2023-09-21 14:10:47 +08:00
openeuler-ci-bot
ad7310ffcc
!205 [sync] PR-203: sync upstream patch
From: @openeuler-sync-bot 
Reviewed-by: @anonymous_z 
Signed-off-by: @anonymous_z
2023-09-01 06:25:05 +00:00
sun_hai_10
8c2b81ae7b sync upstream patch
(cherry picked from commit 2f05a5ccc561ca16a40487c7b4f5d35decd2bf44)
2023-08-14 10:01:44 +08:00
openeuler-ci-bot
47b1c808a4
!200 [sync] PR-196: dnf:remove patch about pidfile
From: @openeuler-sync-bot 
Reviewed-by: @anonymous_z 
Signed-off-by: @anonymous_z
2023-07-18 07:46:39 +00:00
chenhaxing
4c7d2cc671 dnf:remove patch about pidfile
(cherry picked from commit ca82c61220c6900508ce40026386f28185aa00dc)
2023-07-17 14:10:42 +08:00
14 changed files with 358 additions and 196 deletions

View File

@ -1,25 +0,0 @@
From 77d9646088647ae2bbecb70248701458662ebf48 Mon Sep 17 00:00:00 2001
From: Sun Haiyong <sunhaiyong@loongson.cn>
Date: Wed, 22 Dec 2021 14:37:16 +0800
Subject: [PATCH] Add loongarch architecture support.
---
dnf/rpm/__init__.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/dnf/rpm/__init__.py b/dnf/rpm/__init__.py
index 696e594..0db8e95 100644
--- a/dnf/rpm/__init__.py
+++ b/dnf/rpm/__init__.py
@@ -97,6 +97,8 @@ _BASEARCH_MAP = _invert({
'mipsel': ('mipsel',),
'mips64': ('mips64',),
'mips64el': ('mips64el',),
+ 'loongarch32' : ('loongarch32',),
+ 'loongarch64' : ('loongarch64',),
'noarch': ('noarch',),
'ppc': ('ppc',),
'ppc64': ('ppc64', 'ppc64iseries', 'ppc64p7', 'ppc64pseries'),
--
2.30.0

View File

@ -1,25 +0,0 @@
From 997310fff83c3701ffc5c3835979732b130679c0 Mon Sep 17 00:00:00 2001
From: zhangrui <zhangrui182@huawei.com>
Date: Wed, 29 Dec 2021 14:59:18 +0800
Subject: [PATCH] adapt-test-another-process
---
tests/test_lock.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/test_lock.py b/tests/test_lock.py
index ce9806b..c075005 100644
--- a/tests/test_lock.py
+++ b/tests/test_lock.py
@@ -112,7 +112,7 @@ class ProcessLockTest(tests.support.TestCase):
with l1:
process.start()
process.join()
- self.assertIsInstance(process.queue.get(), ProcessLockError)
+ self.assertEqual(process.queue.empty(), True)
def test_another_process_blocking(self):
l1 = build_lock(blocking=True)
--
2.27.0

View File

@ -0,0 +1,12 @@
diff --git a/dnf/rpm/__init__.py b/dnf/rpm/__init__.py
index 12efca7..d9eba54 100644
--- a/dnf/rpm/__init__.py
+++ b/dnf/rpm/__init__.py
@@ -111,6 +111,7 @@ _BASEARCH_MAP = _invert({
'sh4': ('sh4', 'sh4a'),
'sparc': ('sparc', 'sparc64', 'sparc64v', 'sparcv8', 'sparcv9',
'sparcv9v'),
+ 'sw_64': ('sw_64',),
'x86_64': ('x86_64', 'amd64', 'ia32e'),
})

View File

@ -0,0 +1,73 @@
From 96f8d79c37e119ff56f730797865121b63241a6b Mon Sep 17 00:00:00 2001
From: Jaroslav Mracek <jmracek@redhat.com>
Date: Thu, 15 Feb 2024 11:28:59 +0100
Subject: [PATCH] Add all candidates for reinstall to solver
Resolves: https://issues.redhat.com/browse/RHEL-25005
Conflict:NA
Reference:https://github.com/rpm-software-management/dnf/commit/96f8d79c37e119ff56f730797865121b63241a6b
---
dnf/base.py | 9 ++++++---
dnf/query.py | 5 ++++-
tests/test_queries.py | 7 ++++++-
3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/dnf/base.py b/dnf/base.py
index 9b59b9d7e5..552d53f4c7 100644
--- a/dnf/base.py
+++ b/dnf/base.py
@@ -2336,19 +2336,22 @@ def reinstall(self, pkg_spec, old_reponame=None, new_reponame=None,
if not installed_pkgs:
raise dnf.exceptions.PackagesNotInstalledError(
- 'no package matched', pkg_spec, available_nevra2pkg.values())
+ 'no package matched', pkg_spec, available_q.run())
cnt = 0
clean_deps = self.conf.clean_requirements_on_remove
+ strict = self.conf.strict
for installed_pkg in installed_pkgs:
try:
- available_pkg = available_nevra2pkg[ucd(installed_pkg)]
+ available_pkgs = available_nevra2pkg[ucd(installed_pkg)]
except KeyError:
if not remove_na:
continue
self._goal.erase(installed_pkg, clean_deps=clean_deps)
else:
- self._goal.install(available_pkg)
+ sltr = dnf.selector.Selector(self.sack)
+ sltr.set(pkg=available_pkgs)
+ self._goal.install(select=sltr, optional=(not strict))
cnt += 1
if cnt == 0:
diff --git a/dnf/query.py b/dnf/query.py
index ab4139bf9a..02e631a6ec 100644
--- a/dnf/query.py
+++ b/dnf/query.py
@@ -43,4 +43,7 @@ def _by_provides(sack, patterns, ignore_case=False, get_query=False):
return q.run()
def _per_nevra_dict(pkg_list):
- return {ucd(pkg):pkg for pkg in pkg_list}
+ nevra_dic = {}
+ for pkg in pkg_list:
+ nevra_dic.setdefault(ucd(pkg), []).append(pkg)
+ return nevra_dic
diff --git a/tests/test_queries.py b/tests/test_queries.py
index cdcb7ca453..e025300879 100644
--- a/tests/test_queries.py
+++ b/tests/test_queries.py
@@ -128,4 +128,9 @@ def test_per_nevra_dict(self):
dct = dnf.query._per_nevra_dict(pkgs)
self.assertCountEqual(dct.keys(),
["lotus-3-16.x86_64", "lotus-3-16.i686"])
- self.assertCountEqual(dct.values(), pkgs)
+ test_list = []
+ for list_items in dct.values():
+ for item in list_items:
+ test_list.append(item)
+
+ self.assertCountEqual(test_list, pkgs)

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

@ -0,0 +1,30 @@
From 33fde245b0a49eb02837b6fedb2d14ed92c2d99f Mon Sep 17 00:00:00 2001
From: grumpey <61189565+grumpey@users.noreply.github.com>
Date: Sun, 20 Aug 2023 07:35:29 -0400
Subject: [PATCH] Fix bash completion due to sqlite changes
Conflict:NA
Reference:https://github.com/rpm-software-management/dnf/commit/33fde245b0a49eb02837b6fedb2d14ed92c2d99f
= changelog =
msg: Fix bash completion due to sqlite changes
type: bugfix
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2232052
related: https://sqlite.org/src/info/c995932c3ffe7f27
---
etc/bash_completion.d/dnf | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/etc/bash_completion.d/dnf b/etc/bash_completion.d/dnf
index eb34b807a9..8a9256a695 100644
--- a/etc/bash_completion.d/dnf
+++ b/etc/bash_completion.d/dnf
@@ -112,7 +112,7 @@ _dnf_query_db()
{
local table=$1
local prefix=$2
- local query="select pkg from $table where pkg like \"$prefix%\""
+ local query="select pkg from $table where pkg like '$prefix%'"
if [ "$table" = "available" ]; then
# The available table contains both installed and non-installed
# packages. Exclude the installed packages.

View File

@ -0,0 +1,27 @@
From 4d57212f4c3b7cca3844050a17518ca46bc1859a Mon Sep 17 00:00:00 2001
From: Anish Bhatt <anish.bhatt@salesforce.com>
Date: Mon, 10 Jul 2023 10:09:17 -0700
Subject: [PATCH] When parsing over a KVP list, do not return till the whole
list is parsed
Conflict:NA
Reference:https://github.com/rpm-software-management/dnf/commit/4d57212f4c3b7cca3844050a17518ca46bc1859a
---
dnf/repodict.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/dnf/repodict.py b/dnf/repodict.py
index ffa0f8ed88..82c05ac002 100644
--- a/dnf/repodict.py
+++ b/dnf/repodict.py
@@ -79,8 +79,8 @@ def substitute(values):
if isinstance(value, str):
substituted.append(
libdnf.conf.ConfigParser.substitute(value, conf.substitutions))
- if substituted:
- return substituted
+ if substituted:
+ return substituted
return values
repo = dnf.repo.Repo(repoid, conf)

View File

@ -0,0 +1,32 @@
From 720338fed8124b120b56cc99cc0b13dfe48ffe95 Mon Sep 17 00:00:00 2001
From: Pavla Kratochvilova <pkratoch@redhat.com>
Date: Fri, 5 Apr 2024 14:42:38 +0200
Subject: [PATCH] remove --duplicates: when no duplicates, exit with 0
(RHEL-6424)
If no duplicates are present, then the command succesfully removed all
duplicates and should exit with 0 and write the message to stdout
instead of stderr.
Resolves: https://issues.redhat.com/browse/RHEL-6424
Conflict:NA
Reference:https://github.com/rpm-software-management/dnf/commit/720338fed8124b120b56cc99cc0b13dfe48ffe95
---
dnf/cli/commands/remove.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/dnf/cli/commands/remove.py b/dnf/cli/commands/remove.py
index e455ba6e61..af9622fdef 100644
--- a/dnf/cli/commands/remove.py
+++ b/dnf/cli/commands/remove.py
@@ -92,7 +92,8 @@ def run(self):
instonly = self.base._get_installonly_query(q.installed())
dups = q.duplicated().difference(instonly)
if not dups:
- raise dnf.exceptions.Error(_('No duplicated packages found for removal.'))
+ logger.info(_('No duplicated packages found for removal.'))
+ return
for (name, arch), pkgs_list in dups._na_dict().items():
if len(pkgs_list) < 2:

View File

@ -0,0 +1,30 @@
From 87eb5a7a3561381b5ef5e70548f49288251300fc Mon Sep 17 00:00:00 2001
From: Pavla Kratochvilova <pkratoch@redhat.com>
Date: Fri, 5 Apr 2024 14:43:04 +0200
Subject: [PATCH] remove --oldinstallonly: when no old installonly packages,
exit with 0
If no old installonly packages are present, then the command succesfully
removed all of them and should exit with 0 and write the message to
stdout instead of stderr.
Conflict:NA
Reference:https://github.com/rpm-software-management/dnf/commit/87eb5a7a3561381b5ef5e70548f49288251300fc
---
dnf/cli/commands/remove.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/dnf/cli/commands/remove.py b/dnf/cli/commands/remove.py
index af9622fdef..32e78d6d4d 100644
--- a/dnf/cli/commands/remove.py
+++ b/dnf/cli/commands/remove.py
@@ -124,8 +124,7 @@ def run(self):
for pkg in instonly:
self.base.package_remove(pkg)
else:
- raise dnf.exceptions.Error(
- _('No old installonly packages found for removal.'))
+ logger.info(_('No old installonly packages found for removal.'))
return
# Remove groups.

View File

@ -1,11 +0,0 @@
diff -Naur dnf-4.10.0.org/dnf/rpm/__init__.py dnf-4.10.0.sw/dnf/rpm/__init__.py
--- dnf-4.10.0.org/dnf/rpm/__init__.py 2022-02-27 01:21:45.610000000 +0000
+++ dnf-4.10.0.sw/dnf/rpm/__init__.py 2022-02-27 01:22:17.040000000 +0000
@@ -87,6 +87,7 @@
_BASEARCH_MAP = _invert({
'aarch64': ('aarch64',),
+ 'sw_64': ('sw_64',),
'alpha': ('alpha', 'alphaev4', 'alphaev45', 'alphaev5', 'alphaev56',
'alphaev6', 'alphaev67', 'alphaev68', 'alphaev7', 'alphapca56'),
'arm': ('armv5tejl', 'armv5tel', 'armv5tl', 'armv6l', 'armv7l', 'armv8l'),

View File

@ -3,35 +3,33 @@
Name: dnf
Version: 4.14.0
Release: 14
Release: 19
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
Patch9000: unlock-pidfile-if-current-proccess-is-NOT-dnf.patch
Patch9001: fix-pid-file-residue.patch
Patch1000: add-sw_64-support-not-upstream-modified.patch
Patch9002: add-rpm-transaction-debuginfo.patch
Patch9003: adapt-test-another-process.patch
Patch9004: fix-dnf-history-undo-error-when-history-sqlite-missing.patch
Patch9005: huawei-lock-file-add-verify-parameter.patch
%if 0%{?check_target_before_unlink}
Patch9006: get-lockfile-exists-before-unlick.patch
%endif
%ifarch sw_64
Patch6000: dnf-4.10.0-sw.patch
%endif
%if 0%(test `uname -m` == "loongarch64" && echo 1)
Patch6001: 0001-Add-loongarch-architecture-support.patch
%endif
Patch6002: backport-fix-plugins-unit-tests-unload-plugins-upon-their-deletion.patch
Patch6003: backport-pass-whole-url-in-relativeUrl-to-packageTarget-for-rpm-url-download.patch
Patch6004: backport-add-support-for-rollback-of-group-upgrade-rollback.patch
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
Patch6009: backport-When-parsing-over-a-KVP-list-do-not-return-till-the-whole.patch
Patch6010: backport-Fix-bash-completion-due-to-sqlite-changes.patch
Patch6011: backport-remove-duplicates-when-no-duplicates-exit-with-0.patch
Patch6012: backport-remove-oldinstallonly-when-no-old-installonly-packages-exit-with-0.patch
Patch6013: backport-Add-all-candidates-for-reinstall-to-solver.patch
BuildArch: noarch
BuildRequires: cmake gettext systemd bash-completion python3-sphinx
@ -256,6 +254,38 @@ popd
%{_mandir}/man8/%{name}-automatic.8*
%changelog
* Mon May 6 2024 hanhuihui <hanhuihui5@huawei.com> - 4.14.0-19
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:dnf:Remove --duplicates and --oldinstallonly exit with 0 when nothing to remove and Add all candidates for reinstall to solver
* Fri Dec 29 2023 chenhaixing <chenhaixing@huawei.com> - 4.14.0-18
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:dnf:Fix bash completion due to sqlite changes
When parsing over a KVP list, do not return till the whole list is parsed
* Mon Aug 14 2023 herengui <herengui@kylinsec.com.cn> - 4.14.0-17
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:dnf:remove useless patch of loongarch64
dnf:recreate patch of sw64 and make arch sorted alphabetically
* 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
- SUG:NA
- DESC:dnf:remove patch about pidfile
* Tue Jun 27 2023 chenhaixing <chenhaixing@huawei.com> - 4.14.0-14
- Type:bugfix
- CVE:NA

View File

@ -1,50 +0,0 @@
From 0dfb26f901976a585ed29585d5cae694a11360d7 Mon Sep 17 00:00:00 2001
From: zhangrui <zhangrui182@huawei.com>
Dare: Mon, 21 Feb 2022 11:18:06 +0800
Subject: [PATCH] fix-pid-file-residue
---
dnf/lock.py | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
diff -urNp a/dnf/lock.py b/dnf/lock.py
--- a/dnf/lock.py 2020-07-14 20:33:25.746000000 +0800
+++ b/dnf/lock.py 2020-07-14 20:51:17.378000000 +0800
@@ -108,26 +108,25 @@ class ProcessLock(object):
# already locked by this process
return pid
+ if not os.access('/proc/%d/stat' % old_pid, os.F_OK):
+ # locked by a dead process, write our pid
+ os.lseek(fd, 0, os.SEEK_SET)
+ os.ftruncate(fd, 0)
+ os.write(fd, str(pid).encode('utf-8'))
+ return pid
+
try:
with open('/proc/%d/status' % old_pid) as f:
- for line in f:
- if not re.match(r'Name:(.*)(dnf|yum)$', line, re.I):
- os.write(fd, str(pid).encode('utf-8'))
- return pid
- except Exception as e:
+ if not re.findall(r'Name:(.*)(dnf|yum)', f.read(), re.I):
+ os.write(fd, str(pid).encode('utf-8'))
+ return pid
+ except OSError as e:
msg = _('Malformed lock file found: %s.\n'
'But pid in lock file is invalid '
'Ensure no other dnf/yum process is running and '
'remove the lock file manually.') % (self.target)
raise LockError(msg)
- if not os.access('/proc/%d/stat' % old_pid, os.F_OK):
- # locked by a dead process, write our pid
- os.lseek(fd, 0, os.SEEK_SET)
- os.ftruncate(fd, 0)
- os.write(fd, str(pid).encode('utf-8'))
- return pid
-
return old_pid
finally:

View File

@ -1,29 +0,0 @@
From ec8644e42ec2e0d0f98ea1aee3859b2c510f0cc0 Mon Sep 17 00:00:00 2001
From: chenhaixing <chenhaixing@huawei.com>
Date: Sat, 4 Jun 2022 17:49:53 +0800
Subject: [PATCH] verify-parameter
---
dnf/lock.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/dnf/lock.py b/dnf/lock.py
index ab05a3b..12378ec 100644
--- a/dnf/lock.py
+++ b/dnf/lock.py
@@ -116,7 +116,12 @@ class ProcessLock(object):
return pid
try:
- with open('/proc/%d/status' % old_pid) as f:
+ old_pid_path = f'/proc/{old_pid}/status'
+ true_old_pid_path = os.path.realpath(old_pid_path)
+ if not true_old_pid_path.startswith("/proc/"):
+ return old_pid
+
+ with open(true_old_pid_path) as f:
if not re.findall(r'Name:(.*)(dnf|yum)', f.read(), re.I):
os.write(fd, str(pid).encode('utf-8'))
return pid
--
2.27.0

View File

@ -1,44 +0,0 @@
From 7438ca37b6e688637a87cbdc87490e70a61e1829 Mon Sep 17 00:00:00 2001
From: fengtao40 <fengtao40@huawei.com>
Date: Sat, 13 Jun 2020 16:54:09 +0800
Subject: [PATCH] unlock-pidfile-if-current-proccess-is-NOT-dnf
---
dnf/lock.py | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/dnf/lock.py b/dnf/lock.py
index 13d8c27..589aa0a 100644
--- a/dnf/lock.py
+++ b/dnf/lock.py
@@ -32,6 +32,7 @@ import logging
import os
import threading
import time
+import re
logger = logging.getLogger("dnf")
@@ -106,6 +107,19 @@ class ProcessLock(object):
if old_pid == pid:
# already locked by this process
return pid
+
+ try:
+ with open('/proc/%d/status' % old_pid) as f:
+ for line in f:
+ if not re.match(r'Name:(.*)(dnf|yum)$', line, re.I):
+ os.write(fd, str(pid).encode('utf-8'))
+ return pid
+ except Exception as e:
+ msg = _('Malformed lock file found: %s.\n'
+ 'But pid in lock file is invalid '
+ 'Ensure no other dnf/yum process is running and '
+ 'remove the lock file manually.') % (self.target)
+ raise LockError(msg)
if not os.access('/proc/%d/stat' % old_pid, os.F_OK):
# locked by a dead process, write our pid
--
2.18.2