Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment helpers: function to set environment variable? #149

Closed
aprotyas opened this issue Nov 2, 2021 · 2 comments · Fixed by #150
Closed

Environment helpers: function to set environment variable? #149

aprotyas opened this issue Nov 2, 2021 · 2 comments · Fixed by #150

Comments

@aprotyas
Copy link
Member

aprotyas commented Nov 2, 2021

Feature request

It would be nice to have a way to set environment variables. I have at least one use-case in ros2/domain_bridge#60 (comment).

Feature description

A function that allows setting a named environment variable; essentially a dual of rcpputils::get_env_var.

Implementation considerations

It could be implemented exactly how rcpputils::get_env_var is implemented, by invoking the corresponding rcutils environment helper function.

One approach:

bool set_env_var(const char * env_var, const char * env_value)
{
  if (!rcutils_set_env(env_var, env_value)) {
    std::string err = rcutils_get_error_string().str;
    // Resetting the error state since error string has been extracted
    rcutils_reset_error();
    throw std::runtime_error(err);
  }
  return true;
}
@aprotyas
Copy link
Member Author

aprotyas commented Nov 2, 2021

I've already opened #150 with my own implementation, but if that needs changing, feel free to open a separate PR to close this issue.

@fujitatomoya
Copy link
Collaborator

this makes sense to me, i am good to go with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants