From e5157fc9f0ed3dc54800775563d5b48d162b86a2 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 17 Apr 2012 13:05:04 +0200 Subject: [PATCH] swapon: use only libmount for paths/tags evealuation libmount provides very simple API for paths and tags canonicalizations, let's use it, rather directly link to libblkid and lib/canonicalize.c. Signed-off-by: Karel Zak --- sys-utils/Makefile.am | 8 +++----- sys-utils/swapon.c | 24 +++++++++--------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/sys-utils/Makefile.am b/sys-utils/Makefile.am index 5b0a6eb6cf..a1fb3dd82c 100644 --- a/sys-utils/Makefile.am +++ b/sys-utils/Makefile.am @@ -137,12 +137,10 @@ dist_man_MANS += swapoff.8 swapon.8 swapon_SOURCES = \ swapon.c \ $(top_srcdir)/lib/blkdev.c \ - $(top_srcdir)/lib/canonicalize.c \ - $(top_srcdir)/lib/linux_version.c \ - $(top_srcdir)/lib/mangle.c + $(top_srcdir)/lib/linux_version.c -swapon_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir) -I$(ul_libmount_incdir) -swapon_LDADD = $(ul_libblkid_la) $(ul_libmount_la) +swapon_CFLAGS = $(AM_CFLAGS) -I$(ul_libmount_incdir) +swapon_LDADD = $(ul_libmount_la) endif if BUILD_LSCPU diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c index a28ff3c1b1..5904b6d60b 100644 --- a/sys-utils/swapon.c +++ b/sys-utils/swapon.c @@ -15,7 +15,6 @@ #include #include -#include #include #include "bitops.h" @@ -24,7 +23,6 @@ #include "pathnames.h" #include "swapheader.h" #include "mangle.h" -#include "canonicalize.h" #include "xalloc.h" #include "c.h" #include "closestream.h" @@ -161,9 +159,6 @@ static struct libmnt_table *get_swaps_table(void) swaps = mnt_new_table(); if (!swaps) return NULL; - if (!mntcache) - mntcache = mnt_new_cache(); - mnt_table_set_cache(swaps, mntcache); if (mnt_table_parse_swaps(swaps, NULL) != 0) return NULL; @@ -516,7 +511,7 @@ do_swapon(const char *orig_special, int prio, int fl_discard, int canonic) { printf(_("%s on %s\n"), progname, orig_special); if (!canonic) { - special = blkid_evaluate_spec(orig_special, NULL); + special = mnt_resolve_spec(orig_special, mntcache); if (!special) return cannot_find(orig_special); } @@ -551,14 +546,14 @@ cannot_find(const char *special) { static int swapon_by_label(const char *label, int prio, int dsc) { - const char *special = blkid_evaluate_tag("LABEL", label, NULL); + const char *special = mnt_resolve_tag("LABEL", label, mntcache); return special ? do_swapon(special, prio, dsc, CANONIC) : cannot_find(label); } static int swapon_by_uuid(const char *uuid, int prio, int dsc) { - const char *special = blkid_evaluate_tag("UUID", uuid, NULL); + const char *special = mnt_resolve_tag("UUID", uuid, mntcache); return special ? do_swapon(special, prio, dsc, CANONIC) : cannot_find(uuid); } @@ -571,7 +566,7 @@ do_swapoff(const char *orig_special, int quiet, int canonic) { printf(_("%s on %s\n"), progname, orig_special); if (!canonic) { - special = blkid_evaluate_spec(orig_special, NULL); + special = mnt_resolve_spec(orig_special, mntcache); if (!special) return cannot_find(orig_special); } @@ -590,13 +585,13 @@ do_swapoff(const char *orig_special, int quiet, int canonic) { static int swapoff_by_label(const char *label, int quiet) { - const char *special = blkid_evaluate_tag("LABEL", label, NULL); + const char *special = mnt_resolve_tag("LABEL", label, mntcache); return special ? do_swapoff(special, quiet, CANONIC) : cannot_find(label); } static int swapoff_by_uuid(const char *uuid, int quiet) { - const char *special = blkid_evaluate_tag("UUID", uuid, NULL); + const char *special = mnt_resolve_tag("UUID", uuid, mntcache); return special ? do_swapoff(special, quiet, CANONIC) : cannot_find(uuid); } @@ -637,7 +632,7 @@ swapon_all(void) { if (skip) continue; - special = blkid_evaluate_spec(fstab->mnt_fsname, NULL); + special = mnt_resolve_spec(fstab->mnt_fsname, mntcache); if (!special) { if (!nofail) status |= cannot_find(fstab->mnt_fsname); @@ -647,8 +642,6 @@ swapon_all(void) { if (!is_active_swap(special) && (!nofail || !access(special, R_OK))) status |= do_swapon(special, pri, dsc, CANONIC); - - free((void *) special); } fclose(fp); @@ -830,7 +823,7 @@ main_swapoff(int argc, char *argv[]) { if (!streq(fstab->mnt_type, MNTTYPE_SWAP)) continue; - special = blkid_evaluate_spec(fstab->mnt_fsname, NULL); + special = mnt_resolve_spec(fstab->mnt_fsname, mntcache); if (!special) continue; @@ -860,6 +853,7 @@ main(int argc, char *argv[]) { } mnt_init_debug(0); + mntcache = mnt_new_cache(); if (streq(progname, "swapon")) status = main_swapon(argc, argv); -- 2.47.3