[systemd-devel] [PATCH] log: add log_errno() helper

David Herrmann dh.herrmann at gmail.com
Fri Nov 15 06:26:54 PST 2013


Hi

On Fri, Nov 15, 2013 at 2:33 PM, Zbigniew Jędrzejewski-Szmek
<zbyszek at in.waw.pl> wrote:
> On Fri, Nov 15, 2013 at 11:22:59AM +0100, David Herrmann wrote:
>> Syscalls may fail for a lot of reasons, but most times these errors are
>> unexpected (we cannot recover). Especially when dealing with device nodes
>> that can be revoked asynchronously, a series of syscalls may start failing
>> at any point. Normally, we can silently ignore errors and just bail out,
>> but for debugging purposes log messages are quite helpful.
> I'm not sold of the idea of completely generic message. If I'm sitting
> in front of a failed boot, seeing only "Syscall failed unexpectedly: no such
> file or directory", I'm going to be pretty frustrated.
> Maybe there should be a custom message argument like
> "ioctl AUTOFS_DEV_IOCTL_VERSION". This isn't going to increase the
> footprint too much, but will help undertand bug reprots.
> Or if you thyink it's too annoying to write, than maybe just
> print the file name and line automatically.

file-name and line is actually what I wanted (does log_meta() suppress
these?). Custom error-messages don't really make much sense.

For example: Assume you have a function to open an input device. The
function itself has to run a bunch of syscalls:
 - open() (open device node)
 - ioctl() (get device bits, like 10 EVIOC* ioctls)
 - write() (to initialize LED values)
These are all mostly straightforward and shouldn't fail if the device
is valid. However, they *can* fail for various reasons (daemon not
running with enough privileges, device being unplugged during
operation, ...) but it's almost impossible to detect these properly.
So we want debug/error messages.

If we now add a custom log_error() message for each of these calls,
they will be something like "EVIOCGABS failed: %m". To a user this is
as helpful as "syscall failed in $file:$line:$func". So I thought, we
can avoid cluttering .text with useless error-messages and just print
$file:$line:$func and %m.

Does that make sense?

Note that this obviously is only for developer error-messages. For
functions like open() it makes sense to handle it separately. A
message like "cannot open /dev/$sth: Access denied" even helps users,
not only developers. The log_errno() is really intended for stuff like
custom ioctls/etc.

Thanks
David


More information about the systemd-devel mailing list