Fix the "missing nameserver value" bug. Simplify some unnecessarily

crufty code, here and there.
This commit is contained in:
Jordan K. Hubbard 1996-10-03 07:50:09 +00:00
parent 1a7eb2dcab
commit 11a7f9359b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=18652
4 changed files with 77 additions and 46 deletions

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: config.c,v 1.48 1996/10/02 10:32:28 jkh Exp $
* $Id: config.c,v 1.49 1996/10/02 10:44:24 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@ -376,17 +376,19 @@ configResolv(void)
if (!RunningAsInit && file_readable("/etc/resolv.conf"))
return;
if (!variable_get(VAR_NAMESERVER)) {
if (mediaDevice && (mediaDevice->type == DEVICE_TYPE_NFS || mediaDevice->type == DEVICE_TYPE_FTP))
msgConfirm("Warning: Missing name server value - network operations\n"
"may fail as a result!");
goto skip;
}
if (Mkdir("/etc")) {
msgConfirm("Unable to create /etc directory. Network configuration\n"
"files will therefore not be written!");
return;
}
cp = variable_get(VAR_NAMESERVER);
if (!cp || !*cp) {
msgConfirm("Warning: Missing name server value - be sure to refer\n"
"to other hosts in any network operation by IP address\n"
"rather than name (or go back and fill in a name server).");
goto skip;
}
fp = fopen("/etc/resolv.conf", "w");
if (!fp) {
msgConfirm("Unable to open /etc/resolv.conf! You will need to do this manually.");
@ -394,32 +396,37 @@ configResolv(void)
}
if (variable_get(VAR_DOMAINNAME))
fprintf(fp, "domain\t%s\n", variable_get(VAR_DOMAINNAME));
fprintf(fp, "nameserver\t%s\n", variable_get(VAR_NAMESERVER));
fprintf(fp, "nameserver\t%s\n", cp);
fclose(fp);
if (isDebug())
msgDebug("Wrote out /etc/resolv.conf\n");
skip:
/* Tack ourselves into /etc/hosts */
cp = variable_get(VAR_IPADDR);
fp = fopen("/etc/hosts", "w");
/* Add an entry for localhost */
dp = variable_get(VAR_DOMAINNAME);
if (cp && *cp != '0' && (hp = variable_get(VAR_HOSTNAME))) {
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];
fp = fopen("/etc/hosts", "w");
if (!index(hp, '.'))
cp2[0] = '\0';
else {
strcpy(cp2, hp);
*(index(cp2, '.')) = '\0';
}
fprintf(fp, "127.0.0.1\t\tlocalhost.%s localhost\n", dp ? dp : "my.domain");
fprintf(fp, "%s\t\t%s %s\n", cp, hp, cp2);
fprintf(fp, "%s\t\t%s.\n", cp, hp);
fclose(fp);
if (isDebug())
msgDebug("Wrote entry for %s to /etc/hosts\n", cp);
}
fclose(fp);
if (isDebug())
msgDebug("Wrote entry for %s to /etc/hosts\n", cp);
}
int

View file

@ -24,7 +24,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* library functions for userconfig library
*
* $Id$
* $Id: uc_main.c,v 1.1 1996/10/03 06:01:41 jkh Exp $
*/
#include <sys/types.h>
@ -40,6 +40,9 @@
#include "uc_main.h"
extern int isDebug(void);
extern void msgDebug(char *fmt, ...);
struct nlist nl[] = {
{"_isa_devtab_bio"},
{"_isa_devtab_tty"},
@ -77,6 +80,8 @@ uc_open(char *name){
} else {
strncpy(kname, name, 79);
}
if (isDebug())
msgDebug("Kernel name is %s, incore = %d\n", kname, incore);
kern=(struct kernel *)malloc(sizeof(struct kernel));
@ -88,6 +93,7 @@ uc_open(char *name){
if((kd=open("/dev/kmem", O_RDONLY))<0){
free(kern);
kern=(struct kernel *)-3;
msgDebug("uc_open: Unable to open /dev/kmem.\n");
return(kern);
}
@ -99,6 +105,7 @@ uc_open(char *name){
if(stat(kname, &sb)<0){
free(kern);
kern=(struct kernel *)-1;
msgDebug("uc_open: Unable to stat %s.\n", kname);
return(kern);
}
kern->size=sb.st_size;
@ -107,12 +114,14 @@ uc_open(char *name){
if (chflags(kname, 0)<0){
free(kern);
kern=(struct kernel *)-2;
msgDebug("uc_open: Unable to chflags %s.\n", kname);
return(kern);
}
if((kd=open(kname, O_RDWR, 0644))<0){
free(kern);
kern=(struct kernel *)-3;
msgDebug("uc_open: Unable to open %s.\n", kname);
return(kern);
}
@ -125,6 +134,7 @@ uc_open(char *name){
if(kern->core == (caddr_t)0){
free(kern);
kern=(struct kernel *)-4;
msgDebug("uc_open: Unable to mmap from %s.\n", kname);
return(kern);
}
}

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: config.c,v 1.48 1996/10/02 10:32:28 jkh Exp $
* $Id: config.c,v 1.49 1996/10/02 10:44:24 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@ -376,17 +376,19 @@ configResolv(void)
if (!RunningAsInit && file_readable("/etc/resolv.conf"))
return;
if (!variable_get(VAR_NAMESERVER)) {
if (mediaDevice && (mediaDevice->type == DEVICE_TYPE_NFS || mediaDevice->type == DEVICE_TYPE_FTP))
msgConfirm("Warning: Missing name server value - network operations\n"
"may fail as a result!");
goto skip;
}
if (Mkdir("/etc")) {
msgConfirm("Unable to create /etc directory. Network configuration\n"
"files will therefore not be written!");
return;
}
cp = variable_get(VAR_NAMESERVER);
if (!cp || !*cp) {
msgConfirm("Warning: Missing name server value - be sure to refer\n"
"to other hosts in any network operation by IP address\n"
"rather than name (or go back and fill in a name server).");
goto skip;
}
fp = fopen("/etc/resolv.conf", "w");
if (!fp) {
msgConfirm("Unable to open /etc/resolv.conf! You will need to do this manually.");
@ -394,32 +396,37 @@ configResolv(void)
}
if (variable_get(VAR_DOMAINNAME))
fprintf(fp, "domain\t%s\n", variable_get(VAR_DOMAINNAME));
fprintf(fp, "nameserver\t%s\n", variable_get(VAR_NAMESERVER));
fprintf(fp, "nameserver\t%s\n", cp);
fclose(fp);
if (isDebug())
msgDebug("Wrote out /etc/resolv.conf\n");
skip:
/* Tack ourselves into /etc/hosts */
cp = variable_get(VAR_IPADDR);
fp = fopen("/etc/hosts", "w");
/* Add an entry for localhost */
dp = variable_get(VAR_DOMAINNAME);
if (cp && *cp != '0' && (hp = variable_get(VAR_HOSTNAME))) {
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];
fp = fopen("/etc/hosts", "w");
if (!index(hp, '.'))
cp2[0] = '\0';
else {
strcpy(cp2, hp);
*(index(cp2, '.')) = '\0';
}
fprintf(fp, "127.0.0.1\t\tlocalhost.%s localhost\n", dp ? dp : "my.domain");
fprintf(fp, "%s\t\t%s %s\n", cp, hp, cp2);
fprintf(fp, "%s\t\t%s.\n", cp, hp);
fclose(fp);
if (isDebug())
msgDebug("Wrote entry for %s to /etc/hosts\n", cp);
}
fclose(fp);
if (isDebug())
msgDebug("Wrote entry for %s to /etc/hosts\n", cp);
}
int

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: config.c,v 1.48 1996/10/02 10:32:28 jkh Exp $
* $Id: config.c,v 1.49 1996/10/02 10:44:24 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@ -376,17 +376,19 @@ configResolv(void)
if (!RunningAsInit && file_readable("/etc/resolv.conf"))
return;
if (!variable_get(VAR_NAMESERVER)) {
if (mediaDevice && (mediaDevice->type == DEVICE_TYPE_NFS || mediaDevice->type == DEVICE_TYPE_FTP))
msgConfirm("Warning: Missing name server value - network operations\n"
"may fail as a result!");
goto skip;
}
if (Mkdir("/etc")) {
msgConfirm("Unable to create /etc directory. Network configuration\n"
"files will therefore not be written!");
return;
}
cp = variable_get(VAR_NAMESERVER);
if (!cp || !*cp) {
msgConfirm("Warning: Missing name server value - be sure to refer\n"
"to other hosts in any network operation by IP address\n"
"rather than name (or go back and fill in a name server).");
goto skip;
}
fp = fopen("/etc/resolv.conf", "w");
if (!fp) {
msgConfirm("Unable to open /etc/resolv.conf! You will need to do this manually.");
@ -394,32 +396,37 @@ configResolv(void)
}
if (variable_get(VAR_DOMAINNAME))
fprintf(fp, "domain\t%s\n", variable_get(VAR_DOMAINNAME));
fprintf(fp, "nameserver\t%s\n", variable_get(VAR_NAMESERVER));
fprintf(fp, "nameserver\t%s\n", cp);
fclose(fp);
if (isDebug())
msgDebug("Wrote out /etc/resolv.conf\n");
skip:
/* Tack ourselves into /etc/hosts */
cp = variable_get(VAR_IPADDR);
fp = fopen("/etc/hosts", "w");
/* Add an entry for localhost */
dp = variable_get(VAR_DOMAINNAME);
if (cp && *cp != '0' && (hp = variable_get(VAR_HOSTNAME))) {
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];
fp = fopen("/etc/hosts", "w");
if (!index(hp, '.'))
cp2[0] = '\0';
else {
strcpy(cp2, hp);
*(index(cp2, '.')) = '\0';
}
fprintf(fp, "127.0.0.1\t\tlocalhost.%s localhost\n", dp ? dp : "my.domain");
fprintf(fp, "%s\t\t%s %s\n", cp, hp, cp2);
fprintf(fp, "%s\t\t%s.\n", cp, hp);
fclose(fp);
if (isDebug())
msgDebug("Wrote entry for %s to /etc/hosts\n", cp);
}
fclose(fp);
if (isDebug())
msgDebug("Wrote entry for %s to /etc/hosts\n", cp);
}
int