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.
This commit is contained in:
Jordan K. Hubbard 1997-02-14 20:59:07 +00:00
parent 88e8266d80
commit c5566bcff7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=22721
15 changed files with 354 additions and 186 deletions

View file

@ -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] == '#')
/* Skip the comments & non-variable settings */
if (lines[i][0] == '#' || !(cp = index(lines[i], '=')))
continue;
SAFE_STRCPY(tmp, lines[i]);
cp = index(tmp, '=');
if (!cp)
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:
/* Tack ourselves into /etc/hosts */
fp = fopen("/etc/hosts", "w");
/* 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 ((!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 */
fprintf(fp, "127.0.0.1\t\tlocalhost.%s localhost\n", dp ? dp : "my.domain");
/* Now the host entries, if applicable */
if (cp && cp[0] != '0' && hp) {
char cp2[255];
@ -471,7 +513,7 @@ configResolv(void)
}
fclose(fp);
if (isDebug())
msgDebug("Wrote entry for %s to /etc/hosts\n", cp);
msgDebug("Wrote out /etc/hosts\n");
}
int

View file

@ -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;

View file

@ -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;
}

View file

@ -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 {

View file

@ -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);

View file

@ -255,7 +255,7 @@ tcpOpenDialog(Device *devp)
}
}
if (!verifySettings())
if (!cancel && !verifySettings())
goto reenter;
/* Clear this crap off the screen */

View file

@ -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] == '#')
/* Skip the comments & non-variable settings */
if (lines[i][0] == '#' || !(cp = index(lines[i], '=')))
continue;
SAFE_STRCPY(tmp, lines[i]);
cp = index(tmp, '=');
if (!cp)
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:
/* Tack ourselves into /etc/hosts */
fp = fopen("/etc/hosts", "w");
/* 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 ((!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 */
fprintf(fp, "127.0.0.1\t\tlocalhost.%s localhost\n", dp ? dp : "my.domain");
/* Now the host entries, if applicable */
if (cp && cp[0] != '0' && hp) {
char cp2[255];
@ -471,7 +513,7 @@ configResolv(void)
}
fclose(fp);
if (isDebug())
msgDebug("Wrote entry for %s to /etc/hosts\n", cp);
msgDebug("Wrote out /etc/hosts\n");
}
int

View file

@ -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;

View file

@ -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);

View file

@ -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] == '#')
/* Skip the comments & non-variable settings */
if (lines[i][0] == '#' || !(cp = index(lines[i], '=')))
continue;
SAFE_STRCPY(tmp, lines[i]);
cp = index(tmp, '=');
if (!cp)
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:
/* Tack ourselves into /etc/hosts */
fp = fopen("/etc/hosts", "w");
/* 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 ((!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 */
fprintf(fp, "127.0.0.1\t\tlocalhost.%s localhost\n", dp ? dp : "my.domain");
/* Now the host entries, if applicable */
if (cp && cp[0] != '0' && hp) {
char cp2[255];
@ -471,7 +513,7 @@ configResolv(void)
}
fclose(fp);
if (isDebug())
msgDebug("Wrote entry for %s to /etc/hosts\n", cp);
msgDebug("Wrote out /etc/hosts\n");
}
int

View file

@ -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;

View file

@ -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;
}

View file

@ -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 {

View file

@ -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);

View file

@ -255,7 +255,7 @@ tcpOpenDialog(Device *devp)
}
}
if (!verifySettings())
if (!cancel && !verifySettings())
goto reenter;
/* Clear this crap off the screen */