tDon't close a random fd - ratox - FIFO based tox client
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 2e31429e333c10d4d6a94b57d4d6c8d46ccf7a2d
 (DIR) parent 68bfca6e6ec56f7eda1a08b6cb7316ce0d8bc425
 (HTM) Author: sin <sin@2f30.org>
       Date:   Wed,  8 Oct 2014 20:52:33 +0100
       
       Don't close a random fd
       
       if (f->rxstate == TRANSFER_INPROGRESS &&
           (fd = openat(f->dirfd, ffiles[FFILE_OUT].name, ffiles[FFILE_OUT].flags, 0666)) == -1 &&
           errno == ENXIO) {
           ...
       } else {
           close(fd); <--- not always appropriate!
       }
       
       Diffstat:
         M ratox.c                             |      10 ++++++----
       
       1 file changed, 6 insertions(+), 4 deletions(-)
       ---
 (DIR) diff --git a/ratox.c b/ratox.c
       t@@ -1687,10 +1687,12 @@ loop(void)
                                        canceltxtransfer(f);
                                        cancelrxtransfer(f);
                                }
       -                        if (f->rxstate == TRANSFER_INPROGRESS &&
       -                            (fd = openat(f->dirfd, ffiles[FFILE_OUT].name, ffiles[FFILE_OUT].flags, 0666)) == -1 &&
       -                            errno == ENXIO) {
       -                                cancelrxtransfer(f);
       +                        if (f->rxstate != TRANSFER_INPROGRESS)
       +                                continue;
       +                        fd = openat(f->dirfd, ffiles[FFILE_OUT].name, ffiles[FFILE_OUT].flags, 0666);
       +                        if (fd < 0) {
       +                                if (errno == ENXIO)
       +                                        cancelrxtransfer(f);
                                } else {
                                        close(fd);
                                }