Skip to content

Commit 283b70b

Browse files
hyperb1issGerrit Code Review
authored and
Gerrit Code Review
committed
init: support in init for replacing environment keys
* Add support in init for replacing environment keys Change-Id: I9940293f9932cf5ec4255d59d553dd3605c6bae5
1 parent d8aa8ab commit 283b70b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

init/init.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,14 @@ static unsigned charging_mode = 0;
114114
int add_environment(const char *key, const char *val)
115115
{
116116
int n;
117+
size_t lens = strlen(key) + 2;
118+
char *check = malloc(lens);
119+
snprintf(check, lens, "%s=", key);
117120

118121
for (n = 0; n < 31; n++) {
119-
if (!ENV[n]) {
122+
if (!ENV[n] || strncmp(ENV[n], check, strlen(check)) == 0) {
123+
if (ENV[n])
124+
free(ENV[n]);
120125
size_t len = strlen(key) + strlen(val) + 2;
121126
char *entry = malloc(len);
122127
snprintf(entry, len, "%s=%s", key, val);

0 commit comments

Comments
 (0)