From 9ad5f93a07be0bf4f645f16dbbf29e2e8cd3b871 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Tue, 23 Aug 2016 13:50:48 +0200 Subject: [PATCH 09/10] lircd: Warn for duplicate remote definitions (#222). --- daemons/lircd.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/daemons/lircd.cpp b/daemons/lircd.cpp index 2dc9029..8fd8336 100644 --- a/daemons/lircd.cpp +++ b/daemons/lircd.cpp @@ -70,6 +70,9 @@ #include #endif +#include +#include + #include "lirc_private.h" #ifdef HAVE_INT_GETGROUPLIST_GROUPS @@ -540,6 +543,22 @@ static int setup_hardware(void) return ret; } +static void check_config_duplicates(const struct ir_remote* head) +{ + std::set names; + const struct ir_remote* ir; + const char* const errmsg = + "Duplicate remotes \"%s\" found, problems ahead"; + + for (ir = head; ir != NULL; ir = ir->next) { + std::string name(ir->name); + if (names.count(name) == 1) + log_warn(errmsg, name.c_str()) + else + names.insert(name); + } +} + void config(void) { @@ -572,6 +591,7 @@ void config(void) } configfile = filename; config_remotes = read_config(fd, configfile); + check_config_duplicates(config_remotes); fclose(fd); if (config_remotes == (void*)-1) { log_error("reading of config file failed"); -- 2.5.5