-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
bus-unit-util: fix bus_wait_for_jobs() debug output #8760
Conversation
We shouldn't print 'errno' if its not initialized properly.
lgtm. |
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.
Oooh, I forgot to press submit. Please see my late review.
@@ -1972,6 +1972,8 @@ int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet, const char* const* extra_ar | |||
if (q < 0 && r == 0) | |||
r = q; | |||
|
|||
errno = 0; /* Reset errno explicitly, so that log_debug_errno() will properly print 'Success' | |||
* for q == 0, instead of whatever is set in errno */ |
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.
Shouldn't we just fix log_internalv_realm
to unconditionally override errno
, even if the value passed as the argument is 0. Seems like a much better solution.
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.
When we originally added the errno patching we went for a "best of both worlds" approach, i.e. that we override errno if an error is specified, but if no error is specified (i.e. 0 is passed as error code) then we use the previously set errno, similar in style how plain printf()
would do it. In retrospect I think we almost never purposefully made use of the second, i.e. the plain printf()
logic, but we multiple times — like in this case the bugfix is about — ran into this case accidentally and introduced a bug. Hence yes, it probably makes sense to switch this over, and consistently ignore the errno
already set and always override it with the error passed in. The only problem I see with that is: I wonder if there might be a case or two lurking somewhere where we actually made use of the "best of both worlds" approach, and if so, if we can detect where... (But then again, even if there is, and we fail to find those cases, maybe that's not all bad, as it's just a few new bugs against probably fixing many more old and future bugs, if you follow what I mean).
So yeah, might be something to do indeed, we just need to be careful.
Quoting systemd#8760 (comment): > When we originally added the errno patching we went for a "best of both > worlds" approach, i.e. that we override errno if an error is specified, but > if no error is specified (i.e. 0 is passed as error code) then we use the > previously set errno, similar in style how plain `printf()` would do it. In > retrospect I think we almost never purposefully made use of the second, > i.e. the plain `printf()` logic, but we multiple times ran into this case > accidentally and introduced a bug. Hence yes, it probably makes sense to > switch this over, and consistently ignore the `errno` already set and always > override it with the error passed in. The only problem I see with that is: I > wonder if there might be a case or two lurking somewhere where we actually > made use of the "best of both worlds" approach, and if so, if we can detect > where... (But then again, even if there is, and we fail to find those cases, > maybe that's not all bad, as it's just a few new bugs against probably fixing > many more old and future bugs, if you follow what I mean). I scanned our codebase, and found some bugs in the value passed to log_*_errno, but no intentional cases of error=0 being passed.
Quoting systemd/systemd#8760 (comment): > When we originally added the errno patching we went for a "best of both > worlds" approach, i.e. that we override errno if an error is specified, but > if no error is specified (i.e. 0 is passed as error code) then we use the > previously set errno, similar in style how plain `printf()` would do it. In > retrospect I think we almost never purposefully made use of the second, > i.e. the plain `printf()` logic, but we multiple times ran into this case > accidentally and introduced a bug. Hence yes, it probably makes sense to > switch this over, and consistently ignore the `errno` already set and always > override it with the error passed in. The only problem I see with that is: I > wonder if there might be a case or two lurking somewhere where we actually > made use of the "best of both worlds" approach, and if so, if we can detect > where... (But then again, even if there is, and we fail to find those cases, > maybe that's not all bad, as it's just a few new bugs against probably fixing > many more old and future bugs, if you follow what I mean). I scanned our codebase, and found some bugs in the value passed to log_*_errno, but no intentional cases of error=0 being passed. (cherry picked from commit b29f648)
We shouldn't print 'errno' if its not initialized properly. (cherry picked from commit d6b8763)
Quoting systemd/systemd#8760 (comment): > When we originally added the errno patching we went for a "best of both > worlds" approach, i.e. that we override errno if an error is specified, but > if no error is specified (i.e. 0 is passed as error code) then we use the > previously set errno, similar in style how plain `printf()` would do it. In > retrospect I think we almost never purposefully made use of the second, > i.e. the plain `printf()` logic, but we multiple times ran into this case > accidentally and introduced a bug. Hence yes, it probably makes sense to > switch this over, and consistently ignore the `errno` already set and always > override it with the error passed in. The only problem I see with that is: I > wonder if there might be a case or two lurking somewhere where we actually > made use of the "best of both worlds" approach, and if so, if we can detect > where... (But then again, even if there is, and we fail to find those cases, > maybe that's not all bad, as it's just a few new bugs against probably fixing > many more old and future bugs, if you follow what I mean). I scanned our codebase, and found some bugs in the value passed to log_*_errno, but no intentional cases of error=0 being passed. (cherry picked from commit b29f6480eca0550ba65d30fbece8dd4d4bfe666d)
Quoting systemd/systemd#8760 (comment): > When we originally added the errno patching we went for a "best of both > worlds" approach, i.e. that we override errno if an error is specified, but > if no error is specified (i.e. 0 is passed as error code) then we use the > previously set errno, similar in style how plain `printf()` would do it. In > retrospect I think we almost never purposefully made use of the second, > i.e. the plain `printf()` logic, but we multiple times ran into this case > accidentally and introduced a bug. Hence yes, it probably makes sense to > switch this over, and consistently ignore the `errno` already set and always > override it with the error passed in. The only problem I see with that is: I > wonder if there might be a case or two lurking somewhere where we actually > made use of the "best of both worlds" approach, and if so, if we can detect > where... (But then again, even if there is, and we fail to find those cases, > maybe that's not all bad, as it's just a few new bugs against probably fixing > many more old and future bugs, if you follow what I mean). I scanned our codebase, and found some bugs in the value passed to log_*_errno, but no intentional cases of error=0 being passed. (cherry picked from commit b29f6480eca0550ba65d30fbece8dd4d4bfe666d)
Quoting systemd/systemd#8760 (comment): > When we originally added the errno patching we went for a "best of both > worlds" approach, i.e. that we override errno if an error is specified, but > if no error is specified (i.e. 0 is passed as error code) then we use the > previously set errno, similar in style how plain `printf()` would do it. In > retrospect I think we almost never purposefully made use of the second, > i.e. the plain `printf()` logic, but we multiple times ran into this case > accidentally and introduced a bug. Hence yes, it probably makes sense to > switch this over, and consistently ignore the `errno` already set and always > override it with the error passed in. The only problem I see with that is: I > wonder if there might be a case or two lurking somewhere where we actually > made use of the "best of both worlds" approach, and if so, if we can detect > where... (But then again, even if there is, and we fail to find those cases, > maybe that's not all bad, as it's just a few new bugs against probably fixing > many more old and future bugs, if you follow what I mean). I scanned our codebase, and found some bugs in the value passed to log_*_errno, but no intentional cases of error=0 being passed.
Quoting systemd/systemd#8760 (comment): > When we originally added the errno patching we went for a "best of both > worlds" approach, i.e. that we override errno if an error is specified, but > if no error is specified (i.e. 0 is passed as error code) then we use the > previously set errno, similar in style how plain `printf()` would do it. In > retrospect I think we almost never purposefully made use of the second, > i.e. the plain `printf()` logic, but we multiple times ran into this case > accidentally and introduced a bug. Hence yes, it probably makes sense to > switch this over, and consistently ignore the `errno` already set and always > override it with the error passed in. The only problem I see with that is: I > wonder if there might be a case or two lurking somewhere where we actually > made use of the "best of both worlds" approach, and if so, if we can detect > where... (But then again, even if there is, and we fail to find those cases, > maybe that's not all bad, as it's just a few new bugs against probably fixing > many more old and future bugs, if you follow what I mean). I scanned our codebase, and found some bugs in the value passed to log_*_errno, but no intentional cases of error=0 being passed.
We shouldn't print 'errno' if its not initialized properly.