]> err.no Git - util-linux/commitdiff
swapon: simplify spec to devname conversion
authorKarel Zak <kzak@redhat.com>
Mon, 2 Mar 2009 13:21:03 +0000 (14:21 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 3 Mar 2009 14:20:45 +0000 (15:20 +0100)
We needn't to use spec_to_devname() and check for pseudo filesystems.
The swap{on,off} is always checking for the 'swap' fstype.

This patch also removes the dependence on xmalloc.c.

Signed-off-by: Karel Zak <kzak@redhat.com>
mount/Makefile.am
mount/swapon.c

index b34df3c3b3619dc650eb55297bbad1c323ed755a..7714efbcf97c938bdfd754aa6ffdc1f7e51d8a14 100644 (file)
@@ -6,12 +6,12 @@ bin_PROGRAMS = mount umount
 sbin_PROGRAMS = losetup swapon
 dist_man_MANS = fstab.5 mount.8 swapoff.8 swapon.8 umount.8 losetup.8
 
-# generic sources for all programs (mount, umount, swapon, losetup)
-srcs_common = sundries.c xmalloc.c ../lib/canonicalize.c
+# generic sources for all programs (mount, umount, losetup)
+srcs_common = sundries.c xmalloc.c ../lib/canonicalize.c sundries.h xmalloc.h
 
 # generic header for mount and umount
 hdrs_mount = fstab.h mount_mntent.h mount_constants.h \
-       lomount.h xmalloc.h getusername.h loop.h sundries.h
+       lomount.h getusername.h loop.h
 
 # generic sources for mount and umount
 srcs_mount = fstab.c mount_mntent.c getusername.c lomount.c devname.c devname.h \
@@ -38,12 +38,12 @@ umount_CFLAGS = $(SUID_CFLAGS) $(AM_CFLAGS) $(cflags_common)
 umount_LDFLAGS = $(SUID_LDFLAGS) $(AM_LDFLAGS)
 umount_LDADD = $(ldadd_common)
 
-swapon_SOURCES = swapon.c swap_constants.h $(srcs_common) devname.c devname.h \
-       ../lib/linux_version.c ../lib/blkdev.c ../lib/fsprobe.c
+swapon_SOURCES = swapon.c swap_constants.h ../lib/linux_version.c \
+       ../lib/blkdev.c ../lib/fsprobe.c ../lib/canonicalize.c
 swapon_CFLAGS = $(cflags_common)
 swapon_LDADD = $(ldadd_common)
 
-losetup_SOURCES = lomount.c $(srcs_common) loop.h lomount.h xmalloc.h sundries.h
+losetup_SOURCES = lomount.c $(srcs_common) loop.h lomount.h
 losetup_CPPFLAGS = -DMAIN $(AM_CPPFLAGS)
 
 mount_static_LDADD =
index 83c0404fbfccd9e192589efbc5cb48547c30d31f..b0def44a5874d9ccb276fcace376c7b1bcd6e31c 100644 (file)
@@ -1,7 +1,6 @@
 /*
  * A swapon(8)/swapoff(8) for Linux 0.99.
  */
-#include <ctype.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <getopt.h>
 #include <sys/wait.h>
 #include <fcntl.h>
 #include <stdint.h>
+
 #include "bitops.h"
 #include "blkdev.h"
-#include "xmalloc.h"
 #include "swap_constants.h"
 #include "nls.h"
 #include "fsprobe.h"
-#include "devname.h"
 #include "pathnames.h"
-#include "sundries.h"
 #include "swapheader.h"
 
 #define PATH_MKSWAP    "/sbin/mkswap"
@@ -50,11 +47,14 @@ enum {
        SIG_SWSUSPEND
 };
 
-int all = 0;
+int all;
 int priority = -1;     /* non-prioritized swap by default */
 
 /* If true, don't complain if the device/file doesn't exist */
-int ifexists = 0;
+int ifexists;
+
+int verbose;
+char *progname;
 
 static struct option longswaponopts[] = {
                /* swapon only */
@@ -336,7 +336,7 @@ do_swapon(const char *orig_special, int prio, int canonic) {
                printf(_("%s on %s\n"), progname, orig_special);
 
        if (!canonic) {
-               special = spec_to_devname(orig_special);
+               special = fsprobe_get_devname_by_spec(orig_special);
                if (!special)
                        return cannot_find(orig_special);
        }
@@ -492,7 +492,7 @@ do_swapoff(const char *orig_special, int quiet, int canonic) {
                printf(_("%s on %s\n"), progname, orig_special);
 
        if (!canonic) {
-               special = spec_to_devname(orig_special);
+               special = fsprobe_get_devname_by_spec(orig_special);
                if (!special)
                        return cannot_find(orig_special);
        }
@@ -563,7 +563,7 @@ swapon_all(void) {
                if (skip)
                        continue;
 
-               special = spec_to_devname(fstab->mnt_fsname);
+               special = fsprobe_get_devname_by_spec(fstab->mnt_fsname);
                if (!special) {
                        if (!ifexists)
                                status |= cannot_find(fstab->mnt_fsname);
@@ -587,12 +587,16 @@ static const char **ulist = NULL;
 static int ulct = 0;
 
 static void addl(const char *label) {
-       llist = (const char **) xrealloc(llist, (++llct) * sizeof(char *));
+       llist = (const char **) realloc(llist, (++llct) * sizeof(char *));
+       if (!llist)
+               exit(EXIT_FAILURE);
        llist[llct-1] = label;
 }
 
 static void addu(const char *uuid) {
-       ulist = (const char **) xrealloc(ulist, (++ulct) * sizeof(char *));
+       ulist = (const char **) realloc(ulist, (++ulct) * sizeof(char *));
+       if (!ulist)
+               exit(EXIT_FAILURE);
        ulist[ulct-1] = uuid;
 }
 
@@ -744,7 +748,7 @@ main_swapoff(int argc, char *argv[]) {
                        if (!streq(fstab->mnt_type, MNTTYPE_SWAP))
                                continue;
 
-                       special = spec_to_devname(fstab->mnt_fsname);
+                       special = fsprobe_get_devname_by_spec(fstab->mnt_fsname);
                        if (!special)
                                continue;