Re: [exim] Exim 4.89 compile warning on Ubuntu 14.04

Top Pagina
Delete this message
Reply to this message
Auteur: Nigel Metheringham
Datum:  
Aan: exim-users
Onderwerp: Re: [exim] Exim 4.89 compile warning on Ubuntu 14.04
There appears to be some (in fact a lot of) discussion around this in
this bug against gcc
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425


Although it may be argued that the issue here is with the C library that
has labelled write as having a result that is non-ignorable.

Of the various things discussed there, maybe moving to using this form
of code would be best in terms of explanation and suppressing the warning:-

    if (foo()) {
      /* The return value of foo can be ignored here because X and Y.  */
    }


Or we can leave as is in 4.89 and live with a spurious warning.

    Nigel.

> Phil Pennock <mailto:pdp@exim.org>
> 8 March 2017 at 20:01
> On 2017-03-08 at 09:05 +0000, Michael J. Tubby B.Sc. MIET wrote:
>> exim.c: In function ‘usr1_handler’:
>> exim.c:235:1: warning: ignoring return value of ‘write’, declared
>> with attribute warn_unused_result [-Wunused-result]
>> (void)write(fd, process_info, process_info_len);
>> ^
>
>> and believing that cleanliness is next to godliness have fixed the
>> warning by removing the (void) cast over the write function and
>> assigning the return value to variable 'sz'.
>
> No, I object to this change.
>
> Assigning to a variable which is then unused is wrong, and a sign of a
> bug. Decent languages treat this as a compile error (Golang). Return
> values should either be handled _properly_ or honestly and openly
> discarded. In that handler, the decision was made to discard.
>
> The return value is being explicitly discarded via explicit `(void)`
> cast of the result. This is as explicit as it gets that we are
> knowingly and deliberately not heeding the result.
>
> The compiler treating this as a warning is a compiler bug. I got the
> same warning on an Ubuntu box. I ignore it. `-Wunused-result` should
> be skipping complaining about explicit void casts. Making the code
> deceptive by assigning to a variable is the wrong thing to do here.
>
> -Phil
> Michael J. Tubby B.Sc. MIET <mailto:mike.tubby@thorcom.co.uk>
> 8 March 2017 at 09:05
> Phil Pennock has just posted the availability of 4.89 release to
> exim-announce.
>
> I've downloaded and compiled on Ubuntu 14.04.5 and get one warning
> during compilation:
>
> gcc drtables.c
> gcc enq.c
> gcc exim.c
> exim.c: In function ‘usr1_handler’:
> exim.c:235:1: warning: ignoring return value of ‘write’, declared with
> attribute warn_unused_result [-Wunused-result]
> (void)write(fd, process_info, process_info_len);
> ^
> gcc expand.c
> gcc filter.c
> gcc filtertest.c
> gcc globals.c
> gcc dkim.c
>
>
> and believing that cleanliness is next to godliness have fixed the
> warning by removing the (void) cast over the write function and
> assigning the return value to variable 'sz'.
>
> My version of usr1_handler() is provided below in 1TBS style and
> allows Exim to compile without warning on Ubuntu systems:
>
>
> static void usr1_handler(int sig)
> {
> int fd;
> ssize_t sz;
>
> os_restarting_signal(sig, usr1_handler);
>
> fd = Uopen(process_log_path, O_APPEND|O_WRONLY, LOG_MODE);
>
>   if (fd < 0) {
>     /* If we are already running as the Exim user, try to create it in
> the
>     current process (assuming spool_directory exists). Otherwise, if
> we are
>     root, do the creation in an exim:exim subprocess. */

>
>     int euid = geteuid();
>     if (euid == exim_uid)
>       fd = Uopen(process_log_path, O_CREAT|O_APPEND|O_WRONLY, LOG_MODE);
>     else if (euid == root_uid)
>       fd = log_create_as_exim(process_log_path);
>   }

>
> /* If we are neither exim nor root, or if we failed to create the
> log file,
> give up. There is not much useful we can do with errors, since we
> don't want
> to disrupt whatever is going on outside the signal handler. */
>
>   if (fd < 0)
>     return;

>
> sz = write(fd, process_info, process_info_len);
> close(fd);
> }
>
>
>
> Mike
>
>


--

[ Nigel Metheringham ------------------------------ nigel@??? ] 
[                 Ellipsis Intangible Technologies                  ]