14 Star 3 Fork 67

src-openEuler/util-linux
关闭

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-swapoff-clean-up-tag-resolution.patch 2.89 KB
一键复制 编辑 原始数据 按行查看 历史
fly_fzc 提交于 2025-06-26 10:45 +08:00 . backport community patches
From 702f6f0178fa74cf66a13813bd40e5c7839cfe6a Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Wed, 9 Apr 2025 10:51:59 +0200
Subject: [PATCH] swapoff: clean up tag resolution
- Rename swapoff_resolve_tag() to resolve_swapfile_tag() and retain
only code relevant to swapfiles.
- Always call mnt_resolve_*() before resolve_swapfile_tag() to resolve
tags/paths on standard block devices.
- Call free() for resolve_swapfile_tag() to avoid memory leaks.
Signed-off-by: Karel Zak <kzak@redhat.com>
---
sys-utils/swapoff.c | 34 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/sys-utils/swapoff.c b/sys-utils/swapoff.c
index 5677d87a152..ab7e4ca11e1 100644
--- a/sys-utils/swapoff.c
+++ b/sys-utils/swapoff.c
@@ -54,20 +54,13 @@ static int all;
* mnt_resolve_tag() and mnt_resolve_spec() works with system visible block
* devices only.
*/
-static char *swapoff_resolve_tag(const char *name, const char *value,
- struct libmnt_cache *cache)
+static char *resolve_swapfile_tag(const char *name, const char *value)
{
char *path;
struct libmnt_table *tb;
struct libmnt_iter *itr;
struct libmnt_fs *fs;
- /* this is usual case for block devices (and it's really fast as it uses
- * udev /dev/disk/by-* symlinks by default */
- path = mnt_resolve_tag(name, value, cache);
- if (path)
- return path;
-
/* try regular files from /proc/swaps */
tb = get_swaps();
if (!tb)
@@ -103,6 +96,7 @@ static char *swapoff_resolve_tag(const char *name, const char *value,
static int do_swapoff(const char *orig_special, int quiet, int canonic)
{
const char *special = orig_special;
+ char *buf = NULL;
int rc = SWAPOFF_EX_OK;
if (verbose)
@@ -113,12 +107,14 @@ static int do_swapoff(const char *orig_special, int quiet, int canonic)
special = mnt_resolve_spec(orig_special, mntcache);
if (!special && blkid_parse_tag_string(orig_special, &n, &v) == 0) {
- special = swapoff_resolve_tag(n, v, mntcache);
+ special = buf = resolve_swapfile_tag(n, v);
free(n);
free(v);
}
- if (!special)
- return cannot_find(orig_special);
+ if (!special) {
+ rc = cannot_find(orig_special);
+ goto done;
+ }
}
if (swapoff(special) == 0)
@@ -140,13 +136,25 @@ static int do_swapoff(const char *orig_special, int quiet, int canonic)
}
}
+done:
+ free(buf);
return rc;
}
static int swapoff_by(const char *name, const char *value, int quiet)
{
- const char *special = swapoff_resolve_tag(name, value, mntcache);
- return special ? do_swapoff(special, quiet, CANONIC) : cannot_find(value);
+ const char *special;
+ char *buf = NULL;
+ int rc;
+
+ special = mnt_resolve_tag(name, value, mntcache);
+ if (!special)
+ special = buf = resolve_swapfile_tag(name, value);
+
+ rc = special ? do_swapoff(special, quiet, CANONIC) : cannot_find(value);
+ free(buf);
+
+ return rc;
}
static void __attribute__((__noreturn__)) usage(void)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/util-linux.git
git@gitee.com:src-openeuler/util-linux.git
src-openeuler
util-linux
util-linux
master

搜索帮助