Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/distrib/utils/sysinst eliminate useless booleans and use the...



details:   https://anonhg.NetBSD.org/src/rev/55cd74465db4
branches:  trunk
changeset: 772488:55cd74465db4
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jan 05 21:29:24 2012 +0000

description:
eliminate useless booleans and use the file pointers as conditionals.

diffstat:

 distrib/utils/sysinst/defs.h         |   4 +---
 distrib/utils/sysinst/disks.c        |   6 +++---
 distrib/utils/sysinst/main.c         |  13 +++++--------
 distrib/utils/sysinst/mbr.c          |   4 ++--
 distrib/utils/sysinst/net.c          |   6 +++---
 distrib/utils/sysinst/run.c          |  35 ++++++++++++++++++-----------------
 distrib/utils/sysinst/savenewlabel.c |  10 +++++-----
 distrib/utils/sysinst/target.c       |  10 +++++-----
 distrib/utils/sysinst/util.c         |   6 +++---
 9 files changed, 45 insertions(+), 49 deletions(-)

diffs (truncated from 384 to 300 lines):

diff -r 15a927f24329 -r 55cd74465db4 distrib/utils/sysinst/defs.h
--- a/distrib/utils/sysinst/defs.h      Thu Jan 05 21:22:49 2012 +0000
+++ b/distrib/utils/sysinst/defs.h      Thu Jan 05 21:29:24 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.158 2012/01/05 21:22:49 christos Exp $      */
+/*     $NetBSD: defs.h,v 1.159 2012/01/05 21:29:24 christos Exp $      */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -231,8 +231,6 @@
 
 /* loging variables */
 
-int logging;
-int scripting;
 FILE *logfp;
 FILE *script;
 
diff -r 15a927f24329 -r 55cd74465db4 distrib/utils/sysinst/disks.c
--- a/distrib/utils/sysinst/disks.c     Thu Jan 05 21:22:49 2012 +0000
+++ b/distrib/utils/sysinst/disks.c     Thu Jan 05 21:29:24 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disks.c,v 1.120 2012/01/05 21:22:49 christos Exp $ */
+/*     $NetBSD: disks.c,v 1.121 2012/01/05 21:29:24 christos Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -651,7 +651,7 @@
        /* Create the fstab. */
        make_target_dir("/etc");
        f = target_fopen("/etc/fstab", "w");
-       if (logging)
+       if (logfp)
                (void)fprintf(logfp,
                    "Creating %s/etc/fstab.\n", target_prefix());
        scripting_fprintf(NULL, "cat <<EOF >%s/etc/fstab\n", target_prefix());
@@ -659,7 +659,7 @@
        if (f == NULL) {
 #ifndef DEBUG
                msg_display(MSG_createfstab);
-               if (logging)
+               if (logfp)
                        (void)fprintf(logfp, "Failed to make /etc/fstab!\n");
                process_menu(MENU_ok, NULL);
                return 1;
diff -r 15a927f24329 -r 55cd74465db4 distrib/utils/sysinst/main.c
--- a/distrib/utils/sysinst/main.c      Thu Jan 05 21:22:49 2012 +0000
+++ b/distrib/utils/sysinst/main.c      Thu Jan 05 21:29:24 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.61 2011/09/16 15:42:28 joerg Exp $  */
+/*     $NetBSD: main.c,v 1.62 2012/01/05 21:29:24 christos Exp $       */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -60,8 +60,6 @@
 static void process_f_flag(char *);
 
 static int exit_cleanly = 0;   /* Did we finish nicely? */
-int logging;                   /* are we logging everything? */
-int scripting;                 /* are we building a script? */
 FILE *logfp;                   /* log file */
 FILE *script;                  /* script file */
 
@@ -126,13 +124,10 @@
        WINDOW *win;
        int ch;
 
-       logging = 0; /* shut them off unless turned on by the user */
        init();
 #ifdef DEBUG
        log_flip();
 #endif
-       scripting = 0;
-
        /* Check for TERM ... */
        if (!getenv("TERM")) {
                (void)fprintf(stderr,
@@ -407,16 +402,18 @@
 
        endwin();
 
-       if (logging) {
+       if (logfp) {
                fprintf(logfp, "Log ended at: %s\n", asctime(localtime(&tloc)));
                fflush(logfp);
                fclose(logfp);
+               logfp = NULL;
        }
-       if (scripting) {
+       if (script) {
                fprintf(script, "# Script ended at: %s\n",
                    asctime(localtime(&tloc)));
                fflush(script);
                fclose(script);
+               script = NULL;
        }
 
        if (!exit_cleanly)
diff -r 15a927f24329 -r 55cd74465db4 distrib/utils/sysinst/mbr.c
--- a/distrib/utils/sysinst/mbr.c       Thu Jan 05 21:22:49 2012 +0000
+++ b/distrib/utils/sysinst/mbr.c       Thu Jan 05 21:29:24 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mbr.c,v 1.88 2011/10/17 16:35:22 mbalmer Exp $ */
+/*     $NetBSD: mbr.c,v 1.89 2012/01/05 21:29:24 christos Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1287,7 +1287,7 @@
                        msg_display(MSG_ovrwrite);
                        process_menu(MENU_noyes, NULL);
                        if (!yesno) {
-                               if (logging)
+                               if (logfp)
                                        (void)fprintf(logfp, "User answered no to destroy other data, aborting.\n");
                                return 0;
                        }
diff -r 15a927f24329 -r 55cd74465db4 distrib/utils/sysinst/net.c
--- a/distrib/utils/sysinst/net.c       Thu Jan 05 21:22:49 2012 +0000
+++ b/distrib/utils/sysinst/net.c       Thu Jan 05 21:29:24 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: net.c,v 1.127 2011/04/04 08:30:13 mbalmer Exp $        */
+/*     $NetBSD: net.c,v 1.128 2012/01/05 21:29:24 christos Exp $       */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -241,7 +241,7 @@
 
        textsize = collect(T_OUTPUT, &textbuf, "/sbin/ifconfig -a 2>/dev/null");
        if (textsize < 0) {
-               if (logging)
+               if (logfp)
                        (void)fprintf(logfp,
                            "Aborting: Could not run ifconfig.\n");
                (void)fprintf(stderr, "Could not run ifconfig.");
@@ -820,7 +820,7 @@
                ) {
                f = fopen("/etc/resolv.conf", "w");
                if (f == NULL) {
-                       if (logging)
+                       if (logfp)
                                (void)fprintf(logfp,
                                    "%s", msg_string(MSG_resolv));
                        (void)fprintf(stderr, "%s", msg_string(MSG_resolv));
diff -r 15a927f24329 -r 55cd74465db4 distrib/utils/sysinst/run.c
--- a/distrib/utils/sysinst/run.c       Thu Jan 05 21:22:49 2012 +0000
+++ b/distrib/utils/sysinst/run.c       Thu Jan 05 21:29:24 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: run.c,v 1.68 2011/07/06 01:18:08 mrg Exp $     */
+/*     $NetBSD: run.c,v 1.69 2012/01/05 21:29:24 christos Exp $        */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -82,7 +82,8 @@
 {
        wprintw(m->mw, "%s: %s",
                msg_string(opt ? MSG_Scripting : MSG_Logging),
-               msg_string((opt ? scripting : logging) ? MSG_On : MSG_Off));
+               msg_string((opt ? script != NULL : logfp != NULL) ?
+                   MSG_On : MSG_Off));
 }
 
 void
@@ -96,7 +97,7 @@
 
        if (menu_no < 0) {
                (void)fprintf(stderr, "Dynamic menu creation failed.\n");
-               if (logging)
+               if (logfp)
                        (void)fprintf(logfp, "Dynamic menu creation failed.\n");
                exit(EXIT_FAILURE);
        }
@@ -111,15 +112,14 @@
        time_t tloc;
 
        (void)time(&tloc);
-       if (logging == 1) {
-               logging = 0;
+       if (logfp) {
                fprintf(logfp, "Log ended at: %s\n", asctime(localtime(&tloc)));
                fflush(logfp);
                fclose(logfp);
+               logfp = NULL;
        } else {
                logfp = fopen("/tmp/sysinst.log", "a");
                if (logfp != NULL) {
-                       logging = 1;
                        fprintf(logfp,
                            "Log started at: %s\n", asctime(localtime(&tloc)));
                        fflush(logfp);
@@ -137,15 +137,14 @@
        time_t tloc;
 
        (void)time(&tloc);
-       if (scripting == 1) {
+       if (script) {
                scripting_fprintf(NULL, "# Script ended at: %s\n", asctime(localtime(&tloc)));
-               scripting = 0;
                fflush(script);
                fclose(script);
+               script = NULL;
        } else {
                script = fopen("/tmp/sysinst.sh", "w");
                if (script != NULL) {
-                       scripting = 1;
                        scripting_fprintf(NULL, "#!/bin/sh\n");
                        scripting_fprintf(NULL, "# Script started at: %s\n",
                            asctime(localtime(&tloc)));
@@ -410,9 +409,9 @@
                }
        }
 
-       if (logging)
+       if (logfp)
                fflush(logfp);
-       if (scripting)
+       if (script)
                fflush(script);
 
        child = fork();
@@ -434,13 +433,15 @@
                rtt.c_lflag |= (ICANON|ECHO);
                (void)tcsetattr(slave, TCSANOW, &rtt);
                login_tty(slave);
-               if (logging) {
+               if (logfp) {
                        fprintf(logfp, "executing: %s\n", scmd);
                        fclose(logfp);
+                       logfp = NULL;
                }
-               if (scripting) {
+               if (script) {
                        fprintf(script, "%s\n", scmd);
                        fclose(script);
+                       script = NULL;
                }
                if (strcmp(args[0], "cd") == 0 && strcmp(args[2], "&&") == 0) {
                        target_chdir_or_die(args[1]);
@@ -483,7 +484,7 @@
        for (selectfailed = 0;;) {
                if (selectfailed) {
                        const char mmsg[] = "select(2) failed but no child died?";
-                       if (logging)
+                       if (logfp)
                                (void)fprintf(logfp, mmsg);
                        errx(1, mmsg);
                }
@@ -496,7 +497,7 @@
                if (i < 0) {
                        if (errno != EINTR) {
                                warn("select");
-                               if (logging)
+                               if (logfp)
                                        (void)fprintf(logfp,
                                            "select failure: %s\n",
                                            strerror(errno));
@@ -528,7 +529,7 @@
                        }
                        if (*cp == 0 || flags & RUN_SILENT)
                                continue;
-                       if (logging) {
+                       if (logfp) {
                                fprintf(logfp, "%s", cp);
                                fflush(logfp);
                        }
@@ -548,7 +549,7 @@
        }
        close(master);
        close(slave);
-       if (logging)
+       if (logfp)
                fflush(logfp);
 
        /* from here on out, we take tty signals ourselves */
diff -r 15a927f24329 -r 55cd74465db4 distrib/utils/sysinst/savenewlabel.c
--- a/distrib/utils/sysinst/savenewlabel.c      Thu Jan 05 21:22:49 2012 +0000
+++ b/distrib/utils/sysinst/savenewlabel.c      Thu Jan 05 21:29:24 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: savenewlabel.c,v 1.10 2012/01/05 21:22:49 christos Exp $       */
+/*     $NetBSD: savenewlabel.c,v 1.11 2012/01/05 21:29:25 christos Exp $       */
 
 /*
  * Copyright 1997 Jonathan Stone
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: savenewlabel.c,v 1.10 2012/01/05 21:22:49 christos Exp $");
+__RCSID("$NetBSD: savenewlabel.c,v 1.11 2012/01/05 21:29:25 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -68,13 +68,13 @@
 
        /* Create /etc/disktab */
        f = fopen("/tmp/disktab", "w");
-       if (logging)
+       if (logfp)
                (void)fprintf(logfp, "Creating disklabel %s\n", bsddiskname);
        scripting_fprintf(NULL, "cat <<EOF >>/etc/disktab\n");
        if (f == NULL) {



Home | Main Index | Thread Index | Old Index