Skip to content

Commit

Permalink
mctpd: attempt a default configuration from /etc/mctpd.conf
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jk-ozlabs committed Feb 6, 2024
1 parent 41dd75d commit cb62ff2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, byt 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
Expand Down
5 changes: 5 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 13 additions & 9 deletions src/mctpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -3654,25 +3656,28 @@ 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;
warn("can't open configuration file %s", filename);
/* only fatal if no configuration file was specified */
return conf_file_specified ? -1 : 0;
}

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;
}

Expand Down Expand Up @@ -3723,8 +3728,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);
Expand Down

0 comments on commit cb62ff2

Please sign in to comment.