[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: proposal: module 'accept4'
From: |
Bruno Haible |
Subject: |
Re: proposal: module 'accept4' |
Date: |
Mon, 24 Aug 2009 02:20:12 +0200 |
User-agent: |
KMail/1.9.9 |
Eric Blake wrote:
> Shouldn't we follow the lead of popen-safer, and cache whether pipe2
> exists, so that we aren't wasting time on a guaranteed ENOSYS on all
> subsequent invocations?
Good point. This should do it. Feel free to add the same optimization to
lib/utimens.c.
2009-08-23 Bruno Haible <address@hidden>
* lib/dup3.c (dup3): Test only once whether the system actually exists.
* lib/pipe2.c (pipe2): Likewise.
Suggested by Eric Blake.
*** lib/dup3.c.orig 2009-08-24 02:16:12.000000000 +0200
--- lib/dup3.c 2009-08-24 02:11:17.000000000 +0200
***************
*** 53,61 ****
/* Try the system call first, if it exists. (We may be running with a glibc
that has the function but with an older kernel that lacks it.) */
{
! int result = dup3 (oldfd, newfd, flags);
! if (!(result < 0 && errno == ENOSYS))
! return result;
}
#endif
--- 53,70 ----
/* Try the system call first, if it exists. (We may be running with a glibc
that has the function but with an older kernel that lacks it.) */
{
! /* Cache the information whether the system call really exists. */
! static int have_dup3_really; /* 0 = unknown, 1 = yes, -1 = no */
! if (have_dup3_really >= 0)
! {
! int result = dup3 (oldfd, newfd, flags);
! if (!(result < 0 && errno == ENOSYS))
! {
! have_dup3_really = 1;
! return result;
! }
! have_dup3_really = -1;
! }
}
#endif
*** lib/pipe2.c.orig 2009-08-24 02:16:12.000000000 +0200
--- lib/pipe2.c 2009-08-24 02:11:18.000000000 +0200
***************
*** 45,53 ****
/* Try the system call first, if it exists. (We may be running with a glibc
that has the function but with an older kernel that lacks it.) */
{
! int result = pipe2 (fd, flags);
! if (!(result < 0 && errno == ENOSYS))
! return result;
}
#endif
--- 45,62 ----
/* Try the system call first, if it exists. (We may be running with a glibc
that has the function but with an older kernel that lacks it.) */
{
! /* Cache the information whether the system call really exists. */
! static int have_pipe2_really; /* 0 = unknown, 1 = yes, -1 = no */
! if (have_pipe2_really >= 0)
! {
! int result = pipe2 (fd, flags);
! if (!(result < 0 && errno == ENOSYS))
! {
! have_pipe2_really = 1;
! return result;
! }
! have_pipe2_really = -1;
! }
}
#endif
- proposal: module 'accept4', Bruno Haible, 2009/08/22
- Re: proposal: module 'accept4', Eric Blake, 2009/08/22
- Re: proposal: module 'accept4', Paolo Bonzini, 2009/08/23
- Re: proposal: module 'accept4', Eric Blake, 2009/08/23
- Re: proposal: module 'accept4', Paolo Bonzini, 2009/08/24
- Re: proposal: module 'accept4', Simon Josefsson, 2009/08/24
- Re: proposal: module 'accept4', Bruno Haible, 2009/08/24
- Re: proposal: module 'accept4', Paolo Bonzini, 2009/08/25