Ignore:
Timestamp:
Oct 18, 2010, 10:52:03 AM (15 years ago)
Author:
bird
Message:

kash: Some S-bahn optimizations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/redir.c

    r2423 r2424  
    233233
    234234        if (f != fd) {
    235                 copyfd(psh, f, fd);
    236                 shfile_close(&psh->fdtab, f);
     235                movefd(psh, f, fd);
    237236        }
    238237        INTON;
     
    302301                        if (i == 0)
    303302                                psh->fd0_redirected--;
    304                         shfile_close(&psh->fdtab, i);
    305303                        if (rp->renamed[i] >= 0) {
    306                                 copyfd(psh, rp->renamed[i], i);
    307                                 shfile_close(&psh->fdtab, rp->renamed[i]);
     304                                movefd(psh, rp->renamed[i], i);
     305                        } else {
     306                                shfile_close(&psh->fdtab, i);
    308307                        }
    309308                }
     
    378377                if (errno == EMFILE)
    379378                        return EMPTY;
    380                 else
    381                         error(psh, "%d: %s", from, strerror(errno));
     379                error(psh, "%d: %s", from, strerror(errno));
    382380        }
    383381        return newfd;
     
    386384
    387385/*
    388  * Copy a file descriptor to be = to.  Returns -1
     386 * Move a file descriptor to be == to.  Returns -1
    389387 * if the source file descriptor is closed, EMPTY if there are no unused
    390388 * file descriptors left.
     
    392390
    393391int
    394 copyfd2(shinstance *psh, int from, int to)
     392movefd(shinstance *psh, int from, int to)
    395393{
    396394        int newfd;
    397395
    398         /** @todo Use dup2()... */
    399         newfd = shfile_fcntl(&psh->fdtab, from, F_DUPFD, to);
     396        newfd = shfile_movefd(&psh->fdtab, from, to);
    400397        if (newfd < 0) {
    401398                if (errno == EMFILE)
    402399                        return EMPTY;
    403                 else
    404                         error(psh, "%d: %s", from, strerror(errno));
    405         }
    406         else if (newfd != to) {
    407                 error(psh, "%d: F_DUPFD returned %d, expected %d", from, newfd, to);
    408                 close(newfd);
    409                 newfd = -1;
    410         }
    411 
     400                error(psh, "%d: %s", from, strerror(errno));
     401        }
    412402        return newfd;
    413403}
    414404
     405
     406/*
     407 * Move a file descriptor to be >= to.  Returns -1
     408 * if the source file descriptor is closed, EMPTY if there are no unused
     409 * file descriptors left.
     410 */
     411
     412int
     413movefd_above(shinstance *psh, int from, int to)
     414{
     415        int newfd;
     416
     417        newfd = shfile_movefd_above(&psh->fdtab, from, to);
     418        if (newfd < 0) {
     419                if (errno == EMFILE)
     420                        return EMPTY;
     421                error(psh, "%d: %s", from, strerror(errno));
     422        }
     423        return newfd;
     424}
     425
Note: See TracChangeset for help on using the changeset viewer.