diff options
author | mux <mux@FreeBSD.org> | 2002-04-17 13:06:36 +0000 |
---|---|---|
committer | mux <mux@FreeBSD.org> | 2002-04-17 13:06:36 +0000 |
commit | a207e41bef089b8849a230f44088a562d0b5d19f (patch) | |
tree | cb447f9f2a04a764ece9fcefc6fa6b52d19870b8 /sys/amd64 | |
parent | c79270302c4767b589a4fe70da3ba9866936358f (diff) | |
download | FreeBSD-src-a207e41bef089b8849a230f44088a562d0b5d19f.zip FreeBSD-src-a207e41bef089b8849a230f44088a562d0b5d19f.tar.gz |
Rework the kernel environment subsystem. We now convert the static
environment needed at boot time to a dynamic subsystem when VM is
up. The dynamic kernel environment is protected by an sx lock.
This adds some new functions to manipulate the kernel environment :
freeenv(), setenv(), unsetenv() and testenv(). freeenv() has to be
called after every getenv() when you have finished using the string.
testenv() only tests if an environment variable is present, and
doesn't require a freeenv() call. setenv() and unsetenv() are self
explanatory.
The kenv(2) syscall exports these new functionalities to userland,
mainly for kenv(1).
Reviewed by: peter
Diffstat (limited to 'sys/amd64')
-rw-r--r-- | sys/amd64/amd64/autoconf.c | 33 | ||||
-rw-r--r-- | sys/amd64/amd64/bios.c | 4 | ||||
-rw-r--r-- | sys/amd64/amd64/machdep.c | 3 |
3 files changed, 32 insertions, 8 deletions
diff --git a/sys/amd64/amd64/autoconf.c b/sys/amd64/amd64/autoconf.c index d8d7b4f..60b3725 100644 --- a/sys/amd64/amd64/autoconf.c +++ b/sys/amd64/amd64/autoconf.c @@ -242,6 +242,7 @@ inaddr_to_sockaddr(char *ev, struct sockaddr_in *sa) { u_int32_t a[4]; char *cp; + int count; bzero(sa, sizeof(*sa)); sa->sin_len = sizeof(*sa); @@ -249,7 +250,9 @@ inaddr_to_sockaddr(char *ev, struct sockaddr_in *sa) if ((cp = getenv(ev)) == NULL) return(1); - if (sscanf(cp, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]) != 4) + count = sscanf(cp, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]); + freeenv(cp); + if (count != 4) return(1); /* XXX is this ordering correct? */ sa->sin_addr.s_addr = (a[3] << 24) + (a[2] << 16) + (a[1] << 8) + a[0]; @@ -261,6 +264,7 @@ hwaddr_to_sockaddr(char *ev, struct sockaddr_dl *sa) { char *cp; u_int32_t a[6]; + int count; bzero(sa, sizeof(*sa)); sa->sdl_len = sizeof(*sa); @@ -269,7 +273,10 @@ hwaddr_to_sockaddr(char *ev, struct sockaddr_dl *sa) sa->sdl_alen = ETHER_ADDR_LEN; if ((cp = getenv(ev)) == NULL) return(1); - if (sscanf(cp, "%x:%x:%x:%x:%x:%x", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]) != 6) + count = sscanf(cp, "%x:%x:%x:%x:%x:%x", + &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]); + freeenv(cp); + if (count != 6) return(1); sa->sdl_data[0] = a[0]; sa->sdl_data[1] = a[1]; @@ -286,20 +293,30 @@ decode_nfshandle(char *ev, u_char *fh) u_char *cp; int len, val; - if (((cp = getenv(ev)) == NULL) || (strlen(cp) < 2) || (*cp != 'X')) + if ((cp = getenv(ev)) == NULL) return(0); + if ((strlen(cp) < 2) || (*cp != 'X')) { + freeenv(cp); + return (0); + } len = 0; cp++; for (;;) { - if (*cp == 'X') + if (*cp == 'X') { + freeenv(cp); return(len); - if ((sscanf(cp, "%2x", &val) != 1) || (val > 0xff)) + } + if ((sscanf(cp, "%2x", &val) != 1) || (val > 0xff)) { + freeenv(cp); return(0); + } *(fh++) = val; len++; cp += 2; - if (len > NFSX_V2FH) + if (len > NFSX_V2FH) { + freeenv(cp); return(0); + } } } @@ -382,8 +399,10 @@ match_done: printf("PXE: no NFS handle\n"); return; } - if ((cp = getenv("boot.nfsroot.path")) != NULL) + if ((cp = getenv("boot.nfsroot.path")) != NULL) { strncpy(nd->root_hostnam, cp, MNAMELEN - 1); + freeenv(cp); + } nfs_diskless_valid = 1; } diff --git a/sys/amd64/amd64/bios.c b/sys/amd64/amd64/bios.c index 40696fb..bfd1afe 100644 --- a/sys/amd64/amd64/bios.c +++ b/sys/amd64/amd64/bios.c @@ -110,6 +110,8 @@ bios32_init(void *junk) if (!bios32_SDlookup(&PCIbios) && bootverbose) printf("pcibios: PCI BIOS entry at 0x%x+0x%x\n", PCIbios.base, PCIbios.entry); } + if (p != NULL) + freeenv(p); } else { printf("bios32: Bad BIOS32 Service Directory\n"); } @@ -145,6 +147,8 @@ bios32_init(void *junk) printf("pnpbios: Bad PnP BIOS data checksum\n"); } } + if (p != NULL) + freeenv(p); if (bootverbose) { /* look for other know signatures */ printf("Other BIOS signatures found:\n"); diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index a3ad87b..8db2ab8 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -1238,7 +1238,7 @@ getmemsize(int first) struct vm86context vmc; vm_offset_t pa, physmap[PHYSMAP_SIZE]; pt_entry_t *pte; - const char *cp; + char *cp; struct bios_smap *smap; bzero(&vmf, sizeof(struct vm86frame)); @@ -1454,6 +1454,7 @@ physmap_done: printf("Ignoring invalid memory size of '%s'\n", cp); else Maxmem = atop(AllowMem); + freeenv(cp); } if (atop(physmap[physmap_idx + 1]) != Maxmem && |