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
No related branches found
No related tags found
No related merge requests found
...@@ -130,12 +130,12 @@ static void add_config_pair( ...@@ -130,12 +130,12 @@ static void add_config_pair(
static void trim(char *str) static void trim(char *str)
{ {
char *start = str; char *start = str;
while (*start && !isgraph((int)*start)) while (*start && !isgraph(*start))
start++; start++;
if (strlen(start) > 0) { if (strlen(start) > 0) {
char *end = start + strlen(start) - 1; char *end = start + strlen(start) - 1;
while (*end && !isgraph((int)*end)) while (*end && !isgraph(*end))
end--; end--;
end[1] = 0; end[1] = 0;
} }
...@@ -388,7 +388,6 @@ bool config_get_boolean_with_default(const char *key, bool default_value) ...@@ -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) int epic_config_set_string(const char *key, const char *value_in)
{ {
char value[MAX_LINE_LENGTH + 1]; char value[MAX_LINE_LENGTH + 1];
...@@ -481,10 +480,10 @@ int epic_config_set_string(const char *key, const char *value_in) ...@@ -481,10 +480,10 @@ int epic_config_set_string(const char *key, const char *value_in)
); );
} }
if (write_ret < 0) { if (write_ret < 0) {
return write_ret; ret = write_ret;
} }
if (ret < 0) { if (ret < 0) {
return ret; goto out;
} }
if (write_ret < (int)strlen(buf)) { if (write_ret < (int)strlen(buf)) {
LOG_DEBUG( LOG_DEBUG(
...@@ -493,7 +492,8 @@ int epic_config_set_string(const char *key, const char *value_in) ...@@ -493,7 +492,8 @@ int epic_config_set_string(const char *key, const char *value_in)
write_ret, write_ret,
strlen(buf) strlen(buf)
); );
return -EIO; ret = -EIO;
goto out;
} }
} else { } else {
/* Complex case: The value is already somewhere in the file. /* 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) ...@@ -511,7 +511,7 @@ int epic_config_set_string(const char *key, const char *value_in)
); );
if (nread == 0) { if (nread == 0) {
LOG_DEBUG("card10.cfg", "could not read old value", ); LOG_DEBUG("card10.cfg", "could not read old value", );
goto out; goto complex_out;
} }
char *end = buf; char *end = buf;
...@@ -530,7 +530,7 @@ int epic_config_set_string(const char *key, const char *value_in) ...@@ -530,7 +530,7 @@ int epic_config_set_string(const char *key, const char *value_in)
fd1 fd1
); );
ret = fd1; ret = fd1;
goto out; goto complex_out;
} }
fd2 = epic_file_open("card10.nfg", "w"); fd2 = epic_file_open("card10.nfg", "w");
...@@ -542,7 +542,7 @@ int epic_config_set_string(const char *key, const char *value_in) ...@@ -542,7 +542,7 @@ int epic_config_set_string(const char *key, const char *value_in)
fd2 fd2
); );
ret = fd2; ret = fd2;
goto out; goto complex_out;
} }
/* Copy over slot->value_offset bytes */ /* Copy over slot->value_offset bytes */
...@@ -556,7 +556,7 @@ int epic_config_set_string(const char *key, const char *value_in) ...@@ -556,7 +556,7 @@ int epic_config_set_string(const char *key, const char *value_in)
"read failed: rc: %d", "read failed: rc: %d",
ret ret
); );
goto out; goto complex_out;
} }
int ret2 = epic_file_write(fd2, buf, ret); int ret2 = epic_file_write(fd2, buf, ret);
...@@ -568,7 +568,7 @@ int epic_config_set_string(const char *key, const char *value_in) ...@@ -568,7 +568,7 @@ int epic_config_set_string(const char *key, const char *value_in)
"write failed: rc: %d", "write failed: rc: %d",
ret ret
); );
goto out; goto complex_out;
} }
i -= ret; i -= ret;
} }
...@@ -577,7 +577,7 @@ int epic_config_set_string(const char *key, const char *value_in) ...@@ -577,7 +577,7 @@ int epic_config_set_string(const char *key, const char *value_in)
ret = epic_file_write(fd2, value, strlen(value)); ret = epic_file_write(fd2, value, strlen(value));
if (ret < 0) { if (ret < 0) {
LOG_DEBUG("card10.nfg", "write failed: rc: %d", ret); LOG_DEBUG("card10.nfg", "write failed: rc: %d", ret);
goto out; goto complex_out;
} }
/* Skip the old value inside the old file */ /* Skip the old value inside the old file */
...@@ -597,7 +597,7 @@ int epic_config_set_string(const char *key, const char *value_in) ...@@ -597,7 +597,7 @@ int epic_config_set_string(const char *key, const char *value_in)
"read failed: rc: %d", "read failed: rc: %d",
ret ret
); );
goto out; goto complex_out;
} }
int ret2 = epic_file_write(fd2, buf, ret); int ret2 = epic_file_write(fd2, buf, ret);
...@@ -609,7 +609,7 @@ int epic_config_set_string(const char *key, const char *value_in) ...@@ -609,7 +609,7 @@ int epic_config_set_string(const char *key, const char *value_in)
"write failed: rc: %d", "write failed: rc: %d",
ret ret
); );
goto out; goto complex_out;
} }
if (ret < (int)sizeof(buf)) { if (ret < (int)sizeof(buf)) {
...@@ -617,7 +617,7 @@ int epic_config_set_string(const char *key, const char *value_in) ...@@ -617,7 +617,7 @@ int epic_config_set_string(const char *key, const char *value_in)
} }
} }
out: complex_out:
if (fd1 >= 0) { if (fd1 >= 0) {
epic_file_close(fd1); epic_file_close(fd1);
} }
...@@ -634,6 +634,7 @@ int epic_config_set_string(const char *key, const char *value_in) ...@@ -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 */ /* Reload config so the new key or the changed value is available */
load_config(); load_config();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment