Changeset 2424 for trunk/src/kash/redir.c
- Timestamp:
- Oct 18, 2010, 10:52:03 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/redir.c
r2423 r2424 233 233 234 234 if (f != fd) { 235 copyfd(psh, f, fd); 236 shfile_close(&psh->fdtab, f); 235 movefd(psh, f, fd); 237 236 } 238 237 INTON; … … 302 301 if (i == 0) 303 302 psh->fd0_redirected--; 304 shfile_close(&psh->fdtab, i);305 303 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); 308 307 } 309 308 } … … 378 377 if (errno == EMFILE) 379 378 return EMPTY; 380 else 381 error(psh, "%d: %s", from, strerror(errno)); 379 error(psh, "%d: %s", from, strerror(errno)); 382 380 } 383 381 return newfd; … … 386 384 387 385 /* 388 * Copy a file descriptor to be= to. Returns -1386 * Move a file descriptor to be == to. Returns -1 389 387 * if the source file descriptor is closed, EMPTY if there are no unused 390 388 * file descriptors left. … … 392 390 393 391 int 394 copyfd2(shinstance *psh, int from, int to)392 movefd(shinstance *psh, int from, int to) 395 393 { 396 394 int newfd; 397 395 398 /** @todo Use dup2()... */ 399 newfd = shfile_fcntl(&psh->fdtab, from, F_DUPFD, to); 396 newfd = shfile_movefd(&psh->fdtab, from, to); 400 397 if (newfd < 0) { 401 398 if (errno == EMFILE) 402 399 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 } 412 402 return newfd; 413 403 } 414 404 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 412 int 413 movefd_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.