Repository navigation
Cleanup error handling #2471
Description
Activity
@2xsec, this might be something you might be interested in doing. Probably a good idea to either do a commit for each function or for each file.
- addedFeatureNew feature, not a bugNew feature, not a bugEasyGood for new contributorsGood for new contributors
on Jul 16, 2018 @brauner, Of course. I'll check it.
@2xsec, no pressure just in case you're interested. You might also consider jumping into our irc channel #lxc-dev on Freenode. But of course, that's completely optional too. :)
@brauner This is no pressure for me.:) Please recommend a good tool for irc.:)
Hm, we usually either use
irssiorweechat. But there are graphical or browser based irc clients as well. It depends on whether you want to be connected constantly or only on demand. Most of us have a persistent irc session running in tmux on a remote server so that we can simply attach to it every day and see what we missed and also have logs of all interactions.
Personally, I use ZNC as irc bouncer but that is probably not needed.- added a commit that references this issue
on Jul 21, 2018 Updated my intial comment a bit in response to #2551. I think this part might benefit from a few examples in the coding style doc, or some more situation distinctions.
I don't remember saying that ;-). Setting
errnowas for functions where the return type conflicts with the error codes (eg pointers.). Weren't you entertaining the idea of usingPTR_ERR()? That one I'm not so fond of ;-).No,
PTR_ERR()and friends should stay restricted to our kernel work. ;) We agreed on that on irc a while back.errnois what we have for the userspace part of our work.I'll let @Blub spearhead this work and its direction. I'm just going to give snide comments from time to time. ;)
@brauner Thanks. :)
I'll close #2551 then and let you boys at it.
@brauner do we still need this issue or did you accidentally clean that all up by now?
We have a bunch of functions throughout with inconsistent error return values, mixing
-1with and without a validerrnowith returning negative errno codes. Eg. some confile.c functions can return-EINVALas well as just-1.We should clean these up to follow the coding style[1] document.
In other words: in our own functions, if not in conflict with a successful return value,
alwaysif the type of error makes a difference to the caller, try to return a negative error code (iow, if the error was triggered by something settingerrno, simplyreturn -errno;), otherwise actually seterrnoif needed. (Eg. when a non-NULL pointer is to be returned on success, returnNULLafter settingerrno).[1] https://github.com/lxc/lxc/blob/master/CODING_STYLE.md#return-error-codes
EDIT: I updated the above a bit as it doesn't actually make sense to force such values to be used everywhere. The thing to look out for is whether the type of error actually makes a difference to the caller. The coding style doc actually says to use them if the function can fail in a "non-binary way". In cases where the caller cannot react to the exact error the best thing to do is to report as much diagnostic info as available at the time the error happens and then just return
-1.