summaryrefslogtreecommitdiff
path: root/sysdep/unix
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2020-02-04 10:34:46 +0100
committerMaria Matejka <mq@ucw.cz>2020-02-04 10:34:46 +0100
commitab089f4fb5e1ac762a9c95ed4638e2477803678e (patch)
tree774b50c80a53b3e23a1e8525b5150fac37262646 /sysdep/unix
parent027a3e66f786be8863784aefb043097b41090896 (diff)
Conf: Better error message when reading iproute2 config
Reported by: Martin Weinelt <martin@darmstadt.freifunk.net>
Diffstat (limited to 'sysdep/unix')
-rw-r--r--sysdep/unix/main.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c
index d9d9ad84..5209b9b3 100644
--- a/sysdep/unix/main.c
+++ b/sysdep/unix/main.c
@@ -95,11 +95,15 @@ drop_gid(gid_t gid)
#ifdef PATH_IPROUTE_DIR
static inline void
-add_num_const(char *name, int val)
+add_num_const(char *name, int val, const char *file, const uint line)
{
struct f_val *v = cfg_alloc(sizeof(struct f_val));
*v = (struct f_val) { .type = T_INT, .val.i = val };
- cf_define_symbol(cf_get_symbol(name), SYM_CONSTANT | T_INT, val, v);
+ struct symbol *sym = cf_get_symbol(name);
+ if (sym->class && (sym->scope == conf_this_scope))
+ cf_error("Error reading value for %s from %s:%d: already defined", name, file, line);
+
+ cf_define_symbol(sym, SYM_CONSTANT | T_INT, val, v);
}
/* the code of read_iproute_table() is based on
@@ -119,7 +123,7 @@ read_iproute_table(char *file, char *prefix, int max)
if (!fp)
return;
- while (fgets(buf, sizeof(buf), fp))
+ for (uint line = 1; fgets(buf, sizeof(buf), fp); line++)
{
char *p = buf;
@@ -142,7 +146,7 @@ read_iproute_table(char *file, char *prefix, int max)
if ((*p < 'a' || *p > 'z') && (*p < 'A' || *p > 'Z') && (*p < '0' || *p > '9') && (*p != '_'))
*p = '_';
- add_num_const(namebuf, val);
+ add_num_const(namebuf, val, file, line);
}
fclose(fp);