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

Reading has_realtime fails sometimes #306

Closed
axelschroth opened this issue Jan 13, 2021 · 4 comments
Closed

Reading has_realtime fails sometimes #306

axelschroth opened this issue Jan 13, 2021 · 4 comments
Labels
good first issue Good for newcomers ToDo This issue needs to be implemented

Comments

@axelschroth
Copy link
Contributor

I think this line should be changed from

to

bool has_realtime = false;

I noticed that if I modify some unrelated code without initializing has_realtime, printing has_realtime sometimes outputs a number like e.g. 168 or 66. I suspect the ifstream to do nothing if /sys/kernel/realtime does not exist.
Any thoughts on that strange behavior?

@fmauch fmauch added good first issue Good for newcomers ToDo This issue needs to be implemented labels Jan 14, 2021
@fmauch
Copy link
Contributor

fmauch commented Jan 14, 2021

Using the stream's fail() or good() functions might be reasonable. I've wanted to refactor this code for quite some time to also allow setting a higher thread priority if no realtime capability is found.

Initializing the variable and checking the ifstream might be a good first start to address the issue you mentioned.

Something like

std::ifstream realtime_file("/sys/kernel/realtime", std::ios::in);
bool has_realtime = false;
if (realtime_file.good())
{
  realtime_file >> has_realtime;
}

@axelschroth could you maybe test whether this works for you?

@axelschroth
Copy link
Contributor Author

Following works for me using is_open():

std::ifstream realtime_file("/sys/kernel/realtime", std::ios::in);
bool has_realtime = false;
if (realtime_file.is_open())
{
  realtime_file >> has_realtime;
}

axelschroth added a commit to isys-vision/Universal_Robots_ROS_Driver that referenced this issue Jan 19, 2021
Reading this from system may end up in undefined behavior.
(UniversalRobots#306)
axelschroth added a commit to isys-vision/Universal_Robots_ROS_Driver that referenced this issue Jan 19, 2021
Reading this from system may end up in undefined behavior. (UniversalRobots#306)
@axelschroth
Copy link
Contributor Author

Sorry for the confusion above. I created a PR.

fmauch pushed a commit that referenced this issue May 21, 2021
Reading this from system may end up in undefined behavior. (#306)
@fmauch
Copy link
Contributor

fmauch commented May 31, 2021

This should have been fixed with #311 -> closing this issue.

@fmauch fmauch closed this as completed May 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers ToDo This issue needs to be implemented
Projects
None yet
Development

No branches or pull requests

2 participants