From patchwork Thu Mar 4 12:23:21 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Seither X-Patchwork-Id: 31 Return-Path: Received: from devzero.de (devzero.de [85.214.76.202]) by open-mesh.net (Postfix) with ESMTP id A70AF154207 for ; Thu, 4 Mar 2010 13:47:10 +0100 (CET) Received: from [192.168.178.47] (p5DCF0601.dip0.t-ipconnect.de [93.207.6.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by devzero.de (Postfix) with ESMTPSA id 2810095400D for ; Thu, 4 Mar 2010 12:23:22 +0000 (UTC) Message-ID: <4B8FA639.5000502@tiwoc.de> Date: Thu, 04 Mar 2010 13:23:21 +0100 From: Daniel Seither User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: The list for a Better Approach To Mobile Ad-hoc Networking X-Enigmail-Version: 0.95.7 Subject: [B.A.T.M.A.N.] [PATCH] batctl: avoid parsing bat-hosts multiple times X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.11 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Mar 2010 12:47:10 -0000 Currently, running batctl from the home directory leads to warnings ("Warning - mac already known") if ~/bat-hosts exists. This is caused by batctl parsing both "~/bat-hosts" and "bat-hosts" which happen to be the same file when the working directory is ~ This patch adds duplicate file name detection to bat_hosts_init() to avoid these warnings. Signed-off-by: Daniel Seither Index: batctl/bat-hosts.c =================================================================== --- batctl/bat-hosts.c (revision 1579) +++ batctl/bat-hosts.c (working copy) @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -144,9 +145,11 @@ void bat_hosts_init(void) { - unsigned int i; + unsigned int i, j, parse; char confdir[CONF_DIR_LEN]; char *homedir; + size_t locations = sizeof(bat_hosts_path) / sizeof(char *); + char normalized[locations][PATH_MAX]; host_hash = hash_new(64, compare_mac, choose_mac); @@ -157,7 +160,7 @@ homedir = getenv("HOME"); - for (i = 0; i < sizeof(bat_hosts_path) / sizeof(char *); i++) { + for (i = 0; i < locations; i++) { strcpy(confdir, ""); if (strlen(bat_hosts_path[i]) >= 2 @@ -169,8 +172,22 @@ strncpy(confdir, bat_hosts_path[i], CONF_DIR_LEN); confdir[CONF_DIR_LEN - 1] = '\0'; } - - parse_hosts_file(&host_hash, confdir); + + if (realpath(confdir, normalized[i]) == NULL) { + normalized[i][0] = '\0'; + continue; + } + + /* check for duplicates: don't parse the same file twice */ + parse = 1; + for (j = 0; j < i; j++) + if (strncmp(normalized[i], normalized[j], CONF_DIR_LEN) == 0) { + parse = 0; + break; + } + + if (parse && (normalized[i][0] != '\0')) + parse_hosts_file(&host_hash, normalized[i]); } }