Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp42809lfe; Fri, 15 Apr 2022 18:32:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3r3YH2v3ksZ8CyCAr0+c86jJM4SSosHTwDHn+U4f1YTkf0x25Spx8mQxAEAj1sPyJdc0q X-Received: by 2002:a62:3083:0:b0:505:f7ac:c4a6 with SMTP id w125-20020a623083000000b00505f7acc4a6mr1728597pfw.66.1650072757536; Fri, 15 Apr 2022 18:32:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650072757; cv=none; d=google.com; s=arc-20160816; b=0GFQlpcy4tlTHhcmVGRiPfogMRgTyFMfbKdE7vgvKtuFjhqyhJ4Ts1F4I4CUTVCzyp 2ETwlG7/Qu6xolRVhlMbrG/GPalTb4dR5Eh8i2HhagZ3Uk/ETIEcNZ9EJiCKMbMiABik hDTgGf7gPK9I2vbQTpbMIUQ2VlaXSUaMaedoELzd4ifrK/bQBXixSXpa9cUSiSBifWpC mURdaWuwmEE3WnkXYc5cG6VTZrjIDpaABRcKrggvLjgjNbVR/CzHQK3uOoeWtTBPV4/t Lj38pjYwUX7hkP/RPnk8mmMVJBE90nk3YFccefxm2YHS4gb2wf066VwrgP+IP+I6sA5M JX7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=GHAnsbP6AFrJg0mQehKfPLFs1ej/e9xkPrmiHnU7ue4=; b=hm/5PZWbZvC6hye3coyo5Ar+ZikrFTccwavTrZIlNjSXt6xpqrWal466GqAF0NE/rb yWVxawDVkVlbUyR/pJyeVPQShBef9NBKxp41gMZPSVOYUNUzUfwjEhluZ/kmEHleDY0X Je6NRsG86wF1dlQJzCRh3lwGiMJjo+f5Zs1IgqiWpdCXjgBgXjaPhAhAPFYJimfjFXTQ w2Wt4hxjT54codO7c2g5gxUG6PcqSYtya49XKomdJg4deo4WartvfCmmp+C/9Cglcdj5 uIzWVZwE7KlUmxz7R9rIev8DjCY4yNPKxoWDMJGx+f0eiJWVWJ7XdetKqS6z9dari/sO MhwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RgXTxhgX; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a6-20020a056a000c8600b004fa895878afsi3473206pfv.254.2022.04.15.18.32.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 18:32:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RgXTxhgX; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4075E50062; Fri, 15 Apr 2022 17:59:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232367AbiDOWdY (ORCPT + 99 others); Fri, 15 Apr 2022 18:33:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231630AbiDOWdY (ORCPT ); Fri, 15 Apr 2022 18:33:24 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D71B48119F for ; Fri, 15 Apr 2022 15:30:52 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id s137so8783925pgs.5 for ; Fri, 15 Apr 2022 15:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=GHAnsbP6AFrJg0mQehKfPLFs1ej/e9xkPrmiHnU7ue4=; b=RgXTxhgXIi5wf61VjoT2Gl1BL8mWPQY1Iyk+xHXH19UL4RZ63O6NVbN2nT5KWaavNM 77Sb9Td8iETdooTNfbCLMwwGtMsjRmg41kg/0PV4jqhVdmp4IWhZK4UDo+Pt8nLzD/uh 0re9+lHgeyCpGA+C8pBCM0INW5V0eAQKxMZZNak1seDZ5F5MkHSSKn5tJNch9EVjcZBI S9FNNWqgM29hFtaG2qH5y22lF//9Yk1jXKOP4+z1INbRUWnh2D0cLa8QQzBZ+1ZIptEY b46/aGoair5UGvAdI/mCloaYrufr2LfMmXn9E8whjUdWLxeZBOghFvfQ1eIAwL6jy3dO 7n6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GHAnsbP6AFrJg0mQehKfPLFs1ej/e9xkPrmiHnU7ue4=; b=z9QOal6jbZFRVnntJZ6zwTQTt8izJwuuTJDs1dFQpvhg2+i68WnHdUPOLQzVdirGNY Ot+AH+WvJumfqwzOVrZFEddXFOOvgWhpmeEixnLDoIpLMUKsZsDfSNc0CZhyiE0vn4Pv QRVLl/JQGC6fT73oWQPgW/o4M0EgI35UdIPQnpq5vn/AEdnTczB2qR0IFnWwfvLmZtIh 4N91PyZn5EknqckivcmkGTFtvotuqZgKyj/7EZKgmTAaOM3OnVUgNjiSK9uG8ynlEmi5 Sy0BeAW2ZDlbZc+a0O6h5aZ6vcHoFsCOqfQH0dBbGXF2bPrNw1RdkYFHI0Kdh6XizWsN dy4A== X-Gm-Message-State: AOAM530rTs3gXSqsGycs+qJh45zozfEI2eK22FAgHa80kqpgNMwIc7Dc /ricixLIYZSskFR8awtB4YpyvZPxdx8= X-Received: by 2002:a63:151e:0:b0:39d:7613:9183 with SMTP id v30-20020a63151e000000b0039d76139183mr871224pgl.52.1650061851969; Fri, 15 Apr 2022 15:30:51 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id t38-20020a634626000000b0039cc30b7c93sm5132594pga.82.2022.04.15.15.30.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 15:30:51 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v2 BlueZ 2/3] main: Add support for CONFIGURATION_DIRECTORY environment variable Date: Fri, 15 Apr 2022 15:30:48 -0700 Message-Id: <20220415223049.1155838-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220415223049.1155838-1-luiz.dentz@gmail.com> References: <20220415223049.1155838-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz When running as a systemd service the CONFIGURATION_DIRECTORY environment variable maybe set: https://www.freedesktop.org/software/systemd/man/systemd.exec.html --- src/main.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/main.c b/src/main.c index a448320c1..528956643 100644 --- a/src/main.c +++ b/src/main.c @@ -64,7 +64,7 @@ struct btd_opts btd_opts; static GKeyFile *main_conf; -static char *main_conf_file_path; +static char main_conf_file_path[PATH_MAX]; static const char *supported_options[] = { "Name", @@ -175,18 +175,43 @@ GKeyFile *btd_get_main_conf(void) return main_conf; } -static GKeyFile *load_config(const char *file) +static GKeyFile *load_config(const char *name) { GError *err = NULL; GKeyFile *keyfile; + int len; + + if (!name) + return NULL; + + if (name) + snprintf(main_conf_file_path, PATH_MAX, "%s", name); + else { + const char *configdir = getenv("CONFIGURATION_DIRECTORY"); + + /* Check if running as service */ + if (configdir) { + /* Check if there multiple paths given */ + len = strstr(configdir, ":") - configdir; + if (len < 0) + len = strlen(configdir); + } else { + configdir = CONFIGDIR; + len = strlen(configdir); + } + + snprintf(main_conf_file_path, PATH_MAX, "%*s/main.conf", len, + configdir); + } keyfile = g_key_file_new(); g_key_file_set_list_separator(keyfile, ','); - if (!g_key_file_load_from_file(keyfile, file, 0, &err)) { + if (!g_key_file_load_from_file(keyfile, main_conf_file_path, 0, &err)) { if (!g_error_matches(err, G_FILE_ERROR, G_FILE_ERROR_NOENT)) - error("Parsing %s failed: %s", file, err->message); + error("Parsing %s failed: %s", main_conf_file_path, + err->message); g_error_free(err); g_key_file_free(keyfile); return NULL; @@ -1194,12 +1219,7 @@ int main(int argc, char *argv[]) mainloop_sd_notify("STATUS=Starting up"); - if (option_configfile) - main_conf_file_path = option_configfile; - else - main_conf_file_path = CONFIGDIR "/main.conf"; - - main_conf = load_config(main_conf_file_path); + main_conf = load_config(option_configfile ? : "main.conf"); parse_config(main_conf); -- 2.35.1