]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
swapon: cleanup main()
authorKarel Zak <kzak@redhat.com>
Wed, 18 Apr 2012 10:44:14 +0000 (12:44 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 18 Apr 2012 10:44:14 +0000 (12:44 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/swapon.c

index 71b798caad60cca3fe4518fbf93b92936fe0062f..e7d0707e28939ec485ce2a67c1e626702d031690 100644 (file)
@@ -77,7 +77,6 @@ static int ifexists;
 static int fixpgsz;
 
 static int verbose;
-static char *progname;
 
 static const struct option longswaponopts[] = {
                /* swapon only */
@@ -106,7 +105,7 @@ static const struct option longswaponopts[] = {
 static void
 swapon_usage(FILE *out, int n) {
        fputs(_("\nUsage:\n"), out);
-       fprintf(out, _(" %s [options] [<spec>]\n"), progname);
+       fprintf(out, _(" %s [options] [<spec>]\n"), program_invocation_name);
 
        fputs(_("\nOptions:\n"), out);
        fputs(_(" -a, --all              enable all swaps from /etc/fstab\n"
@@ -459,7 +458,7 @@ do_swapon(const char *orig_special, int prio, int fl_discard, int canonic) {
        int flags = 0;
 
        if (verbose)
-               printf(_("%s on %s\n"), progname, orig_special);
+               printf(_("swapon %s\n"), orig_special);
 
        if (!canonic) {
                special = mnt_resolve_spec(orig_special, mntcache);
@@ -547,12 +546,20 @@ swapon_all(void) {
        return status;
 }
 
-static int
-main_swapon(int argc, char *argv[]) {
+int main(int argc, char *argv[])
+{
        int status = 0;
        int c;
        size_t i;
 
+       setlocale(LC_ALL, "");
+       bindtextdomain(PACKAGE, LOCALEDIR);
+       textdomain(PACKAGE);
+       atexit(close_stdout);
+
+       mnt_init_debug(0);
+       mntcache = mnt_new_cache();
+
        while ((c = getopt_long(argc, argv, "ahdefp:svVL:U:",
                                longswaponopts, NULL)) != -1) {
                switch (c) {
@@ -587,8 +594,8 @@ main_swapon(int argc, char *argv[]) {
                        ++verbose;
                        break;
                case 'V':               /* version */
-                       printf(_("%s (%s)\n"), progname, PACKAGE_STRING);
-                       exit(EXIT_SUCCESS);
+                       printf(UTIL_LINUX_VERSION);
+                       return EXIT_SUCCESS;
                case 0:
                        break;
                case '?':
@@ -601,7 +608,7 @@ main_swapon(int argc, char *argv[]) {
        if (!all && !numof_labels() && numof_uuids() && *argv == NULL)
                swapon_usage(stderr, 2);
 
-       if (ifexists && (!all || strcmp(progname, "swapon")))
+       if (ifexists && !all)
                swapon_usage(stderr, 1);
 
        if (all)
@@ -616,31 +623,8 @@ main_swapon(int argc, char *argv[]) {
        while (*argv != NULL)
                status |= do_swapon(*argv++, priority, discard, !CANONIC);
 
-       return status;
-}
-
-int
-main(int argc, char *argv[]) {
-
-       int status;
-
-       setlocale(LC_ALL, "");
-       bindtextdomain(PACKAGE, LOCALEDIR);
-       textdomain(PACKAGE);
-       atexit(close_stdout);
-
-       progname = program_invocation_short_name;
-       if (!progname) {
-               char *p = strrchr(argv[0], '/');
-               progname = p ? p+1 : argv[0];
-       }
-
-       mnt_init_debug(0);
-       mntcache = mnt_new_cache();
-
-       status = main_swapon(argc, argv);
-
        free_tables();
        mnt_free_cache(mntcache);
+
        return status;
 }