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

avoid strerror #2794

Open
markus2330 opened this issue Jun 18, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@markus2330
Copy link
Contributor

commented Jun 18, 2019

From #2686:

We should not recommend to call strerror(errno) as it is not thread-safe. strerror_r should be used instead. It would be better if we can embed the strerror in a generic way, so that not every caller needs to worry about that.

@Piankero wrote:

Always allocating and freeing memory just for an error message seems very cumbersome.

Exactly, this is why our error system should take care of this. Then we only implement it once, and everyone can safely report errno.

So why now introduce thread safety just for error messages?

Thread safety is always supported with Elektra. The current uses of strerror are simply a bug.

It is okay if your implementation uses strerror for now (if you find the other strerror APIs too difficult). But it is important that we have a single place where we can fix the problem.

@markus2330

This comment has been minimized.

Copy link
Contributor Author

commented Jun 18, 2019

Btw. this issue is already listed in #2572, so it is not new. And if you use mustache for the template, it should be very easy to fix strerror at the one place.

This issue is also related to #2697.

@kodebach

This comment has been minimized.

Copy link
Contributor

commented Jun 18, 2019

Always allocating and freeing memory just for an error message seems very cumbersome.

I don't think that is needed. The following is safe to use and message longer than 2048 characters (if they even exist anywhere) wouldn't be read by the user anyway, so IMO its fine to truncate them. A smaller limit would probably, be fine as well.

char buf[2048];
strerror_r (errno, buf, sizeof(buf));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.