eliminate useless booleans and use the file pointers as conditionals.
This commit is contained in:
parent
c03a5a1e01
commit
4ea9182c55
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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, void *arg)
|
|||
{
|
||||
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 **args, struct winsize *win, int flags,
|
|||
}
|
||||
}
|
||||
|
||||
if (logging)
|
||||
if (logfp)
|
||||
fflush(logfp);
|
||||
if (scripting)
|
||||
if (script)
|
||||
fflush(script);
|
||||
|
||||
child = fork();
|
||||
|
@ -434,13 +433,15 @@ launch_subwin(WINDOW **actionwin, char **args, struct winsize *win, int flags,
|
|||
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 **args, struct winsize *win, int flags,
|
|||
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 **args, struct winsize *win, int flags,
|
|||
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 **args, struct winsize *win, int flags,
|
|||
}
|
||||
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 **args, struct winsize *win, int flags,
|
|||
}
|
||||
close(master);
|
||||
close(slave);
|
||||
if (logging)
|
||||
if (logfp)
|
||||
fflush(logfp);
|
||||
|
||||
/* from here on out, we take tty signals ourselves */
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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 must_succeed)
|
|||
/* 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 must_succeed)
|
|||
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);
|
||||
|
|
|
@ -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 setupdone_msg, msg success_msg, msg failure_
|
|||
|
||||
/* 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 *fmt, va_list ap)
|
|||
|
||||
if (f)
|
||||
(void)vfprintf(f, fmt, ap);
|
||||
if (scripting)
|
||||
if (script)
|
||||
(void)vfprintf(script, fmt, ap);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue