subr_hints.c (240070) | subr_hints.c (240119) |
---|---|
1/*- 2 * Copyright (c) 2000,2001 Peter Wemm <peter@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2000,2001 Peter Wemm <peter@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/kern/subr_hints.c 240070 2012-09-03 09:46:46Z ray $"); | 28__FBSDID("$FreeBSD: head/sys/kern/subr_hints.c 240119 2012-09-04 23:16:55Z ray $"); |
29 30#include <sys/param.h> 31#include <sys/lock.h> 32#include <sys/malloc.h> 33#include <sys/mutex.h> | 29 30#include <sys/param.h> 31#include <sys/lock.h> 32#include <sys/malloc.h> 33#include <sys/mutex.h> |
34#include <sys/systm.h> | |
35#include <sys/sysctl.h> | 34#include <sys/sysctl.h> |
35#include <sys/systm.h> |
|
36#include <sys/bus.h> 37 38/* 39 * Access functions for device resources. 40 */ 41 42static int checkmethod = 1; 43static int use_kenv; 44static char *hintp; 45 46/* 47 * Define kern.hintmode sysctl, which only accept value 2, that cause to 48 * switch from Static KENV mode to Dynamic KENV. So systems that have hints 49 * compiled into kernel will be able to see/modify KENV (and hints too). 50 */ 51 52static int 53sysctl_hintmode(SYSCTL_HANDLER_ARGS) 54{ | 36#include <sys/bus.h> 37 38/* 39 * Access functions for device resources. 40 */ 41 42static int checkmethod = 1; 43static int use_kenv; 44static char *hintp; 45 46/* 47 * Define kern.hintmode sysctl, which only accept value 2, that cause to 48 * switch from Static KENV mode to Dynamic KENV. So systems that have hints 49 * compiled into kernel will be able to see/modify KENV (and hints too). 50 */ 51 52static int 53sysctl_hintmode(SYSCTL_HANDLER_ARGS) 54{ |
55 int error, i, from_kenv, value, eqidx; | |
56 const char *cp; 57 char *line, *eq; | 55 const char *cp; 56 char *line, *eq; |
57 int eqidx, error, from_kenv, i, value; |
|
58 59 from_kenv = 0; 60 cp = kern_envp; 61 value = hintmode; 62 63 /* Fetch candidate for new hintmode value */ 64 error = sysctl_handle_int(oidp, &value, 0, req); | 58 59 from_kenv = 0; 60 cp = kern_envp; 61 value = hintmode; 62 63 /* Fetch candidate for new hintmode value */ 64 error = sysctl_handle_int(oidp, &value, 0, req); |
65 if (error || !req->newptr) | 65 if (error || req->newptr == NULL) |
66 return (error); 67 68 if (value != 2) 69 /* Only accept swithing to hintmode 2 */ 70 return (EINVAL); 71 72 /* Migrate from static to dynamic hints */ 73 switch (hintmode) { 74 case 0: 75 if (dynamic_kenv) { | 66 return (error); 67 68 if (value != 2) 69 /* Only accept swithing to hintmode 2 */ 70 return (EINVAL); 71 72 /* Migrate from static to dynamic hints */ 73 switch (hintmode) { 74 case 0: 75 if (dynamic_kenv) { |
76 /* Already here */ 77 hintmode = value; /* XXX: Need we switch or not ? */ | 76 /* 77 * Already here. But assign hintmode to 2, to not 78 * check it in the future. 79 */ 80 hintmode = 2; |
78 return (0); 79 } 80 from_kenv = 1; 81 cp = kern_envp; 82 break; 83 case 1: 84 cp = static_hints; 85 break; --- 7 unchanged lines hidden (view full) --- 93 if (i == 0) 94 break; 95 if (from_kenv) { 96 if (strncmp(cp, "hint.", 5) != 0) 97 /* kenv can have not only hints */ 98 continue; 99 } 100 eq = strchr(cp, '='); | 81 return (0); 82 } 83 from_kenv = 1; 84 cp = kern_envp; 85 break; 86 case 1: 87 cp = static_hints; 88 break; --- 7 unchanged lines hidden (view full) --- 96 if (i == 0) 97 break; 98 if (from_kenv) { 99 if (strncmp(cp, "hint.", 5) != 0) 100 /* kenv can have not only hints */ 101 continue; 102 } 103 eq = strchr(cp, '='); |
101 if (!eq) | 104 if (eq == NULL) |
102 /* Bad hint value */ 103 continue; 104 eqidx = eq - cp; 105 106 line = malloc(i+1, M_TEMP, M_WAITOK); 107 strcpy(line, cp); 108 line[eqidx] = '\0'; 109 setenv(line, line + eqidx + 1); --- 351 unchanged lines hidden --- | 105 /* Bad hint value */ 106 continue; 107 eqidx = eq - cp; 108 109 line = malloc(i+1, M_TEMP, M_WAITOK); 110 strcpy(line, cp); 111 line[eqidx] = '\0'; 112 setenv(line, line + eqidx + 1); --- 351 unchanged lines hidden --- |