Skip to content

Commit

Permalink
Merge pull request #5543 from garlick/broker_attr_cleanup
Browse files Browse the repository at this point in the history
broker: cleanup up attribute initialization code
  • Loading branch information
mergify[bot] authored Nov 11, 2023
2 parents 8b2bdfb + 5b329ba commit 865647e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 36 deletions.
2 changes: 1 addition & 1 deletion doc/man1/flux-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ The following configuration keys may be printed with

**shell_initrc**
The initrc script path used by :man1:`flux-shell`, unless overridden by
setting the ``conf.shell_pluginpath`` broker attribute.
setting the ``conf.shell_initrc`` broker attribute.

**jobtap_pluginpath**
The search path used by the job manager to locate
Expand Down
2 changes: 1 addition & 1 deletion doc/man7/flux-broker-attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ broker.rc1_path [Updates: C]
The path to the broker's rc1 script. Default: ``${prefix}/etc/flux/rc1``.

broker.rc3_path [Updates: C]
The path to the broker's rc3 script. Default: ``${prefix}/etc/flux/rc1``.
The path to the broker's rc3 script. Default: ``${prefix}/etc/flux/rc3``.

broker.exit-restart [Updates: C, R]
A numeric exit code that the broker uses to indicate that it should not be
Expand Down
45 changes: 11 additions & 34 deletions src/broker/broker.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,35 +536,6 @@ int main (int argc, char *argv[])
return ctx.exit_rc;
}

struct attrmap {
const char *env;
const char *attr;
uint8_t required:1;
uint8_t sanitize:1;
};

static struct attrmap attrmap[] = {
{ "FLUX_URI", "parent-uri", 0, 1 },
{ "FLUX_KVS_NAMESPACE", "parent-kvs-namespace", 0, 1 },
{ NULL, NULL, 0, 0 },
};

static void init_attrs_from_environment (attr_t *attrs)
{
struct attrmap *m;
const char *val;

for (m = &attrmap[0]; m->env != NULL; m++) {
val = getenv (m->env);
if (!val && m->required)
log_msg_exit ("required environment variable %s is not set", m->env);
if (attr_add (attrs, m->attr, val, ATTR_IMMUTABLE) < 0)
log_err_exit ("attr_add %s", m->attr);
if (m->sanitize)
unsetenv (m->env);
}
}

static void init_attrs_broker_pid (attr_t *attrs, pid_t pid)
{
char *attrname = "broker.pid";
Expand Down Expand Up @@ -618,12 +589,18 @@ static void init_attrs_starttime (attr_t *attrs, double starttime)

static void init_attrs (attr_t *attrs, pid_t pid, struct flux_msg_cred *cred)
{
/* Initialize config attrs from environment set up by flux(1)
*/
init_attrs_from_environment (attrs);
const char *val;

val = getenv ("FLUX_URI");
if (attr_add (attrs, "parent-uri", val, ATTR_IMMUTABLE) < 0)
log_err_exit ("setattr parent-uri");
unsetenv ("FLUX_URI");

val = getenv ("FLUX_KVS_NAMESPACE");
if (attr_add (attrs, "parent-kvs-namespace", val, ATTR_IMMUTABLE) < 0)
log_err_exit ("setattr parent-kvs-namespace");
unsetenv ("FLUX_KVS_NAMESPACE");

/* Initialize other miscellaneous attrs
*/
init_attrs_broker_pid (attrs, pid);
init_attrs_rc_paths (attrs);
init_attrs_shell_paths (attrs);
Expand Down

0 comments on commit 865647e

Please sign in to comment.