summaryrefslogtreecommitdiffstats
path: root/release
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1999-01-27 02:32:47 +0000
committerjkh <jkh@FreeBSD.org>1999-01-27 02:32:47 +0000
commit51f031f980235df682c3f8989a3a33f593c26f23 (patch)
tree80848b68d53a422c68458ed0c5edcf7a88d2bf10 /release
parent78e7f4e7dcd3762a6b1b323a53118b77e5dd948d (diff)
downloadFreeBSD-src-51f031f980235df682c3f8989a3a33f593c26f23.zip
FreeBSD-src-51f031f980235df682c3f8989a3a33f593c26f23.tar.gz
Write changes out to /etc/rc.conf.site now rather than mucking with
rc.conf. There were many different ways I could have done this, some of them "cleaner", but this represented the lowest impact.
Diffstat (limited to 'release')
-rw-r--r--release/sysinstall/config.c111
-rw-r--r--release/sysinstall/install.c4
-rw-r--r--release/sysinstall/sysinstall.h4
3 files changed, 68 insertions, 51 deletions
diff --git a/release/sysinstall/config.c b/release/sysinstall/config.c
index 878a232..d83b31d 100644
--- a/release/sysinstall/config.c
+++ b/release/sysinstall/config.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: config.c,v 1.114 1998/10/14 01:04:44 jkh Exp $
+ * $Id: config.c,v 1.115 1998/11/15 09:06:19 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -287,9 +287,8 @@ 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 an rc.conf file */
-void
-configEnvironmentRC_conf(char *config)
+static void
+configReadRC_conf(char *config)
{
char *lines[MAX_LINES], *cp, *cp2;
int i, nlines;
@@ -321,6 +320,24 @@ configEnvironmentRC_conf(char *config)
}
}
+/* Load the environment from rc.conf file(s) */
+void
+configEnvironmentRC_conf(void)
+{
+ static char *configs[] = {
+ "/etc/rc.conf",
+ "/etc/rc.conf.site",
+ "/etc/rc.conf.local",
+ NULL
+ };
+ int i;
+
+ for (i = 0; configs[i]; i++) {
+ if (file_readable(configs[i]))
+ configReadRC_conf(configs[i]);
+ }
+}
+
/* Load the environment from a resolv.conf file */
void
configEnvironmentResolv(char *config)
@@ -359,11 +376,15 @@ configRC(dialogMenuItem *unused)
void
configRC_conf(char *config)
{
- FILE *fp;
+ FILE *rcSite;
char *lines[MAX_LINES], *cp;
Variable *v;
int i, nlines, len;
+ rcSite = fopen("/etc/rc.conf.site", "w");
+ if (!rcSite)
+ return;
+
nlines = readConfig(config, lines, MAX_LINES);
if (nlines == -1)
return;
@@ -372,8 +393,11 @@ configRC_conf(char *config)
for (v = VarHead; v; v = v->next) {
for (i = 0; i < nlines; i++) {
/* Skip the comments & non-variable settings */
- if (lines[i][0] == '#' || !(cp = index(lines[i], '=')))
+ if (lines[i][0] == '#' || !(cp = index(lines[i], '='))) {
+ free(lines[i]);
continue;
+ }
+
len = strlen(v->name);
if (!strncmp(lines[i], v->name, cp - lines[i]) && (cp - lines[i]) == len) {
char *cp2, *comment = NULL;
@@ -389,57 +413,50 @@ configRC_conf(char *config)
}
}
free(lines[i]);
- lines[i] = (char *)malloc(strlen(v->name) + strlen(v->value) + (comment ? strlen(comment) : 0) + 10);
+ lines[i] = (char *)alloca(strlen(v->name) + strlen(v->value) + (comment ? strlen(comment) : 0) + 10);
if (comment)
sprintf(lines[i], "%s=\"%s\"%s", v->name, v->value, comment);
else
sprintf(lines[i], "%s=\"%s\"\n", v->name, v->value);
- }
- }
- }
-
- /* Now write it all back out again */
- if (isDebug())
- msgDebug("Writing configuration changes to %s file..", config);
- if (Fake)
- fp = fdopen(DebugFD, "w");
- else {
- (void)vsystem("cp %s %s.previous", config, config);
- fp = fopen(config, "w");
- }
- for (i = 0; i < nlines; i++) {
- fprintf(fp, lines[i]);
- /* Stand by for bogus special case handling - we try to dump the interface specs here */
- if (!strncmp(lines[i], VAR_INTERFACES, strlen(VAR_INTERFACES))) {
- Device **devp;
- int j, cnt;
-
- devp = deviceFind(NULL, DEVICE_TYPE_NETWORK);
- cnt = deviceCount(devp);
- for (j = 0; j < cnt; j++) {
- char iname[255], toadd[512];
- int k, addit = TRUE;
-
- if (!strncmp(devp[j]->name, "ppp", 3) || !strncmp(devp[j]->name, "tun", 3))
- continue;
-
- snprintf(iname, 255, "%s%s", VAR_IFCONFIG, devp[j]->name);
- if ((cp = variable_get(iname))) {
- snprintf(toadd, sizeof toadd, "%s=\"%s\"\n", iname, cp);
- for (k = 0; k < nlines; k++) {
- if (!strcmp(lines[k], toadd)) {
- addit = FALSE;
- break;
+ fputs(lines[i], rcSite);
+ /* Stand by for bogus special case handling;
+ * we try to dump the interface specs here
+ */
+ if (!strncmp(lines[i], VAR_INTERFACES,
+ strlen(VAR_INTERFACES))) {
+ Device **devp;
+ int j, cnt;
+
+ devp = deviceFind(NULL, DEVICE_TYPE_NETWORK);
+ cnt = deviceCount(devp);
+ for (j = 0; j < cnt; j++) {
+ char iname[255], toadd[512];
+ int k, addit = TRUE;
+
+ if (!strncmp(devp[j]->name, "ppp", 3) ||
+ !strncmp(devp[j]->name, "tun", 3))
+ continue;
+
+ snprintf(iname, 255, "%s%s", VAR_IFCONFIG, devp[j]->name);
+ if ((cp = variable_get(iname))) {
+ snprintf(toadd, sizeof toadd, "%s=\"%s\"\n", iname, cp);
+ for (k = 0; k < nlines; k++) {
+ if (!strcmp(lines[k], toadd)) {
+ addit = FALSE;
+ break;
+ }
+ }
+ if (addit)
+ fputs(toadd, rcSite);
}
}
- if (addit)
- fprintf(fp, toadd);
}
}
+ else
+ free(lines[i]);
}
- free(lines[i]);
}
- fclose(fp);
+ fclose(rcSite);
}
int
diff --git a/release/sysinstall/install.c b/release/sysinstall/install.c
index fc1f42e..78b2ef6 100644
--- a/release/sysinstall/install.c
+++ b/release/sysinstall/install.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: install.c,v 1.222 1999/01/20 11:56:39 jkh Exp $
+ * $Id: install.c,v 1.223 1999/01/20 12:31:42 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -1065,7 +1065,7 @@ void
installEnvironment(void)
{
if (file_readable("/etc/rc.conf"))
- configEnvironmentRC_conf("/etc/rc.conf");
+ configEnvironmentRC_conf();
if (file_readable("/etc/resolv.conf"))
configEnvironmentResolv("/etc/resolv.conf");
}
diff --git a/release/sysinstall/sysinstall.h b/release/sysinstall/sysinstall.h
index a50eb3e..67fbf84 100644
--- a/release/sysinstall/sysinstall.h
+++ b/release/sysinstall/sysinstall.h
@@ -4,7 +4,7 @@
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated to essentially a complete rewrite.
*
- * $Id: sysinstall.h,v 1.152 1998/12/22 12:31:25 jkh Exp $
+ * $Id: sysinstall.h,v 1.153 1999/01/20 12:31:43 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -401,7 +401,7 @@ extern void command_shell_add(char *key, char *fmt, ...);
extern void command_func_add(char *key, commandFunc func, void *data);
/* config.c */
-extern void configEnvironmentRC_conf(char *config);
+extern void configEnvironmentRC_conf(void);
extern void configEnvironmentResolv(char *config);
extern void configRC_conf(char *config);
extern int configFstab(dialogMenuItem *self);
OpenPOWER on IntegriCloud