Module Name:    src
Committed By:   christos
Date:           Thu Jan  5 21:29:25 UTC 2012

Modified Files:
        src/distrib/utils/sysinst: defs.h disks.c main.c mbr.c net.c run.c
            savenewlabel.c target.c util.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 src/distrib/utils/sysinst/defs.h
cvs rdiff -u -r1.120 -r1.121 src/distrib/utils/sysinst/disks.c
cvs rdiff -u -r1.61 -r1.62 src/distrib/utils/sysinst/main.c
cvs rdiff -u -r1.88 -r1.89 src/distrib/utils/sysinst/mbr.c
cvs rdiff -u -r1.127 -r1.128 src/distrib/utils/sysinst/net.c
cvs rdiff -u -r1.68 -r1.69 src/distrib/utils/sysinst/run.c
cvs rdiff -u -r1.10 -r1.11 src/distrib/utils/sysinst/savenewlabel.c
cvs rdiff -u -r1.53 -r1.54 src/distrib/utils/sysinst/target.c
cvs rdiff -u -r1.171 -r1.172 src/distrib/utils/sysinst/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/utils/sysinst/defs.h
diff -u src/distrib/utils/sysinst/defs.h:1.158 src/distrib/utils/sysinst/defs.h:1.159
--- src/distrib/utils/sysinst/defs.h:1.158	Thu Jan  5 16:22:49 2012
+++ src/distrib/utils/sysinst/defs.h	Thu Jan  5 16:29:24 2012
@@ -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 @@ const char *multname;
 
 /* loging variables */
 
-int logging;
-int scripting;
 FILE *logfp;
 FILE *script;
 

Index: src/distrib/utils/sysinst/disks.c
diff -u src/distrib/utils/sysinst/disks.c:1.120 src/distrib/utils/sysinst/disks.c:1.121
--- src/distrib/utils/sysinst/disks.c:1.120	Thu Jan  5 16:22:49 2012
+++ src/distrib/utils/sysinst/disks.c	Thu Jan  5 16:29:24 2012
@@ -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 @@ make_fstab(void)
 	/* 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 @@ make_fstab(void)
 	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;

Index: src/distrib/utils/sysinst/main.c
diff -u src/distrib/utils/sysinst/main.c:1.61 src/distrib/utils/sysinst/main.c:1.62
--- src/distrib/utils/sysinst/main.c:1.61	Fri Sep 16 11:42:28 2011
+++ src/distrib/utils/sysinst/main.c	Thu Jan  5 16:29:24 2012
@@ -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 cleanup(void);
 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 @@ main(int argc, char **argv)
 	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 @@ cleanup(void)
 
 	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)

Index: src/distrib/utils/sysinst/mbr.c
diff -u src/distrib/utils/sysinst/mbr.c:1.88 src/distrib/utils/sysinst/mbr.c:1.89
--- src/distrib/utils/sysinst/mbr.c:1.88	Mon Oct 17 12:35:22 2011
+++ src/distrib/utils/sysinst/mbr.c	Thu Jan  5 16:29:24 2012
@@ -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 @@ edit_mbr(mbr_info_t *mbri)
 			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;
 			}

Index: src/distrib/utils/sysinst/net.c
diff -u src/distrib/utils/sysinst/net.c:1.127 src/distrib/utils/sysinst/net.c:1.128
--- src/distrib/utils/sysinst/net.c:1.127	Mon Apr  4 04:30:13 2011
+++ src/distrib/utils/sysinst/net.c	Thu Jan  5 16:29:24 2012
@@ -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 @@ get_ifconfig_info(void)
 
 	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 @@ done:
 		) {
 		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));

Index: src/distrib/utils/sysinst/run.c
diff -u src/distrib/utils/sysinst/run.c:1.68 src/distrib/utils/sysinst/run.c:1.69
--- src/distrib/utils/sysinst/run.c:1.68	Tue Jul  5 21:18:08 2011
+++ src/distrib/utils/sysinst/run.c	Thu Jan  5 16:29:24 2012
@@ -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 @@ log_menu_label(menudesc *m, int opt, voi
 {
 	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 @@ do_logging(void)
 
 	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 @@ log_flip(menudesc *m, void *arg)
 	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 @@ script_flip(menudesc *m, void *arg)
 	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 @@ launch_subwin(WINDOW **actionwin, char *
 		}
 	}
 
-	if (logging)
+	if (logfp)
 		fflush(logfp);
-	if (scripting)
+	if (script)
 		fflush(script);
 
 	child = fork();
@@ -434,13 +433,15 @@ launch_subwin(WINDOW **actionwin, char *
 		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 @@ launch_subwin(WINDOW **actionwin, char *
 	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 @@ launch_subwin(WINDOW **actionwin, char *
 		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 @@ launch_subwin(WINDOW **actionwin, char *
 			}
 			if (*cp == 0 || flags & RUN_SILENT)
 				continue;
-			if (logging) {
+			if (logfp) {
 				fprintf(logfp, "%s", cp);
 				fflush(logfp);
 			}
@@ -548,7 +549,7 @@ launch_subwin(WINDOW **actionwin, char *
 	}
 	close(master);
 	close(slave);
-	if (logging)
+	if (logfp)
 		fflush(logfp);
 
 	/* from here on out, we take tty signals ourselves */

Index: src/distrib/utils/sysinst/savenewlabel.c
diff -u src/distrib/utils/sysinst/savenewlabel.c:1.10 src/distrib/utils/sysinst/savenewlabel.c:1.11
--- src/distrib/utils/sysinst/savenewlabel.c:1.10	Thu Jan  5 16:22:49 2012
+++ src/distrib/utils/sysinst/savenewlabel.c	Thu Jan  5 16:29:25 2012
@@ -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 @@ savenewlabel(partinfo *lp, int nparts)
 
 	/* 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) {
 		endwin();
 		(void)fprintf(stderr, "Could not open /etc/disktab");
-		if (logging)
+		if (logfp)
 			(void)fprintf(logfp,
 			    "Failed to open /etc/disktab for appending.\n");
 		exit (1);
@@ -87,7 +87,7 @@ savenewlabel(partinfo *lp, int nparts)
 	scripting_fprintf(f, "\t:se#%d:%s\\\n", sectorsize, doessf);
 	if ((size_t)nparts > __arraycount(bsdlabel)) {
 		nparts = __arraycount(bsdlabel);
-		if (logging)
+		if (logfp)
 			(void)fprintf(logfp, "nparts limited to %d.\n", nparts);
 	}
 	for (i = 0; i < nparts; i++) {

Index: src/distrib/utils/sysinst/target.c
diff -u src/distrib/utils/sysinst/target.c:1.53 src/distrib/utils/sysinst/target.c:1.54
--- src/distrib/utils/sysinst/target.c:1.53	Thu Jan  5 16:22:49 2012
+++ src/distrib/utils/sysinst/target.c	Thu Jan  5 16:29:25 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: target.c,v 1.53 2012/01/05 21:22:49 christos Exp $	*/
+/*	$NetBSD: target.c,v 1.54 2012/01/05 21:29:25 christos Exp $	*/
 
 /*
  * Copyright 1997 Jonathan Stone
@@ -71,7 +71,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: target.c,v 1.53 2012/01/05 21:22:49 christos Exp $");
+__RCSID("$NetBSD: target.c,v 1.54 2012/01/05 21:29:25 christos Exp $");
 #endif
 
 /*
@@ -284,11 +284,11 @@ do_target_chdir(const char *dir, int mus
 	/* chdir returns -1 on error and sets errno. */
 	if (chdir(tgt_dir) < 0)
 		error = errno;
-	if (logging) {
+	if (logfp) {
 		fprintf(logfp, "cd to %s\n", tgt_dir);
 		fflush(logfp);
 	}
-	if (scripting) {
+	if (script) {
 		scripting_fprintf(NULL, "cd %s\n", tgt_dir);
 		fflush(script);
 	}
@@ -296,7 +296,7 @@ do_target_chdir(const char *dir, int mus
 	if (error && must_succeed) {
 		fprintf(stderr, msg_string(MSG_realdir),
 		       target_prefix(), strerror(error));
-		if (logging)
+		if (logfp)
 			fprintf(logfp, msg_string(MSG_realdir),
 			       target_prefix(), strerror(error));
 		exit(1);

Index: src/distrib/utils/sysinst/util.c
diff -u src/distrib/utils/sysinst/util.c:1.171 src/distrib/utils/sysinst/util.c:1.172
--- src/distrib/utils/sysinst/util.c:1.171	Sun Jan  1 18:26:22 2012
+++ src/distrib/utils/sysinst/util.c	Thu Jan  5 16:29:25 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.171 2012/01/01 23:26:22 riz Exp $	*/
+/*	$NetBSD: util.c,v 1.172 2012/01/05 21:29:25 christos Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -967,7 +967,7 @@ get_and_unpack_sets(int update, msg setu
 
 	/* Ensure mountpoint for distribution files exists in current root. */
 	(void)mkdir("/mnt2", S_IRWXU| S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH);
-	if (scripting)
+	if (script)
 		(void)fprintf(script, "mkdir -m 755 /mnt2\n");
 
 	/* reset failure/success counters */
@@ -1411,7 +1411,7 @@ scripting_vfprintf(FILE *f, const char *
 
 	if (f)
 		(void)vfprintf(f, fmt, ap);
-	if (scripting)
+	if (script)
 		(void)vfprintf(script, fmt, ap);
 }
 

Reply via email to