Read /etc/resolv.conf information as well as /etc/sysconfig info, making

this a little more robust.
This commit is contained in:
Jordan K. Hubbard 1997-02-15 15:24:14 +00:00
parent 2df00d4c64
commit e33c24a2d2
12 changed files with 120 additions and 21 deletions

View file

@ -301,9 +301,9 @@ readConfig(char *config, char **lines, int max)
#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 */
/* Load the environment from a sysconfig file */
void
configEnvironment(char *config)
configEnvironmentSysconfig(char *config)
{
char *lines[MAX_LINES], *cp, *cp2;
int i, j, nlines;
@ -332,6 +332,30 @@ configEnvironment(char *config)
}
}
/* Load the environment from a resolv.conf file */
void
configEnvironmentResolv(char *config)
{
char *lines[MAX_LINES];
int i, nlines;
nlines = readConfig(config, lines, MAX_LINES);
if (nlines == -1)
return;
for (i = 0; i < nlines; i++) {
Boolean name_set = FALSE;
if (!strncmp(lines[i], "domain", 6))
variable_set2(VAR_DOMAINNAME, string_skipwhite(lines[i] + 6));
else if (!strncmp(lines[i], "nameserver", 10) && !name_set) {
/* Only take the first nameserver setting - we're lame */
variable_set2(VAR_NAMESERVER, string_skipwhite(lines[i] + 10));
name_set = TRUE;
}
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.
@ -360,7 +384,6 @@ configSysconfig(char *config)
free(lines[i]);
lines[i] = (char *)malloc(strlen(v->name) + strlen(v->value) + 5);
sprintf(lines[i], "%s=\"%s\"\n", v->name, v->value);
msgDebug("Variable substitution on: %s\n", lines[i]);
}
}
}

View file

@ -973,6 +973,16 @@ installVarDefaults(dialogMenuItem *self)
return DITEM_SUCCESS;
}
/* Load the environment up from various system configuration files */
void
installEnvironment(void)
{
if (file_readable("/etc/sysconfig"))
configEnvironmentSysconfig("/etc/sysconfig");
if (file_readable("/etc/resolv.conf"))
configEnvironmentResolv("/etc/resolv.conf");
}
/* Copy the boot floppy contents into /stand */
Boolean
copySelf(void)

View file

@ -70,9 +70,7 @@ main(int argc, char **argv)
/* Set default flag and variable values */
installVarDefaults(NULL);
if (file_readable("/etc/sysconfig"))
configEnvironment("/etc/sysconfig");
installEnvironment();
if (argc > 1 && !strcmp(argv[1], "-fake")) {
variable_set2(VAR_DEBUG, "YES");

View file

@ -404,7 +404,8 @@ extern void command_func_add(char *key, commandFunc func, void *data);
/* config.c */
extern int configFstab(void);
extern void configEnvironment(char *config);
extern void configEnvironmentSysconfig(char *config);
extern void configEnvironmentResolv(char *config);
extern void configSysconfig(char *config);
extern void configResolv(void);
extern int configPackages(dialogMenuItem *self);
@ -530,6 +531,7 @@ extern int installFixup(dialogMenuItem *self);
extern int installUpgrade(dialogMenuItem *self);
extern int installFilesystems(dialogMenuItem *self);
extern int installVarDefaults(dialogMenuItem *self);
extern void installEnvironment(void);
extern Boolean copySelf(void);
/* keymap.c */

View file

@ -301,9 +301,9 @@ readConfig(char *config, char **lines, int max)
#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 */
/* Load the environment from a sysconfig file */
void
configEnvironment(char *config)
configEnvironmentSysconfig(char *config)
{
char *lines[MAX_LINES], *cp, *cp2;
int i, j, nlines;
@ -332,6 +332,30 @@ configEnvironment(char *config)
}
}
/* Load the environment from a resolv.conf file */
void
configEnvironmentResolv(char *config)
{
char *lines[MAX_LINES];
int i, nlines;
nlines = readConfig(config, lines, MAX_LINES);
if (nlines == -1)
return;
for (i = 0; i < nlines; i++) {
Boolean name_set = FALSE;
if (!strncmp(lines[i], "domain", 6))
variable_set2(VAR_DOMAINNAME, string_skipwhite(lines[i] + 6));
else if (!strncmp(lines[i], "nameserver", 10) && !name_set) {
/* Only take the first nameserver setting - we're lame */
variable_set2(VAR_NAMESERVER, string_skipwhite(lines[i] + 10));
name_set = TRUE;
}
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.
@ -360,7 +384,6 @@ configSysconfig(char *config)
free(lines[i]);
lines[i] = (char *)malloc(strlen(v->name) + strlen(v->value) + 5);
sprintf(lines[i], "%s=\"%s\"\n", v->name, v->value);
msgDebug("Variable substitution on: %s\n", lines[i]);
}
}
}

View file

@ -973,6 +973,16 @@ installVarDefaults(dialogMenuItem *self)
return DITEM_SUCCESS;
}
/* Load the environment up from various system configuration files */
void
installEnvironment(void)
{
if (file_readable("/etc/sysconfig"))
configEnvironmentSysconfig("/etc/sysconfig");
if (file_readable("/etc/resolv.conf"))
configEnvironmentResolv("/etc/resolv.conf");
}
/* Copy the boot floppy contents into /stand */
Boolean
copySelf(void)

View file

@ -70,9 +70,7 @@ main(int argc, char **argv)
/* Set default flag and variable values */
installVarDefaults(NULL);
if (file_readable("/etc/sysconfig"))
configEnvironment("/etc/sysconfig");
installEnvironment();
if (argc > 1 && !strcmp(argv[1], "-fake")) {
variable_set2(VAR_DEBUG, "YES");

View file

@ -404,7 +404,8 @@ extern void command_func_add(char *key, commandFunc func, void *data);
/* config.c */
extern int configFstab(void);
extern void configEnvironment(char *config);
extern void configEnvironmentSysconfig(char *config);
extern void configEnvironmentResolv(char *config);
extern void configSysconfig(char *config);
extern void configResolv(void);
extern int configPackages(dialogMenuItem *self);
@ -530,6 +531,7 @@ extern int installFixup(dialogMenuItem *self);
extern int installUpgrade(dialogMenuItem *self);
extern int installFilesystems(dialogMenuItem *self);
extern int installVarDefaults(dialogMenuItem *self);
extern void installEnvironment(void);
extern Boolean copySelf(void);
/* keymap.c */

View file

@ -301,9 +301,9 @@ readConfig(char *config, char **lines, int max)
#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 */
/* Load the environment from a sysconfig file */
void
configEnvironment(char *config)
configEnvironmentSysconfig(char *config)
{
char *lines[MAX_LINES], *cp, *cp2;
int i, j, nlines;
@ -332,6 +332,30 @@ configEnvironment(char *config)
}
}
/* Load the environment from a resolv.conf file */
void
configEnvironmentResolv(char *config)
{
char *lines[MAX_LINES];
int i, nlines;
nlines = readConfig(config, lines, MAX_LINES);
if (nlines == -1)
return;
for (i = 0; i < nlines; i++) {
Boolean name_set = FALSE;
if (!strncmp(lines[i], "domain", 6))
variable_set2(VAR_DOMAINNAME, string_skipwhite(lines[i] + 6));
else if (!strncmp(lines[i], "nameserver", 10) && !name_set) {
/* Only take the first nameserver setting - we're lame */
variable_set2(VAR_NAMESERVER, string_skipwhite(lines[i] + 10));
name_set = TRUE;
}
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.
@ -360,7 +384,6 @@ configSysconfig(char *config)
free(lines[i]);
lines[i] = (char *)malloc(strlen(v->name) + strlen(v->value) + 5);
sprintf(lines[i], "%s=\"%s\"\n", v->name, v->value);
msgDebug("Variable substitution on: %s\n", lines[i]);
}
}
}

View file

@ -973,6 +973,16 @@ installVarDefaults(dialogMenuItem *self)
return DITEM_SUCCESS;
}
/* Load the environment up from various system configuration files */
void
installEnvironment(void)
{
if (file_readable("/etc/sysconfig"))
configEnvironmentSysconfig("/etc/sysconfig");
if (file_readable("/etc/resolv.conf"))
configEnvironmentResolv("/etc/resolv.conf");
}
/* Copy the boot floppy contents into /stand */
Boolean
copySelf(void)

View file

@ -70,9 +70,7 @@ main(int argc, char **argv)
/* Set default flag and variable values */
installVarDefaults(NULL);
if (file_readable("/etc/sysconfig"))
configEnvironment("/etc/sysconfig");
installEnvironment();
if (argc > 1 && !strcmp(argv[1], "-fake")) {
variable_set2(VAR_DEBUG, "YES");

View file

@ -404,7 +404,8 @@ extern void command_func_add(char *key, commandFunc func, void *data);
/* config.c */
extern int configFstab(void);
extern void configEnvironment(char *config);
extern void configEnvironmentSysconfig(char *config);
extern void configEnvironmentResolv(char *config);
extern void configSysconfig(char *config);
extern void configResolv(void);
extern int configPackages(dialogMenuItem *self);
@ -530,6 +531,7 @@ extern int installFixup(dialogMenuItem *self);
extern int installUpgrade(dialogMenuItem *self);
extern int installFilesystems(dialogMenuItem *self);
extern int installVarDefaults(dialogMenuItem *self);
extern void installEnvironment(void);
extern Boolean copySelf(void);
/* keymap.c */