nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Error message when writing to a FIFO


From: André Kugland
Subject: Re: Error message when writing to a FIFO
Date: Mon, 27 Sep 2021 17:31:40 +0000

Hello,

Just  saw your fix. I believe it will still trigger the spurious message when
NANOTINY is defined, and also it would flush the stdio buffer for FIFOs
when NANOTINY isn't defined.

Also, the content of st would be undefined if the file doesn't exist:

#include <stdio.h>
#include <string.h>
#include <sys/stat.h>

int main() {
 struct stat st;
 memset(&st, 3, sizeof(struct stat));
 stat("non_existing_file", &st);
 fwrite(&st, sizeof(struct stat), 1, stdout);
 return 0;
}

% ./a.out | hexdump  
0000000 0303 0303 0303 0303 0303 0303 0303 0303
*
0000090

I was thinking: the only error fflush can set is EBADF, so if errno == EINVAL,
it must have been set by the fsync call. So why not set errno = 0 before the if block,
and then add an inner if block with errno != EINVAL:

       /* Ensure the data has reached the disk before reporting it as written. */
       errno = 0;
       if (fflush(thefile) != 0 || fsync(fileno(thefile)) != 0) { 
               /* fsync will trigger EINVAL if the file is a pipe, a socket or a FIFO,
                  so let's just ignore it. */
               if (errno != EINVAL) {
                       statusline(ALERT, _("Error writing %s: %s"), realname, strerror(errno));
                       fclose(thefile);
                       goto cleanup_and_exit;
               }
       }

This would also work when NANOTINY is defined.

The other option would be moving the variables st and is_existing_file, and also setting them,
outside the #ifndef NANOTINY block, and then testing for is_existing_file and S_ISFIFO.

André Kugland

On Mon, Sep 27, 2021 at 3:32 PM Benno Schulenberg <bensberg@telfort.nl> wrote:

Op 27-09-2021 om 08:38 schreef André Kugland:
> When nano tries to write to a FIFO, it calls fsync, which returns EINVAL.
>
> [...]
>
> EROFS, EINVAL
>              fdis bound to a special file (e.g., a pipe, FIFO, or socket) which does
>              not support synchronization.

Thanks for the report!  I have re-reported the issue on Savannah:

  https://savannah.gnu.org/bugs/?61234

And have fixed the issue in git:

  https://git.savannah.gnu.org/cgit/nano.git/commit/?id=a2b20a19

(I think the fix is correct, although ugly, but if you can test...)


Your report made me find another issue, so thank you for that too:

  https://savannah.gnu.org/bugs/?61235

Will work on that tomorrow.

Benno


reply via email to

[Prev in Thread] Current Thread [Next in Thread]