Skip to content
Snippets Groups Projects
Commit 1beed7af authored by schneider's avatar schneider
Browse files

fix(config): Always re-read config in case of an error

parent 277a221a
Branches
Tags
1 merge request!375Default main app selector
Pipeline #4533 canceled
......@@ -130,12 +130,12 @@ static void add_config_pair(
static void trim(char *str)
{
char *start = str;
while (*start && !isgraph((int)*start))
while (*start && !isgraph(*start))
start++;
if (strlen(start) > 0) {
char *end = start + strlen(start) - 1;
while (*end && !isgraph((int)*end))
while (*end && !isgraph(*end))
end--;
end[1] = 0;
}
......@@ -388,7 +388,6 @@ bool config_get_boolean_with_default(const char *key, bool default_value)
}
}
// TODO: don't allow things like "execute_elf" to be set
int epic_config_set_string(const char *key, const char *value_in)
{
char value[MAX_LINE_LENGTH + 1];
......@@ -481,10 +480,10 @@ int epic_config_set_string(const char *key, const char *value_in)
);
}
if (write_ret < 0) {
return write_ret;
ret = write_ret;
}
if (ret < 0) {
return ret;
goto out;
}
if (write_ret < (int)strlen(buf)) {
LOG_DEBUG(
......@@ -493,7 +492,8 @@ int epic_config_set_string(const char *key, const char *value_in)
write_ret,
strlen(buf)
);
return -EIO;
ret = -EIO;
goto out;
}
} else {
/* Complex case: The value is already somewhere in the file.
......@@ -511,7 +511,7 @@ int epic_config_set_string(const char *key, const char *value_in)
);
if (nread == 0) {
LOG_DEBUG("card10.cfg", "could not read old value", );
goto out;
goto complex_out;
}
char *end = buf;
......@@ -530,7 +530,7 @@ int epic_config_set_string(const char *key, const char *value_in)
fd1
);
ret = fd1;
goto out;
goto complex_out;
}
fd2 = epic_file_open("card10.nfg", "w");
......@@ -542,7 +542,7 @@ int epic_config_set_string(const char *key, const char *value_in)
fd2
);
ret = fd2;
goto out;
goto complex_out;
}
/* Copy over slot->value_offset bytes */
......@@ -556,7 +556,7 @@ int epic_config_set_string(const char *key, const char *value_in)
"read failed: rc: %d",
ret
);
goto out;
goto complex_out;
}
int ret2 = epic_file_write(fd2, buf, ret);
......@@ -568,7 +568,7 @@ int epic_config_set_string(const char *key, const char *value_in)
"write failed: rc: %d",
ret
);
goto out;
goto complex_out;
}
i -= ret;
}
......@@ -577,7 +577,7 @@ int epic_config_set_string(const char *key, const char *value_in)
ret = epic_file_write(fd2, value, strlen(value));
if (ret < 0) {
LOG_DEBUG("card10.nfg", "write failed: rc: %d", ret);
goto out;
goto complex_out;
}
/* Skip the old value inside the old file */
......@@ -597,7 +597,7 @@ int epic_config_set_string(const char *key, const char *value_in)
"read failed: rc: %d",
ret
);
goto out;
goto complex_out;
}
int ret2 = epic_file_write(fd2, buf, ret);
......@@ -609,7 +609,7 @@ int epic_config_set_string(const char *key, const char *value_in)
"write failed: rc: %d",
ret
);
goto out;
goto complex_out;
}
if (ret < (int)sizeof(buf)) {
......@@ -617,7 +617,7 @@ int epic_config_set_string(const char *key, const char *value_in)
}
}
out:
complex_out:
if (fd1 >= 0) {
epic_file_close(fd1);
}
......@@ -634,6 +634,7 @@ int epic_config_set_string(const char *key, const char *value_in)
}
}
out:
/* Reload config so the new key or the changed value is available */
load_config();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment