system/corennnnn
Revisión | 39a76e97a70b0bcaccf8dbc0e28c62ac06c5cbda (tree) |
---|---|
Tiempo | 2013-06-16 17:06:07 |
Autor | Andy Ross <andy.ross@wind...> |
Commiter | Chih-Wei Huang |
Allow for overriding environment variables in export
Don't silently append duplicates, delete the older version. Also
increase the size limit, as the set of shell variables on my test
system is already at 28.
Change-Id: Id2373cc197662ae14fabad4de5e4516fe30d44cc
For: AXIA-2870
Signed-off-by: Andy Ross <andy.ross@windriver.com>
@@ -100,14 +100,24 @@ static int have_console; | ||
100 | 100 | static char *console_name = "/dev/console"; |
101 | 101 | static time_t process_needs_restart; |
102 | 102 | |
103 | -static const char *ENV[32]; | |
103 | +static const char *ENV[128]; | |
104 | 104 | |
105 | 105 | /* add_environment - add "key=value" to the current environment */ |
106 | 106 | int add_environment(const char *key, const char *val) |
107 | 107 | { |
108 | - int n; | |
109 | - | |
110 | - for (n = 0; n < 31; n++) { | |
108 | + unsigned int n, kesz; | |
109 | + char keyeq[128]; | |
110 | + int max_vars = sizeof(ENV)/sizeof(ENV[0]) - 1; /* final null for execve */ | |
111 | + | |
112 | + snprintf(keyeq, sizeof(keyeq), "%s=", key); | |
113 | + kesz = strlen(keyeq); | |
114 | + | |
115 | + for (n = 0; n < max_vars; n++) { | |
116 | + if (ENV[n] && strncmp(ENV[n], keyeq, kesz) == 0) { | |
117 | + /* Override */ | |
118 | + free((char*)ENV[n]); | |
119 | + ENV[n] = NULL; | |
120 | + } | |
111 | 121 | if (!ENV[n]) { |
112 | 122 | size_t len = strlen(key) + strlen(val) + 2; |
113 | 123 | char *entry = malloc(len); |