diff --git a/epicardium/modules/config.c b/epicardium/modules/config.c index 2e5ca6f2f65eecb360e1f76cb8371ee6a90e4e34..8ff11c270c4e9172f83df89327544e29166c4b8d 100644 --- a/epicardium/modules/config.c +++ b/epicardium/modules/config.c @@ -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();