* dtable.cc (fhandler_base::dup2): Cleanup. Ensure that lock is turned off in
error condition.
This commit is contained in:
parent
a70486d790
commit
4c78be52df
|
@ -1,3 +1,8 @@
|
||||||
|
2002-06-24 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
|
* dtable.cc (fhandler_base::dup2): Cleanup. Ensure that lock is turned
|
||||||
|
off in error condition.
|
||||||
|
|
||||||
2002-06-24 Corinna Vinschen <corinna@vinschen.de>
|
2002-06-24 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* uinfo.cc (internal_getlogin): Set myself->uid and myself->gid instead
|
* uinfo.cc (internal_getlogin): Set myself->uid and myself->gid instead
|
||||||
|
|
|
@ -433,6 +433,7 @@ dtable::dup2 (int oldfd, int newfd)
|
||||||
|
|
||||||
MALLOC_CHECK;
|
MALLOC_CHECK;
|
||||||
debug_printf ("dup2 (%d, %d)", oldfd, newfd);
|
debug_printf ("dup2 (%d, %d)", oldfd, newfd);
|
||||||
|
SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
|
||||||
|
|
||||||
if (not_open (oldfd))
|
if (not_open (oldfd))
|
||||||
{
|
{
|
||||||
|
@ -441,6 +442,13 @@ dtable::dup2 (int oldfd, int newfd)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newfd < 0)
|
||||||
|
{
|
||||||
|
syscall_printf ("new fd out of bounds: %d", newfd);
|
||||||
|
set_errno (EBADF);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
if (newfd == oldfd)
|
if (newfd == oldfd)
|
||||||
{
|
{
|
||||||
res = 0;
|
res = 0;
|
||||||
|
@ -453,35 +461,28 @@ dtable::dup2 (int oldfd, int newfd)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_printf ("newfh->io_handle %p, oldfh->io_handle %p", newfh->get_io_handle (), fds[oldfd]->get_io_handle ());
|
debug_printf ("newfh->io_handle %p, oldfh->io_handle %p",
|
||||||
SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
|
newfh->get_io_handle (), fds[oldfd]->get_io_handle ());
|
||||||
|
|
||||||
if (newfd < 0)
|
|
||||||
{
|
|
||||||
syscall_printf ("new fd out of bounds: %d", newfd);
|
|
||||||
set_errno (EBADF);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((size_t) newfd >= size)
|
|
||||||
{
|
|
||||||
int inc_size = NOFILE_INCR * ((newfd + NOFILE_INCR - 1) / NOFILE_INCR) -
|
|
||||||
size;
|
|
||||||
extend (inc_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!not_open (newfd))
|
if (!not_open (newfd))
|
||||||
_close (newfd);
|
_close (newfd);
|
||||||
fds[newfd] = newfh;
|
else if ((size_t) newfd < size)
|
||||||
|
/* nothing to do */;
|
||||||
|
else if (find_unused_handle (newfd) < 0)
|
||||||
|
{
|
||||||
|
newfh->close ();
|
||||||
|
res = -1;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
|
fds[newfd] = newfh;
|
||||||
MALLOC_CHECK;
|
|
||||||
|
|
||||||
if ((res = newfd) <= 2)
|
if ((res = newfd) <= 2)
|
||||||
set_std_handle (res);
|
set_std_handle (res);
|
||||||
|
|
||||||
MALLOC_CHECK;
|
|
||||||
done:
|
done:
|
||||||
|
MALLOC_CHECK;
|
||||||
|
ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
|
||||||
syscall_printf ("%d = dup2 (%d, %d)", res, oldfd, newfd);
|
syscall_printf ("%d = dup2 (%d, %d)", res, oldfd, newfd);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
Loading…
Reference in New Issue