basic/log: assert that 0 is not passed as errno, except in test code
Let's assert if we ever happen to pass 0 to one of the log functions. With the preceding commit to return -EIO from log_*(), passing 0 wouldn't affect the return value any more, but it is still most likely an error. The unit test code is an exception: we fairly often pass the return value to print it, before checking what it is. So let's assert that we're not passing 0 in non-test code. As with the previous check for %m, this is only done in developer mode. We are depending on external code setting errno correctly for us, which might not always be true, and which we can't test, so we shouldn't assert, but just handle this gracefully. I did a bunch of greps to try to figure out if there are any places where we're passing 0 on purpose, and couldn't find any. The one place that failed in tests is adjusted. About "zerook" in the name: I wanted the suffix to be unambiguous. It's a single "word" because each of the words in log_full_errno is also meaningful, and having one term use two words would be confusing.
This commit is contained in:
@@ -306,7 +306,8 @@ int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet, const char* const* extra_ar
|
||||
if (q < 0 && r == 0)
|
||||
r = q;
|
||||
|
||||
log_debug_errno(q, "Got result %s/%m for job %s", d->result, d->name);
|
||||
log_full_errno_zerook(LOG_DEBUG, q,
|
||||
"Got result %s/%m for job %s", d->result, d->name);
|
||||
}
|
||||
|
||||
d->name = mfree(d->name);
|
||||
|
||||
Reference in New Issue
Block a user