summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1997-02-14 20:59:07 +0000
committerjkh <jkh@FreeBSD.org>1997-02-14 20:59:07 +0000
commit5dc52e3240da65ca0ddeb05e574d447b212a235e (patch)
tree7b32acba55b6ee0e882a4479d2609fa691b7b9eb
parent5a03931ab59c699dc77bb35946d102f53e43c6ad (diff)
downloadFreeBSD-src-5dc52e3240da65ca0ddeb05e574d447b212a235e.zip
FreeBSD-src-5dc52e3240da65ca0ddeb05e574d447b212a235e.tar.gz
o Try to be more aggressive about reading in old configuration data
so that we're more useful in multi-user mode. This is still not 100%, but it pulls in a lot more than it used to. Some of the "composite" variables in /etc/sysconfig are going to take more work. o Always write /etc/resolv.conf and /etc/hosts if it makes sense to do so. o Reset media properly when reselecting. Longstanding bogon. o Pull SIGPIPE handling out of package.c; I'm actually hoping to handle this differently shortly. o Fix bug where cancel in TCP setup dialog still checked data fields. I think this closes a PR, but I will have to go look.
-rw-r--r--release/sysinstall/config.c110
-rw-r--r--release/sysinstall/main.c3
-rw-r--r--release/sysinstall/media.c60
-rw-r--r--release/sysinstall/package.c31
-rw-r--r--release/sysinstall/sysinstall.h1
-rw-r--r--release/sysinstall/tcpip.c2
-rw-r--r--usr.sbin/sade/config.c110
-rw-r--r--usr.sbin/sade/main.c3
-rw-r--r--usr.sbin/sade/sade.h1
-rw-r--r--usr.sbin/sysinstall/config.c110
-rw-r--r--usr.sbin/sysinstall/main.c3
-rw-r--r--usr.sbin/sysinstall/media.c60
-rw-r--r--usr.sbin/sysinstall/package.c31
-rw-r--r--usr.sbin/sysinstall/sysinstall.h1
-rw-r--r--usr.sbin/sysinstall/tcpip.c2
15 files changed, 348 insertions, 180 deletions
diff --git a/release/sysinstall/config.c b/release/sysinstall/config.c
index 3198596..96dfcd1 100644
--- a/release/sysinstall/config.c
+++ b/release/sysinstall/config.c
@@ -269,50 +269,93 @@ configFstab(void)
return DITEM_SUCCESS;
}
+/* Do the work of sucking in a config file.
+ * config is the filename to read in.
+ * lines is a fixed (max) sized array of char *.
+ * returns number of lines read. line contents
+ * are malloc'd and must be freed by the caller.
+ */
+int
+readConfig(char *config, char **lines, int max)
+{
+ FILE *fp;
+ char line[256];
+ int i, nlines;
+
+ fp = fopen(config, "r");
+ if (!fp)
+ return -1;
+
+ nlines = 0;
+ /* Read in the entire file */
+ for (i = 0; i < max; i++) {
+ if (!fgets(line, sizeof line, fp))
+ break;
+ lines[nlines++] = strdup(line);
+ }
+ fclose(fp);
+ if (isDebug())
+ msgDebug("readConfig: Read %d lines from %s.\n", nlines, config);
+ return nlines;
+}
+
+#define MAX_LINES 2000 /* Some big number we're not likely to ever reach - I'm being really lazy here, I know */
+
+/* Load the environment from /etc/sysconfig, if it exists */
+void
+configEnvironment(char *config)
+{
+ char *lines[MAX_LINES], *cp;
+ int i, j, nlines;
+
+ nlines = readConfig(config, lines, MAX_LINES);
+ if (nlines == -1)
+ return;
+
+ for (i = 0; i < nlines; i++) {
+ /* Skip the comments & non-variable settings */
+ if (lines[i][0] == '#' || !(cp = index(lines[i], '='))) {
+ free(lines[i]);
+ continue;
+ }
+ *cp++ = '\0';
+ (void)string_prune(lines[i]);
+ cp = string_skipwhite(string_prune(cp));
+ if (*cp == '"') /* Eliminate leading quote if it's quoted */
+ ++cp;
+ j = strlen(cp);
+ if (cp[j] == '"') /* And trailing one */
+ cp[j] = '\0';
+ variable_set2(lines[i], cp);
+ free(lines[i]);
+ }
+}
+
/*
* This sucks in /etc/sysconfig, substitutes anything needing substitution, then
* writes it all back out. It's pretty gross and needs re-writing at some point.
*/
-
-#define MAX_LINES 2000 /* Some big number we're not likely to ever reach - I'm being really lazy here, I know */
void
configSysconfig(char *config)
{
FILE *fp;
char *lines[MAX_LINES], *cp;
- char line[256];
Variable *v;
int i, nlines;
- fp = fopen(config, "r");
- if (!fp) {
+ nlines = readConfig(config, lines, MAX_LINES);
+ if (nlines == -1) {
msgConfirm("Unable to open %s file! This is bad!", config);
return;
}
- msgNotify("Writing configuration changes to %s file..", config);
- nlines = 0;
- /* Read in the entire file */
- for (i = 0; i < MAX_LINES; i++) {
- if (!fgets(line, 255, fp))
- break;
- lines[nlines++] = strdup(line);
- }
- msgDebug("Read %d lines from %s.\n", nlines, config);
/* Now do variable substitutions */
for (v = VarHead; v; v = v->next) {
for (i = 0; i < nlines; i++) {
- char tmp[256];
-
- /* Skip the comments */
- if (lines[i][0] == '#')
- continue;
- SAFE_STRCPY(tmp, lines[i]);
- cp = index(tmp, '=');
- if (!cp)
+ /* Skip the comments & non-variable settings */
+ if (lines[i][0] == '#' || !(cp = index(lines[i], '=')))
continue;
- *(cp++) = '\0';
- if (!strcmp(tmp, v->name)) {
+ if (!strncmp(lines[i], v->name, cp - lines[i])) {
free(lines[i]);
lines[i] = (char *)malloc(strlen(v->name) + strlen(v->value) + 5);
sprintf(lines[i], "%s=\"%s\"\n", v->name, v->value);
@@ -322,7 +365,7 @@ configSysconfig(char *config)
}
/* Now write it all back out again */
- fclose(fp);
+ msgNotify("Writing configuration changes to %s file..", config);
if (Fake) {
msgDebug("Writing %s out to debugging screen..\n", config);
fp = fdopen(DebugFD, "w");
@@ -430,9 +473,6 @@ configResolv(void)
FILE *fp;
char *cp, *dp, *hp;
- if (!RunningAsInit || file_readable("/etc/resolv.conf"))
- return;
-
cp = variable_get(VAR_NAMESERVER);
if (!cp || !*cp)
goto skip;
@@ -447,16 +487,18 @@ configResolv(void)
msgDebug("Wrote out /etc/resolv.conf\n");
skip:
+ dp = variable_get(VAR_DOMAINNAME);
+ cp = variable_get(VAR_IPADDR);
+ hp = variable_get(VAR_HOSTNAME);
+ if ((!dp || !cp || !hp) && file_readable("/etc/hosts"))
+ return;
/* Tack ourselves into /etc/hosts */
fp = fopen("/etc/hosts", "w");
-
+ if (!fp)
+ return;
/* Add an entry for localhost */
- dp = variable_get(VAR_DOMAINNAME);
fprintf(fp, "127.0.0.1\t\tlocalhost.%s localhost\n", dp ? dp : "my.domain");
-
/* Now the host entries, if applicable */
- cp = variable_get(VAR_IPADDR);
- hp = variable_get(VAR_HOSTNAME);
if (cp && cp[0] != '0' && hp) {
char cp2[255];
@@ -471,7 +513,7 @@ skip:
}
fclose(fp);
if (isDebug())
- msgDebug("Wrote entry for %s to /etc/hosts\n", cp);
+ msgDebug("Wrote out /etc/hosts\n");
}
int
diff --git a/release/sysinstall/main.c b/release/sysinstall/main.c
index d9b08a8..ece57d4 100644
--- a/release/sysinstall/main.c
+++ b/release/sysinstall/main.c
@@ -71,6 +71,9 @@ main(int argc, char **argv)
/* Set default flag and variable values */
installVarDefaults(NULL);
+ if (file_readable("/etc/sysconfig"))
+ configEnvironment("/etc/sysconfig");
+
if (argc > 1 && !strcmp(argv[1], "-fake")) {
variable_set2(VAR_DEBUG, "YES");
Fake = TRUE;
diff --git a/release/sysinstall/media.c b/release/sysinstall/media.c
index af7ab98..8362b7b 100644
--- a/release/sysinstall/media.c
+++ b/release/sysinstall/media.c
@@ -96,6 +96,14 @@ cpioVerbosity()
return "";
}
+static void
+mediaClose(void)
+{
+ if (mediaDevice)
+ mediaDevice->shutdown(mediaDevice);
+ mediaDevice = NULL;
+}
+
/*
* Return 1 if we successfully found and set the installation type to
* be a CD.
@@ -106,6 +114,7 @@ mediaSetCDROM(dialogMenuItem *self)
Device **devs;
int cnt;
+ mediaClose();
devs = deviceFind(NULL, DEVICE_TYPE_CDROM);
cnt = deviceCount(devs);
if (!cnt) {
@@ -149,6 +158,7 @@ mediaSetFloppy(dialogMenuItem *self)
Device **devs;
int cnt;
+ mediaClose();
devs = deviceFind(NULL, DEVICE_TYPE_FLOPPY);
cnt = deviceCount(devs);
if (!cnt) {
@@ -190,6 +200,7 @@ mediaSetDOS(dialogMenuItem *self)
Device **devs;
int cnt;
+ mediaClose();
devs = deviceFind(NULL, DEVICE_TYPE_DOS);
cnt = deviceCount(devs);
if (!cnt) {
@@ -229,6 +240,7 @@ mediaSetTape(dialogMenuItem *self)
Device **devs;
int cnt;
+ mediaClose();
devs = deviceFind(NULL, DEVICE_TYPE_TAPE);
cnt = deviceCount(devs);
if (!cnt) {
@@ -277,12 +289,13 @@ mediaSetFTP(dialogMenuItem *self)
static Device ftpDevice;
char *cp, *hostname, *dir;
extern int FtpPort;
- static Boolean network_init = 1;
+ static Device *networkDev = NULL;
int what = DITEM_RESTORE;
+ mediaClose();
cp = variable_get(VAR_FTP_PATH);
/* If we've been through here before ... */
- if (!network_init && cp && msgYesNo("Re-use old FTP site selection values?"))
+ if (networkDev && cp && msgYesNo("Re-use old FTP site selection values?"))
cp = NULL;
if (!cp) {
@@ -318,10 +331,11 @@ mediaSetFTP(dialogMenuItem *self)
SAFE_STRCPY(ftpDevice.name, cp);
dialog_clear_norefresh();
- if (RunningAsInit && (network_init || msgYesNo("You've already done the network configuration once,\n"
- "would you like to skip over it now?") != 0)) {
- if (mediaDevice)
- mediaDevice->shutdown(mediaDevice);
+ if (!networkDev || msgYesNo("You've already done the network configuration once,\n"
+ "would you like to skip over it now?") != 0) {
+ if (networkDev)
+ networkDev->shutdown(networkDev);
+ networkDev = NULL;
if (!tcpDeviceSelect()) {
variable_unset(VAR_FTP_PATH);
return DITEM_FAILURE | what;
@@ -332,8 +346,8 @@ mediaSetFTP(dialogMenuItem *self)
variable_unset(VAR_FTP_PATH);
return DITEM_FAILURE | what;
}
+ networkDev = mediaDevice;
}
- network_init = FALSE;
hostname = cp + 6;
if ((cp = index(hostname, ':')) != NULL) {
*(cp++) = '\0';
@@ -352,13 +366,14 @@ mediaSetFTP(dialogMenuItem *self)
if ((gethostbyname(hostname) == NULL) && (inet_addr(hostname) == INADDR_NONE)) {
msgConfirm("Cannot resolve hostname `%s'! Are you sure that your\n"
"name server, gateway and network interface are correctly configured?", hostname);
- mediaDevice->shutdown(mediaDevice);
- network_init = TRUE;
+ if (networkDev)
+ networkDev->shutdown(networkDev);
+ networkDev = NULL;
variable_unset(VAR_FTP_PATH);
return DITEM_FAILURE | what;
}
else
- msgNotify("Found DNS entry for %s successfully..", hostname);
+ msgDebug("Found DNS entry for %s successfully..", hostname);
}
variable_set2(VAR_FTP_HOST, hostname);
variable_set2(VAR_FTP_DIR, dir ? dir : "/");
@@ -367,7 +382,7 @@ mediaSetFTP(dialogMenuItem *self)
ftpDevice.init = mediaInitFTP;
ftpDevice.get = mediaGetFTP;
ftpDevice.shutdown = mediaShutdownFTP;
- ftpDevice.private = RunningAsInit ? mediaDevice : NULL; /* Set to network device by tcpDeviceSelect() */
+ ftpDevice.private = networkDev;
mediaDevice = &ftpDevice;
return DITEM_SUCCESS | DITEM_LEAVE_MENU | what;
}
@@ -392,6 +407,7 @@ mediaSetUFS(dialogMenuItem *self)
static Device ufsDevice;
char *cp;
+ mediaClose();
dialog_clear_norefresh();
cp = variable_get_value(VAR_UFS_PATH, "Enter a fully qualified pathname for the directory\n"
"containing the FreeBSD distribution files:");
@@ -411,9 +427,10 @@ int
mediaSetNFS(dialogMenuItem *self)
{
static Device nfsDevice;
- static int network_init = 1;
+ static Device *networkDev = NULL;
char *cp, *idx;
+ mediaClose();
dialog_clear_norefresh();
cp = variable_get_value(VAR_NFS_PATH, "Please enter the full NFS file specification for the remote\n"
"host and directory containing the FreeBSD distribution files.\n"
@@ -427,8 +444,11 @@ mediaSetNFS(dialogMenuItem *self)
}
SAFE_STRCPY(nfsDevice.name, cp);
*idx = '\0';
- if (RunningAsInit && (network_init || msgYesNo("You've already done the network configuration once,\n"
- "would you like to skip over it now?") != 0)) {
+ if (!networkDev || msgYesNo("You've already done the network configuration once,\n"
+ "would you like to skip over it now?") != 0) {
+ if (networkDev)
+ networkDev->shutdown(networkDev);
+ networkDev = NULL;
if (!tcpDeviceSelect())
return DITEM_FAILURE;
if (!mediaDevice || !mediaDevice->init(mediaDevice)) {
@@ -436,23 +456,27 @@ mediaSetNFS(dialogMenuItem *self)
msgDebug("mediaSetNFS: Net device init failed\n");
return DITEM_FAILURE;
}
+ networkDev = mediaDevice;
}
- network_init = 0;
- if (!RunningAsInit || variable_get(VAR_NAMESERVER)) {
+ if (variable_get(VAR_NAMESERVER)) {
if ((gethostbyname(cp) == NULL) && (inet_addr(cp) == INADDR_NONE)) {
msgConfirm("Cannot resolve hostname `%s'! Are you sure that your\n"
"name server, gateway and network interface are correctly configured?", cp);
+ if (networkDev)
+ networkDev->shutdown(networkDev);
+ networkDev = NULL;
+ variable_unset(VAR_NFS_PATH);
return DITEM_FAILURE;
}
else
- msgNotify("Found DNS entry for %s successfully..", cp);
+ msgDebug("Found DNS entry for %s successfully..", cp);
}
variable_set2(VAR_NFS_HOST, cp);
nfsDevice.type = DEVICE_TYPE_NFS;
nfsDevice.init = mediaInitNFS;
nfsDevice.get = mediaGetNFS;
nfsDevice.shutdown = mediaShutdownNFS;
- nfsDevice.private = RunningAsInit ? mediaDevice : NULL;
+ nfsDevice.private = networkDev;
mediaDevice = &nfsDevice;
return DITEM_LEAVE_MENU;
}
diff --git a/release/sysinstall/package.c b/release/sysinstall/package.c
index 2ecb4b7..1104364 100644
--- a/release/sysinstall/package.c
+++ b/release/sysinstall/package.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id$
+ * $Id: package.c,v 1.55 1997/02/07 04:26:47 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -68,15 +68,6 @@ package_exists(char *name)
return !status;
}
-/* SIGPIPE handler */
-static Boolean sigpipe_caught = FALSE;
-
-static void
-catch_pipe(int sig)
-{
- sigpipe_caught = TRUE;
-}
-
/* Extract a package based on a namespec and a media device */
int
package_extract(Device *dev, char *name, Boolean depended)
@@ -116,7 +107,6 @@ package_extract(Device *dev, char *name, Boolean depended)
int i, tot, pfd[2];
pid_t pid;
- signal(SIGPIPE, catch_pipe);
msgNotify("Adding %s%s\nfrom %s", path, depended ? " (as a dependency)" : "", dev->name);
pipe(pfd);
pid = fork();
@@ -138,9 +128,11 @@ package_extract(Device *dev, char *name, Boolean depended)
tot = 0;
(void)gettimeofday(&start, (struct timezone *)0);
- while (!sigpipe_caught && (i = fread(buf, 1, BUFSIZ, fp)) > 0) {
+ while ((i = fread(buf, 1, BUFSIZ, fp)) > 0) {
int seconds;
+ if (isDebug())
+ msgDebug("Just read %d bytes from media device.\n", i);
tot += i;
/* Print statistics about how we're doing */
(void) gettimeofday(&stop, (struct timezone *)0);
@@ -160,19 +152,19 @@ package_extract(Device *dev, char *name, Boolean depended)
}
close(pfd[1]);
fclose(fp);
- if (sigpipe_caught)
- msgDebug("Caught SIGPIPE while trying to install the %s package.\n", name);
+ if (i == -1)
+ msgDebug("I/O error while reading in the %s package.\n", name);
else
msgInfo("Package %s read successfully - waiting for pkg_add", name);
refresh();
i = waitpid(pid, &tot, 0);
- if (sigpipe_caught || i < 0 || WEXITSTATUS(tot)) {
+ if (i < 0 || WEXITSTATUS(tot)) {
if (variable_get(VAR_NO_CONFIRM))
- msgNotify("Add of package %s aborted due to some error -\n"
- "Please check the debug screen for more info.", name);
+ msgNotify("Add of package %s aborted, error code %d -\n"
+ "Please check the debug screen for more info.", name, WEXITSTATUS(tot));
else
- msgConfirm("Add of package %s aborted due to some error -\n"
- "Please check the debug screen for more info.", name);
+ msgConfirm("Add of package %s aborted, error code %d -\n"
+ "Please check the debug screen for more info.", name, WEXITSTATUS(tot));
}
else
msgNotify("Package %s was added successfully", name);
@@ -182,7 +174,6 @@ package_extract(Device *dev, char *name, Boolean depended)
sleep(1);
restorescr(w);
- sigpipe_caught = FALSE;
}
}
else {
diff --git a/release/sysinstall/sysinstall.h b/release/sysinstall/sysinstall.h
index 2fd55f8..8d0745a 100644
--- a/release/sysinstall/sysinstall.h
+++ b/release/sysinstall/sysinstall.h
@@ -404,6 +404,7 @@ extern void command_func_add(char *key, commandFunc func, void *data);
/* config.c */
extern int configFstab(void);
+extern void configEnvironment(char *config);
extern void configSysconfig(char *config);
extern void configResolv(void);
extern int configPackages(dialogMenuItem *self);
diff --git a/release/sysinstall/tcpip.c b/release/sysinstall/tcpip.c
index c294c93..b993421 100644
--- a/release/sysinstall/tcpip.c
+++ b/release/sysinstall/tcpip.c
@@ -255,7 +255,7 @@ reenter:
}
}
- if (!verifySettings())
+ if (!cancel && !verifySettings())
goto reenter;
/* Clear this crap off the screen */
diff --git a/usr.sbin/sade/config.c b/usr.sbin/sade/config.c
index 3198596..96dfcd1 100644
--- a/usr.sbin/sade/config.c
+++ b/usr.sbin/sade/config.c
@@ -269,50 +269,93 @@ configFstab(void)
return DITEM_SUCCESS;
}
+/* Do the work of sucking in a config file.
+ * config is the filename to read in.
+ * lines is a fixed (max) sized array of char *.
+ * returns number of lines read. line contents
+ * are malloc'd and must be freed by the caller.
+ */
+int
+readConfig(char *config, char **lines, int max)
+{
+ FILE *fp;
+ char line[256];
+ int i, nlines;
+
+ fp = fopen(config, "r");
+ if (!fp)
+ return -1;
+
+ nlines = 0;
+ /* Read in the entire file */
+ for (i = 0; i < max; i++) {
+ if (!fgets(line, sizeof line, fp))
+ break;
+ lines[nlines++] = strdup(line);
+ }
+ fclose(fp);
+ if (isDebug())
+ msgDebug("readConfig: Read %d lines from %s.\n", nlines, config);
+ return nlines;
+}
+
+#define MAX_LINES 2000 /* Some big number we're not likely to ever reach - I'm being really lazy here, I know */
+
+/* Load the environment from /etc/sysconfig, if it exists */
+void
+configEnvironment(char *config)
+{
+ char *lines[MAX_LINES], *cp;
+ int i, j, nlines;
+
+ nlines = readConfig(config, lines, MAX_LINES);
+ if (nlines == -1)
+ return;
+
+ for (i = 0; i < nlines; i++) {
+ /* Skip the comments & non-variable settings */
+ if (lines[i][0] == '#' || !(cp = index(lines[i], '='))) {
+ free(lines[i]);
+ continue;
+ }
+ *cp++ = '\0';
+ (void)string_prune(lines[i]);
+ cp = string_skipwhite(string_prune(cp));
+ if (*cp == '"') /* Eliminate leading quote if it's quoted */
+ ++cp;
+ j = strlen(cp);
+ if (cp[j] == '"') /* And trailing one */
+ cp[j] = '\0';
+ variable_set2(lines[i], cp);
+ free(lines[i]);
+ }
+}
+
/*
* This sucks in /etc/sysconfig, substitutes anything needing substitution, then
* writes it all back out. It's pretty gross and needs re-writing at some point.
*/
-
-#define MAX_LINES 2000 /* Some big number we're not likely to ever reach - I'm being really lazy here, I know */
void
configSysconfig(char *config)
{
FILE *fp;
char *lines[MAX_LINES], *cp;
- char line[256];
Variable *v;
int i, nlines;
- fp = fopen(config, "r");
- if (!fp) {
+ nlines = readConfig(config, lines, MAX_LINES);
+ if (nlines == -1) {
msgConfirm("Unable to open %s file! This is bad!", config);
return;
}
- msgNotify("Writing configuration changes to %s file..", config);
- nlines = 0;
- /* Read in the entire file */
- for (i = 0; i < MAX_LINES; i++) {
- if (!fgets(line, 255, fp))
- break;
- lines[nlines++] = strdup(line);
- }
- msgDebug("Read %d lines from %s.\n", nlines, config);
/* Now do variable substitutions */
for (v = VarHead; v; v = v->next) {
for (i = 0; i < nlines; i++) {
- char tmp[256];
-
- /* Skip the comments */
- if (lines[i][0] == '#')
- continue;
- SAFE_STRCPY(tmp, lines[i]);
- cp = index(tmp, '=');
- if (!cp)
+ /* Skip the comments & non-variable settings */
+ if (lines[i][0] == '#' || !(cp = index(lines[i], '=')))
continue;
- *(cp++) = '\0';
- if (!strcmp(tmp, v->name)) {
+ if (!strncmp(lines[i], v->name, cp - lines[i])) {
free(lines[i]);
lines[i] = (char *)malloc(strlen(v->name) + strlen(v->value) + 5);
sprintf(lines[i], "%s=\"%s\"\n", v->name, v->value);
@@ -322,7 +365,7 @@ configSysconfig(char *config)
}
/* Now write it all back out again */
- fclose(fp);
+ msgNotify("Writing configuration changes to %s file..", config);
if (Fake) {
msgDebug("Writing %s out to debugging screen..\n", config);
fp = fdopen(DebugFD, "w");
@@ -430,9 +473,6 @@ configResolv(void)
FILE *fp;
char *cp, *dp, *hp;
- if (!RunningAsInit || file_readable("/etc/resolv.conf"))
- return;
-
cp = variable_get(VAR_NAMESERVER);
if (!cp || !*cp)
goto skip;
@@ -447,16 +487,18 @@ configResolv(void)
msgDebug("Wrote out /etc/resolv.conf\n");
skip:
+ dp = variable_get(VAR_DOMAINNAME);
+ cp = variable_get(VAR_IPADDR);
+ hp = variable_get(VAR_HOSTNAME);
+ if ((!dp || !cp || !hp) && file_readable("/etc/hosts"))
+ return;
/* Tack ourselves into /etc/hosts */
fp = fopen("/etc/hosts", "w");
-
+ if (!fp)
+ return;
/* Add an entry for localhost */
- dp = variable_get(VAR_DOMAINNAME);
fprintf(fp, "127.0.0.1\t\tlocalhost.%s localhost\n", dp ? dp : "my.domain");
-
/* Now the host entries, if applicable */
- cp = variable_get(VAR_IPADDR);
- hp = variable_get(VAR_HOSTNAME);
if (cp && cp[0] != '0' && hp) {
char cp2[255];
@@ -471,7 +513,7 @@ skip:
}
fclose(fp);
if (isDebug())
- msgDebug("Wrote entry for %s to /etc/hosts\n", cp);
+ msgDebug("Wrote out /etc/hosts\n");
}
int
diff --git a/usr.sbin/sade/main.c b/usr.sbin/sade/main.c
index d9b08a8..ece57d4 100644
--- a/usr.sbin/sade/main.c
+++ b/usr.sbin/sade/main.c
@@ -71,6 +71,9 @@ main(int argc, char **argv)
/* Set default flag and variable values */
installVarDefaults(NULL);
+ if (file_readable("/etc/sysconfig"))
+ configEnvironment("/etc/sysconfig");
+
if (argc > 1 && !strcmp(argv[1], "-fake")) {
variable_set2(VAR_DEBUG, "YES");
Fake = TRUE;
diff --git a/usr.sbin/sade/sade.h b/usr.sbin/sade/sade.h
index 2fd55f8..8d0745a 100644
--- a/usr.sbin/sade/sade.h
+++ b/usr.sbin/sade/sade.h
@@ -404,6 +404,7 @@ extern void command_func_add(char *key, commandFunc func, void *data);
/* config.c */
extern int configFstab(void);
+extern void configEnvironment(char *config);
extern void configSysconfig(char *config);
extern void configResolv(void);
extern int configPackages(dialogMenuItem *self);
diff --git a/usr.sbin/sysinstall/config.c b/usr.sbin/sysinstall/config.c
index 3198596..96dfcd1 100644
--- a/usr.sbin/sysinstall/config.c
+++ b/usr.sbin/sysinstall/config.c
@@ -269,50 +269,93 @@ configFstab(void)
return DITEM_SUCCESS;
}
+/* Do the work of sucking in a config file.
+ * config is the filename to read in.
+ * lines is a fixed (max) sized array of char *.
+ * returns number of lines read. line contents
+ * are malloc'd and must be freed by the caller.
+ */
+int
+readConfig(char *config, char **lines, int max)
+{
+ FILE *fp;
+ char line[256];
+ int i, nlines;
+
+ fp = fopen(config, "r");
+ if (!fp)
+ return -1;
+
+ nlines = 0;
+ /* Read in the entire file */
+ for (i = 0; i < max; i++) {
+ if (!fgets(line, sizeof line, fp))
+ break;
+ lines[nlines++] = strdup(line);
+ }
+ fclose(fp);
+ if (isDebug())
+ msgDebug("readConfig: Read %d lines from %s.\n", nlines, config);
+ return nlines;
+}
+
+#define MAX_LINES 2000 /* Some big number we're not likely to ever reach - I'm being really lazy here, I know */
+
+/* Load the environment from /etc/sysconfig, if it exists */
+void
+configEnvironment(char *config)
+{
+ char *lines[MAX_LINES], *cp;
+ int i, j, nlines;
+
+ nlines = readConfig(config, lines, MAX_LINES);
+ if (nlines == -1)
+ return;
+
+ for (i = 0; i < nlines; i++) {
+ /* Skip the comments & non-variable settings */
+ if (lines[i][0] == '#' || !(cp = index(lines[i], '='))) {
+ free(lines[i]);
+ continue;
+ }
+ *cp++ = '\0';
+ (void)string_prune(lines[i]);
+ cp = string_skipwhite(string_prune(cp));
+ if (*cp == '"') /* Eliminate leading quote if it's quoted */
+ ++cp;
+ j = strlen(cp);
+ if (cp[j] == '"') /* And trailing one */
+ cp[j] = '\0';
+ variable_set2(lines[i], cp);
+ free(lines[i]);
+ }
+}
+
/*
* This sucks in /etc/sysconfig, substitutes anything needing substitution, then
* writes it all back out. It's pretty gross and needs re-writing at some point.
*/
-
-#define MAX_LINES 2000 /* Some big number we're not likely to ever reach - I'm being really lazy here, I know */
void
configSysconfig(char *config)
{
FILE *fp;
char *lines[MAX_LINES], *cp;
- char line[256];
Variable *v;
int i, nlines;
- fp = fopen(config, "r");
- if (!fp) {
+ nlines = readConfig(config, lines, MAX_LINES);
+ if (nlines == -1) {
msgConfirm("Unable to open %s file! This is bad!", config);
return;
}
- msgNotify("Writing configuration changes to %s file..", config);
- nlines = 0;
- /* Read in the entire file */
- for (i = 0; i < MAX_LINES; i++) {
- if (!fgets(line, 255, fp))
- break;
- lines[nlines++] = strdup(line);
- }
- msgDebug("Read %d lines from %s.\n", nlines, config);
/* Now do variable substitutions */
for (v = VarHead; v; v = v->next) {
for (i = 0; i < nlines; i++) {
- char tmp[256];
-
- /* Skip the comments */
- if (lines[i][0] == '#')
- continue;
- SAFE_STRCPY(tmp, lines[i]);
- cp = index(tmp, '=');
- if (!cp)
+ /* Skip the comments & non-variable settings */
+ if (lines[i][0] == '#' || !(cp = index(lines[i], '=')))
continue;
- *(cp++) = '\0';
- if (!strcmp(tmp, v->name)) {
+ if (!strncmp(lines[i], v->name, cp - lines[i])) {
free(lines[i]);
lines[i] = (char *)malloc(strlen(v->name) + strlen(v->value) + 5);
sprintf(lines[i], "%s=\"%s\"\n", v->name, v->value);
@@ -322,7 +365,7 @@ configSysconfig(char *config)
}
/* Now write it all back out again */
- fclose(fp);
+ msgNotify("Writing configuration changes to %s file..", config);
if (Fake) {
msgDebug("Writing %s out to debugging screen..\n", config);
fp = fdopen(DebugFD, "w");
@@ -430,9 +473,6 @@ configResolv(void)
FILE *fp;
char *cp, *dp, *hp;
- if (!RunningAsInit || file_readable("/etc/resolv.conf"))
- return;
-
cp = variable_get(VAR_NAMESERVER);
if (!cp || !*cp)
goto skip;
@@ -447,16 +487,18 @@ configResolv(void)
msgDebug("Wrote out /etc/resolv.conf\n");
skip:
+ dp = variable_get(VAR_DOMAINNAME);
+ cp = variable_get(VAR_IPADDR);
+ hp = variable_get(VAR_HOSTNAME);
+ if ((!dp || !cp || !hp) && file_readable("/etc/hosts"))
+ return;
/* Tack ourselves into /etc/hosts */
fp = fopen("/etc/hosts", "w");
-
+ if (!fp)
+ return;
/* Add an entry for localhost */
- dp = variable_get(VAR_DOMAINNAME);
fprintf(fp, "127.0.0.1\t\tlocalhost.%s localhost\n", dp ? dp : "my.domain");
-
/* Now the host entries, if applicable */
- cp = variable_get(VAR_IPADDR);
- hp = variable_get(VAR_HOSTNAME);
if (cp && cp[0] != '0' && hp) {
char cp2[255];
@@ -471,7 +513,7 @@ skip:
}
fclose(fp);
if (isDebug())
- msgDebug("Wrote entry for %s to /etc/hosts\n", cp);
+ msgDebug("Wrote out /etc/hosts\n");
}
int
diff --git a/usr.sbin/sysinstall/main.c b/usr.sbin/sysinstall/main.c
index d9b08a8..ece57d4 100644
--- a/usr.sbin/sysinstall/main.c
+++ b/usr.sbin/sysinstall/main.c
@@ -71,6 +71,9 @@ main(int argc, char **argv)
/* Set default flag and variable values */
installVarDefaults(NULL);
+ if (file_readable("/etc/sysconfig"))
+ configEnvironment("/etc/sysconfig");
+
if (argc > 1 && !strcmp(argv[1], "-fake")) {
variable_set2(VAR_DEBUG, "YES");
Fake = TRUE;
diff --git a/usr.sbin/sysinstall/media.c b/usr.sbin/sysinstall/media.c
index af7ab98..8362b7b 100644
--- a/usr.sbin/sysinstall/media.c
+++ b/usr.sbin/sysinstall/media.c
@@ -96,6 +96,14 @@ cpioVerbosity()
return "";
}
+static void
+mediaClose(void)
+{
+ if (mediaDevice)
+ mediaDevice->shutdown(mediaDevice);
+ mediaDevice = NULL;
+}
+
/*
* Return 1 if we successfully found and set the installation type to
* be a CD.
@@ -106,6 +114,7 @@ mediaSetCDROM(dialogMenuItem *self)
Device **devs;
int cnt;
+ mediaClose();
devs = deviceFind(NULL, DEVICE_TYPE_CDROM);
cnt = deviceCount(devs);
if (!cnt) {
@@ -149,6 +158,7 @@ mediaSetFloppy(dialogMenuItem *self)
Device **devs;
int cnt;
+ mediaClose();
devs = deviceFind(NULL, DEVICE_TYPE_FLOPPY);
cnt = deviceCount(devs);
if (!cnt) {
@@ -190,6 +200,7 @@ mediaSetDOS(dialogMenuItem *self)
Device **devs;
int cnt;
+ mediaClose();
devs = deviceFind(NULL, DEVICE_TYPE_DOS);
cnt = deviceCount(devs);
if (!cnt) {
@@ -229,6 +240,7 @@ mediaSetTape(dialogMenuItem *self)
Device **devs;
int cnt;
+ mediaClose();
devs = deviceFind(NULL, DEVICE_TYPE_TAPE);
cnt = deviceCount(devs);
if (!cnt) {
@@ -277,12 +289,13 @@ mediaSetFTP(dialogMenuItem *self)
static Device ftpDevice;
char *cp, *hostname, *dir;
extern int FtpPort;
- static Boolean network_init = 1;
+ static Device *networkDev = NULL;
int what = DITEM_RESTORE;
+ mediaClose();
cp = variable_get(VAR_FTP_PATH);
/* If we've been through here before ... */
- if (!network_init && cp && msgYesNo("Re-use old FTP site selection values?"))
+ if (networkDev && cp && msgYesNo("Re-use old FTP site selection values?"))
cp = NULL;
if (!cp) {
@@ -318,10 +331,11 @@ mediaSetFTP(dialogMenuItem *self)
SAFE_STRCPY(ftpDevice.name, cp);
dialog_clear_norefresh();
- if (RunningAsInit && (network_init || msgYesNo("You've already done the network configuration once,\n"
- "would you like to skip over it now?") != 0)) {
- if (mediaDevice)
- mediaDevice->shutdown(mediaDevice);
+ if (!networkDev || msgYesNo("You've already done the network configuration once,\n"
+ "would you like to skip over it now?") != 0) {
+ if (networkDev)
+ networkDev->shutdown(networkDev);
+ networkDev = NULL;
if (!tcpDeviceSelect()) {
variable_unset(VAR_FTP_PATH);
return DITEM_FAILURE | what;
@@ -332,8 +346,8 @@ mediaSetFTP(dialogMenuItem *self)
variable_unset(VAR_FTP_PATH);
return DITEM_FAILURE | what;
}
+ networkDev = mediaDevice;
}
- network_init = FALSE;
hostname = cp + 6;
if ((cp = index(hostname, ':')) != NULL) {
*(cp++) = '\0';
@@ -352,13 +366,14 @@ mediaSetFTP(dialogMenuItem *self)
if ((gethostbyname(hostname) == NULL) && (inet_addr(hostname) == INADDR_NONE)) {
msgConfirm("Cannot resolve hostname `%s'! Are you sure that your\n"
"name server, gateway and network interface are correctly configured?", hostname);
- mediaDevice->shutdown(mediaDevice);
- network_init = TRUE;
+ if (networkDev)
+ networkDev->shutdown(networkDev);
+ networkDev = NULL;
variable_unset(VAR_FTP_PATH);
return DITEM_FAILURE | what;
}
else
- msgNotify("Found DNS entry for %s successfully..", hostname);
+ msgDebug("Found DNS entry for %s successfully..", hostname);
}
variable_set2(VAR_FTP_HOST, hostname);
variable_set2(VAR_FTP_DIR, dir ? dir : "/");
@@ -367,7 +382,7 @@ mediaSetFTP(dialogMenuItem *self)
ftpDevice.init = mediaInitFTP;
ftpDevice.get = mediaGetFTP;
ftpDevice.shutdown = mediaShutdownFTP;
- ftpDevice.private = RunningAsInit ? mediaDevice : NULL; /* Set to network device by tcpDeviceSelect() */
+ ftpDevice.private = networkDev;
mediaDevice = &ftpDevice;
return DITEM_SUCCESS | DITEM_LEAVE_MENU | what;
}
@@ -392,6 +407,7 @@ mediaSetUFS(dialogMenuItem *self)
static Device ufsDevice;
char *cp;
+ mediaClose();
dialog_clear_norefresh();
cp = variable_get_value(VAR_UFS_PATH, "Enter a fully qualified pathname for the directory\n"
"containing the FreeBSD distribution files:");
@@ -411,9 +427,10 @@ int
mediaSetNFS(dialogMenuItem *self)
{
static Device nfsDevice;
- static int network_init = 1;
+ static Device *networkDev = NULL;
char *cp, *idx;
+ mediaClose();
dialog_clear_norefresh();
cp = variable_get_value(VAR_NFS_PATH, "Please enter the full NFS file specification for the remote\n"
"host and directory containing the FreeBSD distribution files.\n"
@@ -427,8 +444,11 @@ mediaSetNFS(dialogMenuItem *self)
}
SAFE_STRCPY(nfsDevice.name, cp);
*idx = '\0';
- if (RunningAsInit && (network_init || msgYesNo("You've already done the network configuration once,\n"
- "would you like to skip over it now?") != 0)) {
+ if (!networkDev || msgYesNo("You've already done the network configuration once,\n"
+ "would you like to skip over it now?") != 0) {
+ if (networkDev)
+ networkDev->shutdown(networkDev);
+ networkDev = NULL;
if (!tcpDeviceSelect())
return DITEM_FAILURE;
if (!mediaDevice || !mediaDevice->init(mediaDevice)) {
@@ -436,23 +456,27 @@ mediaSetNFS(dialogMenuItem *self)
msgDebug("mediaSetNFS: Net device init failed\n");
return DITEM_FAILURE;
}
+ networkDev = mediaDevice;
}
- network_init = 0;
- if (!RunningAsInit || variable_get(VAR_NAMESERVER)) {
+ if (variable_get(VAR_NAMESERVER)) {
if ((gethostbyname(cp) == NULL) && (inet_addr(cp) == INADDR_NONE)) {
msgConfirm("Cannot resolve hostname `%s'! Are you sure that your\n"
"name server, gateway and network interface are correctly configured?", cp);
+ if (networkDev)
+ networkDev->shutdown(networkDev);
+ networkDev = NULL;
+ variable_unset(VAR_NFS_PATH);
return DITEM_FAILURE;
}
else
- msgNotify("Found DNS entry for %s successfully..", cp);
+ msgDebug("Found DNS entry for %s successfully..", cp);
}
variable_set2(VAR_NFS_HOST, cp);
nfsDevice.type = DEVICE_TYPE_NFS;
nfsDevice.init = mediaInitNFS;
nfsDevice.get = mediaGetNFS;
nfsDevice.shutdown = mediaShutdownNFS;
- nfsDevice.private = RunningAsInit ? mediaDevice : NULL;
+ nfsDevice.private = networkDev;
mediaDevice = &nfsDevice;
return DITEM_LEAVE_MENU;
}
diff --git a/usr.sbin/sysinstall/package.c b/usr.sbin/sysinstall/package.c
index 2ecb4b7..1104364 100644
--- a/usr.sbin/sysinstall/package.c
+++ b/usr.sbin/sysinstall/package.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id$
+ * $Id: package.c,v 1.55 1997/02/07 04:26:47 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -68,15 +68,6 @@ package_exists(char *name)
return !status;
}
-/* SIGPIPE handler */
-static Boolean sigpipe_caught = FALSE;
-
-static void
-catch_pipe(int sig)
-{
- sigpipe_caught = TRUE;
-}
-
/* Extract a package based on a namespec and a media device */
int
package_extract(Device *dev, char *name, Boolean depended)
@@ -116,7 +107,6 @@ package_extract(Device *dev, char *name, Boolean depended)
int i, tot, pfd[2];
pid_t pid;
- signal(SIGPIPE, catch_pipe);
msgNotify("Adding %s%s\nfrom %s", path, depended ? " (as a dependency)" : "", dev->name);
pipe(pfd);
pid = fork();
@@ -138,9 +128,11 @@ package_extract(Device *dev, char *name, Boolean depended)
tot = 0;
(void)gettimeofday(&start, (struct timezone *)0);
- while (!sigpipe_caught && (i = fread(buf, 1, BUFSIZ, fp)) > 0) {
+ while ((i = fread(buf, 1, BUFSIZ, fp)) > 0) {
int seconds;
+ if (isDebug())
+ msgDebug("Just read %d bytes from media device.\n", i);
tot += i;
/* Print statistics about how we're doing */
(void) gettimeofday(&stop, (struct timezone *)0);
@@ -160,19 +152,19 @@ package_extract(Device *dev, char *name, Boolean depended)
}
close(pfd[1]);
fclose(fp);
- if (sigpipe_caught)
- msgDebug("Caught SIGPIPE while trying to install the %s package.\n", name);
+ if (i == -1)
+ msgDebug("I/O error while reading in the %s package.\n", name);
else
msgInfo("Package %s read successfully - waiting for pkg_add", name);
refresh();
i = waitpid(pid, &tot, 0);
- if (sigpipe_caught || i < 0 || WEXITSTATUS(tot)) {
+ if (i < 0 || WEXITSTATUS(tot)) {
if (variable_get(VAR_NO_CONFIRM))
- msgNotify("Add of package %s aborted due to some error -\n"
- "Please check the debug screen for more info.", name);
+ msgNotify("Add of package %s aborted, error code %d -\n"
+ "Please check the debug screen for more info.", name, WEXITSTATUS(tot));
else
- msgConfirm("Add of package %s aborted due to some error -\n"
- "Please check the debug screen for more info.", name);
+ msgConfirm("Add of package %s aborted, error code %d -\n"
+ "Please check the debug screen for more info.", name, WEXITSTATUS(tot));
}
else
msgNotify("Package %s was added successfully", name);
@@ -182,7 +174,6 @@ package_extract(Device *dev, char *name, Boolean depended)
sleep(1);
restorescr(w);
- sigpipe_caught = FALSE;
}
}
else {
diff --git a/usr.sbin/sysinstall/sysinstall.h b/usr.sbin/sysinstall/sysinstall.h
index 2fd55f8..8d0745a 100644
--- a/usr.sbin/sysinstall/sysinstall.h
+++ b/usr.sbin/sysinstall/sysinstall.h
@@ -404,6 +404,7 @@ extern void command_func_add(char *key, commandFunc func, void *data);
/* config.c */
extern int configFstab(void);
+extern void configEnvironment(char *config);
extern void configSysconfig(char *config);
extern void configResolv(void);
extern int configPackages(dialogMenuItem *self);
diff --git a/usr.sbin/sysinstall/tcpip.c b/usr.sbin/sysinstall/tcpip.c
index c294c93..b993421 100644
--- a/usr.sbin/sysinstall/tcpip.c
+++ b/usr.sbin/sysinstall/tcpip.c
@@ -255,7 +255,7 @@ reenter:
}
}
- if (!verifySettings())
+ if (!cancel && !verifySettings())
goto reenter;
/* Clear this crap off the screen */
OpenPOWER on IntegriCloud