[systemd-devel] [PATCH] socket-proxyd: Unchecked return value from library

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Sep 19 05:11:39 PDT 2014


On 19/09/14 09:05, David Herrmann wrote:
>> -        fcntl(buffer[0], F_SETPIPE_SZ, BUFFER_SIZE);
>> +        r = fcntl(buffer[0], F_SETPIPE_SZ, BUFFER_SIZE);
>> +        if (r < 0) {
>> +                log_error("Failed to set pipe buffer size: %m");
>> +                return -errno;
>> +        }
> 
> I don't think that's right. Ignoring the return value of that fcntl is
> just fine.

An idiom I've found to be useful in cases like this is something like

r = whatever();
if (r < 0) {
    /* ignore failure because [short justification here] */
}

which avoids compiler warnings for functions marked with
__attribute__(warn_unused_result) (and hopefully also this Coverity
warning), while making the intention clear.

    S



More information about the systemd-devel mailing list