From 947205f0b8e364c1b00abdbdf0966ef3cd21ba85 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Tue, 23 Jan 2024 17:46:00 +0800 Subject: [PATCH] mctpd: attempt a default configuration from /etc/mctpd.conf Rather than requiring a -c FILE argument, allow a default configuration file of /etc/mctpd.conf. We don't error if this is absent, to allow running with the existing defaults. Signed-off-by: Jeremy Kerr --- CHANGELOG.md | 2 +- README.md | 5 +++-- meson.build | 5 +++++ src/mctpd.c | 26 +++++++++++++++++--------- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb7fa71..4f0a8f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). 2. mctpd: Allow recovery of devices reporting a nil UUID for development 3. mctpd: Allow configuring .Connectivity as writable for development 4. mctpd: Add AssignEndpointStatic for static EID allocations -5. mctpd: Add a configuration file facility +5. mctpd: Add a configuration file facility, defaulting to /etc/mctpd.conf. ### Changed diff --git a/README.md b/README.md index 1ec4f8d..0dc2fc7 100644 --- a/README.md +++ b/README.md @@ -68,8 +68,9 @@ configured (ie., interfaces are enabled, and local addresses have been assigned). There are two sample systemd unit files under the conf/ directory, to coordinate the local setup and the supervision of the mctpd process. -`mctpd` can read some basic configuration from a file, if the `-c FILE` argument -is given. An example configuration is in [`conf/mctpd.conf`](conf/mctpd.conf). +`mctpd` can read some basic configuration from a file, by default +`/etc/mctpd.conf`, but other files can be specified with the `-c FILE` argument. +An example configuration is in [`conf/mctpd.conf`](conf/mctpd.conf). The `mctpd` daemon will expose a dbus interface, claiming the bus name `xyz.openbmc_project.MCTP` and object path `/xyz/openbmc_project/mctp`. This diff --git a/meson.build b/meson.build index 872825a..55533d4 100644 --- a/meson.build +++ b/meson.build @@ -29,6 +29,11 @@ conf.set10('MCTPD_WRITABLE_CONNECTIVITY', get_option('unsafe-writable-connectivity'), description: 'Allow writes to the Connectivity member of the au.com.CodeConstruct.MCTP.Endpoint interface on endpoint objects') +conf.set_quoted('MCTPD_CONF_FILE_DEFAULT', + join_paths(get_option('prefix'), get_option('sysconfdir'), 'mctpd.conf'), + description: 'Default configuration file path', +) + config_h = configure_file( output: 'config.h', configuration: conf, diff --git a/src/mctpd.c b/src/mctpd.c index 38ccd8a..1c64607 100644 --- a/src/mctpd.c +++ b/src/mctpd.c @@ -51,6 +51,8 @@ // an arbitrary constant for use with sd_id128_get_machine_app_specific() static const char* mctpd_appid = "67369c05-4b97-4b7e-be72-65cfd8639f10"; +static const char *conf_file_default = MCTPD_CONF_FILE_DEFAULT; + static mctp_eid_t eid_alloc_min = 0x08; static mctp_eid_t eid_alloc_max = 0xfe; @@ -3654,25 +3656,32 @@ static int parse_config_mctp(ctx *ctx, toml_table_t *mctp_tab) static int parse_config(ctx *ctx) { toml_table_t *conf_root, *mctp_tab; + bool conf_file_specified; char errbuf[256] = { 0 }; + const char *filename; toml_datum_t val; FILE *fp; int rc; - if (!ctx->config_filename) - return 0; + conf_file_specified = !!ctx->config_filename; + filename = ctx->config_filename ?: conf_file_default; rc = -1; - fp = fopen(ctx->config_filename, "r"); + fp = fopen(filename, "r"); if (!fp) { - warn("can't open configuration file %s", ctx->config_filename); - return -1; + /* only fatal if a configuration file was specifed by args */ + rc = 0; + if (conf_file_specified) { + warn("can't open configuration file %s", filename); + rc = -1; + } + return rc; } conf_root = toml_parse_file(fp, errbuf, sizeof(errbuf)); if (!conf_root) { - warnx("can't parse configuration file %s: %s", - ctx->config_filename, errbuf); + warnx("can't parse configuration file %s: %s", filename, + errbuf); goto out_close; } @@ -3723,8 +3732,7 @@ int main(int argc, char **argv) rc = parse_config(ctx); if (rc) { - err(EXIT_FAILURE, "Can't load configuration file %s", - ctx->config_filename); + err(EXIT_FAILURE, "Can't read configuration"); } ctx->nl = mctp_nl_new(false);