-
Notifications
You must be signed in to change notification settings - Fork 434
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
use rcutils_get_env instead of getenv() in node_options.cpp #987
Conversation
Signed-off-by: Suyash458 <suyash.behera458@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@suyash458 rcutils_get_env
is supported on Windows as well, why not just using? There's a TODO right above that you'd be resolving.
Whoops, missed that one. Thanks for pointing out! |
Signed-off-by: Suyash458 <suyash.behera458@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I think this is an improvement, even though neither new nor old implementation are thread-safe.
There's been some discussion in ros2/rcutils#30, if you're interested in following up @suyash458. For the moment I'd be inclined to merge after CI passes. @clalancette @ivanpauno @wjwwood thoughts?
So I agree with switching to the platform-agnostic However, there is a serious bug in this patch (which I can't comment on directly, since the lines are below the ones that are changed). In the error cases, we should definitely not try to free the buffer on Windows, as that will cause this to crash (in the best case). Basically anywhere it says:
in |
Is that true? I think the old method was thread-safe. On windows it gives you a copy (reason we have to free it after) and on Linux it is thread-safe so long as no one changes the environment variable ( On Linux it is fine. So, unfortunately I think this pr takes a step backward in terms of thread-safety. |
@wjwwood should this wait till |
Should I go ahead remove that check as a part of this PR? |
Unfortunately I think that might be the case. I'd like to hear from the other reviewers first to see what they think. I think The other option might be to make it thread-local storage, that way ensuring it is not called more than once in the same thread before using would be safe, but that also requires allocation on new threads (implicitly), so it may not be better than just always returning a copy, other than the convenience of not needing to deallocate the returned string. |
Yeah, I think that's the way we are going to have to go here. It's unfortunate that it blocks this PR, but otherwise we may run into more threading problems. |
As long as the global process environment is left unchanged as you say. No access to the environment will ever be thread-safe, we can only change the extent of the critical section.
That is correct, which makes me wonder about the different implementations. As it is,
So I fully agree with this, on all platforms. Maybe you want to take a stab at it @suyash458 ? |
@hidmic Sure thing, that would close ros2/rcutils#30 right? |
Exactly. We also have ros2/rcutils#182 currently open, but I think we should just close that one out and make a new one that changes the contract to require the caller to free the memory. It still won't be completely thread-safe (as the environment variable could be changing while we are copying it out), but for most practical purposes it will be pretty good. |
If we're going to change the contract, why not just using getenv_s directly. If we don't want to change the contract, why not just using getenv in windows too and ignore the compiler warning (the warning is just showed because windows recommends using
I would prefer a solution that's actually thread-safe (at least, for reading the environment). If not, we can get later weird issues. |
So would I, but I don't actually see a way forward that accomplishes that. If we switch to |
I think that I misread this comment before. If this is referring to avoid the global variable in windows using |
There is one reason to do it, and that's so that we can support embedded platforms that don't supply
Yeah, agreed with this. |
I think |
FWIW I thought about
Hmm I get the concept, but I fail to see why would you do that for any C library or POSIX interface. You'd add (dummy?) support for it to your bare metal platform or RTOS of choice instead. Even basic RedHat's newlib has some stubs you can fill up. |
Didn't know that, thanks for pointing it out. |
Well, I think the answer is in that stackoverflow report/Annex K. Namely, that glibc doesn't actually supply |
@suyash458 have you been able to find the time to push this one and ros2/rcutils#30 forward? |
@hidmic not yet unfortunately, I'll work on this during the weekend. |
@hidmic I've submitted a PR to |
closing as this doesn't apply anymore ( |
RHEL is currently using a Python version older than 3.8, which is when the `missing_ok` argument was added to Path.unlink. For better compatibility, we can just catch and ignore the FileNotFoundError. Signed-off-by: Scott K Logan <logans@cottsay.net>
use
rcutils_get_env
instead ofgetenv()
innode_options.cpp
fixes ros2/ros2#856