diff options
| author | Ulrich Drepper <drepper@redhat.com> | 2006-01-20 07:08:05 +0000 |
|---|---|---|
| committer | Ulrich Drepper <drepper@redhat.com> | 2006-01-20 07:08:05 +0000 |
| commit | 7c65e9001b93d5d20046bc4d50fd10fff5f4adc2 (patch) | |
| tree | 38f65e2a20910e6d074fbcec137eb66853e70eaa | |
| parent | 93c04024a6b900b69bbe9a70de06ac23b8273787 (diff) | |
| download | glibc-7c65e9001b93d5d20046bc4d50fd10fff5f4adc2.tar.xz glibc-7c65e9001b93d5d20046bc4d50fd10fff5f4adc2.zip | |
* include/fcntl.h: Declare __have_atfcts.
* sysdeps/unix/sysv/linux/faccessat.c: Use syscall if available.
* sysdeps/unix/sysv/linux/fchmodat.c: Likewise.
* sysdeps/unix/sysv/linux/fchownat.c: Likewise.
* sysdeps/unix/sysv/linux/futimesat.c: Likewise.
* sysdeps/unix/sysv/linux/linkat.c: Likewise.
* sysdeps/unix/sysv/linux/mkdirat.c: Likewise.
* sysdeps/unix/sysv/linux/openat.c: Likewise.
* sysdeps/unix/sysv/linux/readlinkat.c: Likewise.
* sysdeps/unix/sysv/linux/renameat.c: Likewise.
* sysdeps/unix/sysv/linux/symlinkat.c: Likewise.
* sysdeps/unix/sysv/linux/unlinkat.c: Likewise.
* sysdeps/unix/sysv/linux/xmknodat.c: Likewise.
* sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c: Likewise.
* sysdeps/unix/sysv/linux/kernel-features.h: Define __ASSUME_PSELECT,
__ASSUME_PPOLL, and __ASSUME_ATFCTS if possible.
* io/ppoll.c: New file.
* io/Makefile (routines): Add ppoll.
(CFLAGS-ppoll.c): Define.
* io/Versions: Export ppoll for GLIBC_2.4.
* io/sys/poll.h: Declare ppoll.
* sysdeps/unix/sysv/linux/ppoll.c: New file.
* misc/pselect.c: Make it possible to include this file to define
the generic code as a static function.
* sysdeps/unix/sysv/linux/pselect.c: New file.
| -rw-r--r-- | ChangeLog | 30 | ||||
| -rw-r--r-- | include/fcntl.h | 4 | ||||
| -rw-r--r-- | io/Makefile | 3 | ||||
| -rw-r--r-- | io/Versions | 2 | ||||
| -rw-r--r-- | io/ppoll.c | 76 | ||||
| -rw-r--r-- | io/sys/poll.h | 21 | ||||
| -rw-r--r-- | misc/pselect.c | 2 | ||||
| -rw-r--r-- | nptl/ChangeLog | 4 | ||||
| -rw-r--r-- | nptl/tst-cancel4.c | 50 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/faccessat.c | 62 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/fchmodat.c | 25 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/fchownat.c | 24 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/futimesat.c | 30 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/kernel-features.h | 24 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/linkat.c | 24 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/mkdirat.c | 24 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/openat.c | 68 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/ppoll.c | 76 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/pselect.c | 92 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/readlinkat.c | 24 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/renameat.c | 26 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/symlinkat.c | 24 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/unlinkat.c | 23 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c | 31 | ||||
| -rw-r--r-- | sysdeps/unix/sysv/linux/xmknodat.c | 37 |
25 files changed, 731 insertions, 75 deletions
@@ -1,3 +1,33 @@ +2006-01-19 Ulrich Drepper <drepper@redhat.com> + + * include/fcntl.h: Declare __have_atfcts. + * sysdeps/unix/sysv/linux/faccessat.c: Use syscall if available. + * sysdeps/unix/sysv/linux/fchmodat.c: Likewise. + * sysdeps/unix/sysv/linux/fchownat.c: Likewise. + * sysdeps/unix/sysv/linux/futimesat.c: Likewise. + * sysdeps/unix/sysv/linux/linkat.c: Likewise. + * sysdeps/unix/sysv/linux/mkdirat.c: Likewise. + * sysdeps/unix/sysv/linux/openat.c: Likewise. + * sysdeps/unix/sysv/linux/readlinkat.c: Likewise. + * sysdeps/unix/sysv/linux/renameat.c: Likewise. + * sysdeps/unix/sysv/linux/symlinkat.c: Likewise. + * sysdeps/unix/sysv/linux/unlinkat.c: Likewise. + * sysdeps/unix/sysv/linux/xmknodat.c: Likewise. + * sysdeps/unix/sysv/linux/wordsize-64/fxstatat.c: Likewise. + * sysdeps/unix/sysv/linux/kernel-features.h: Define __ASSUME_PSELECT, + __ASSUME_PPOLL, and __ASSUME_ATFCTS if possible. + + * io/ppoll.c: New file. + * io/Makefile (routines): Add ppoll. + (CFLAGS-ppoll.c): Define. + * io/Versions: Export ppoll for GLIBC_2.4. + * io/sys/poll.h: Declare ppoll. + * sysdeps/unix/sysv/linux/ppoll.c: New file. + + * misc/pselect.c: Make it possible to include this file to define + the generic code as a static function. + * sysdeps/unix/sysv/linux/pselect.c: New file. + 2006-01-19 Jakub Jelinek <jakub@redhat.com> * misc/pselect.c (__pselect): Remove static. diff --git a/include/fcntl.h b/include/fcntl.h index 610e322cfd..f00881449d 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -25,4 +25,8 @@ extern void __atfct_seterrno_2 (int errval, int fd1, const char *buf1, int fd2, const char *buf2) attribute_hidden; + +/* Flag determining whether the *at system calls are available. */ +extern int __have_atfcts attribute_hidden; + #endif diff --git a/io/Makefile b/io/Makefile index 5e6d72eace..e005cb3cd5 100644 --- a/io/Makefile +++ b/io/Makefile @@ -48,7 +48,7 @@ routines := \ ttyname ttyname_r isatty \ link linkat symlink symlinkat readlink readlinkat \ unlink unlinkat rmdir \ - ftw ftw64 fts poll \ + ftw ftw64 fts poll ppoll \ posix_fadvise posix_fadvise64 \ posix_fallocate posix_fallocate64 \ sendfile sendfile64 @@ -72,6 +72,7 @@ include ../Rules CFLAGS-fcntl.c = -fexceptions -fasynchronous-unwind-tables CFLAGS-poll.c = -fexceptions -fasynchronous-unwind-tables +CFLAGS-ppoll.c = -fexceptions -fasynchronous-unwind-tables CFLAGS-lockf.c = -fexceptions CFLAGS-statfs.c = -fexceptions CFLAGS-fstatfs.c = -fexceptions diff --git a/io/Versions b/io/Versions index 16006a8e08..bc9c9d2685 100644 --- a/io/Versions +++ b/io/Versions @@ -110,5 +110,7 @@ libc { readlinkat; symlinkat; unlinkat; + + ppoll; } } diff --git a/io/ppoll.c b/io/ppoll.c new file mode 100644 index 0000000000..a035cfeb1f --- /dev/null +++ b/io/ppoll.c @@ -0,0 +1,76 @@ +/* Copyright (C) 2006 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2006. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <limits.h> +#include <signal.h> +#include <stddef.h> /* For NULL. */ +#include <sys/poll.h> +#include <sysdep-cancel.h> + + +int +ppoll (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, + const sigset_t *sigmask) +{ + int tval = -1; + + /* poll uses a simple millisecond value. Convert it. */ + if (timeout != NULL) + { + if (timeout->tv_sec < 0 + || timeout->tv_nsec < 0 || timeout->tv_nsec >= 1000000000) + { + __set_errno (EINVAL); + return -1; + } + + if (timeout->tv_sec > INT_MAX / 1000 + || (timeout->tv_sec == INT_MAX / 1000 + && ((timeout->tv_nsec + 999999) / 1000000 > INT_MAX % 1000))) + /* We cannot represent the timeout in an int value. Wait + forever. */ + tval = -1; + else + tval = (timeout->tv_sec * 1000 + + (timeout->tv_nsec + 999999) / 1000000); + } + + /* The setting and restoring of the signal mask and the select call + should be an atomic operation. This can't be done without kernel + help. */ + sigset_t savemask; + if (sigmask != NULL) + __sigprocmask (SIG_SETMASK, sigmask, &savemask); + + /* Note the ppoll() is a cancellation point. But since we call + poll() which itself is a cancellation point we do not have + to do anything here. */ + int retval = __poll (fds, nfds, tval); + + if (sigmask != NULL) + __sigprocmask (SIG_SETMASK, &savemask, NULL); + + return retval; +} + +#ifndef ppoll +/* __poll handles cancellation. */ +LIBC_CANCEL_HANDLED (); +#endif diff --git a/io/sys/poll.h b/io/sys/poll.h index 9cf1b9f1c0..4085b785ee 100644 --- a/io/sys/poll.h +++ b/io/sys/poll.h @@ -1,5 +1,5 @@ /* Compatibility definitions for System V `poll' interface. - Copyright (C) 1994,1996-2001,2004,2005 Free Software Foundation, Inc. + Copyright (C) 1994,1996-2001,2004,2005,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -24,6 +24,13 @@ /* Get the platform dependent bits of `poll'. */ #include <bits/poll.h> +#ifdef __USE_GNU +/* Get the __sigset_t definition. */ +# include <bits/sigset.h> +/* Get the timespec definition. */ +# define __need_timespec +# include <time.h> +#endif /* Type used for the number of file descriptors. */ @@ -50,6 +57,18 @@ __BEGIN_DECLS __THROW. */ extern int poll (struct pollfd *__fds, nfds_t __nfds, int __timeout); +#ifdef __USE_GNU +/* Like poll, but before waiting the threads signal mask is replaced + with that specified in the fourth parameter. For better usability, + the timeout value is specified using a TIMESPEC object. + + This function is a cancellation point and therefore not marked with + __THROW. */ +extern int ppoll (struct pollfd *__fds, nfds_t __nfds, + __const struct timespec *__timeout, + __const __sigset_t *__ss); +#endif + __END_DECLS #endif /* sys/poll.h */ diff --git a/misc/pselect.c b/misc/pselect.c index 1d841a8cf4..80cf8be4b3 100644 --- a/misc/pselect.c +++ b/misc/pselect.c @@ -62,7 +62,9 @@ __pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, return retval; } +#ifndef __pselect weak_alias (__pselect, pselect) strong_alias (__pselect, __libc_pselect) /* __select handles cancellation. */ LIBC_CANCEL_HANDLED (); +#endif diff --git a/nptl/ChangeLog b/nptl/ChangeLog index a902ceb62f..dd87226d6e 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,3 +1,7 @@ +2006-01-19 Ulrich Drepper <drepper@redhat.com> + + * tst-cancel4.c: Test ppoll. + 2006-01-18 Andreas Jaeger <aj@suse.de> [BZ #2167] diff --git a/nptl/tst-cancel4.c b/nptl/tst-cancel4.c index cb7619688e..73cfa44614 100644 --- a/nptl/tst-cancel4.c +++ b/nptl/tst-cancel4.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. @@ -524,6 +524,53 @@ tf_poll (void *arg) static void * +tf_ppoll (void *arg) +{ + int fd; + int r; + + if (arg == NULL) + fd = fds[0]; + else + { + char fname[] = "/tmp/tst-cancel4-fd-XXXXXX"; + tempfd = fd = mkstemp (fname); + if (fd == -1) + printf ("%s: mkstemp failed\n", __FUNCTION__); + unlink (fname); + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } }; + + int s; + pthread_cleanup_push (cl, NULL); + + s = ppoll (rfs, 1, NULL, NULL); + + pthread_cleanup_pop (0); + + printf ("%s: ppoll returns with %d (%s)\n", __FUNCTION__, s, + strerror (errno)); + + exit (1); +} + + +static void * tf_wait (void *arg) { pid_t pid = fork (); @@ -2006,6 +2053,7 @@ static struct ADD_TEST (select, 2, 0), ADD_TEST (pselect, 2, 0), ADD_TEST (poll, 2, 0), + ADD_TEST (ppoll, 2, 0), ADD_TEST (write, 2, 0), ADD_TEST (writev, 2, 0), ADD_TEST (sleep, 2, 0), diff --git a/sysdeps/unix/sysv/linux/faccessat.c b/sysdeps/unix/sysv/linux/faccessat.c index 80b3b240f7..7c28280ae6 100644 --- a/sysdeps/unix/sysv/linux/faccessat.c +++ b/sysdeps/unix/sysv/linux/faccessat.c @@ -25,8 +25,10 @@ #include <unistd.h> #include <sys/types.h> #include <alloca.h> +#include <kernel-features.h> #include <sysdep.h> + int faccessat (fd, file, mode, flag) int fd; @@ -40,42 +42,61 @@ faccessat (fd, file, mode, flag) return -1; } - char *buf = NULL; + int result; - if (fd != AT_FDCWD && file[0] != '/') +#ifdef __NR_faccessat + if (flag == 0 +# ifndef __ASSUME_ATFCTS + && __have_atfcts >= 0 +# endif + ) { - size_t filelen = strlen (file); - static const char procfd[] = "/proc/self/fd/%d/%s"; - /* Buffer for the path name we are going to use. It consists of - - the string /proc/self/fd/ - - the file descriptor number - - the file name provided. - The final NUL is included in the sizeof. A bit of overhead - due to the format elements compensates for possible negative - numbers. */ - size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen; - buf = alloca (buflen); - - __snprintf (buf, buflen, procfd, fd, file); - file = buf; + result = INLINE_SYSCALL (faccessat, 3, fd, file, mode); +# ifndef __ASSUME_ATFCTS + if (result == -1 && errno == ENOSYS) + __have_atfcts = -1; + else +# endif + return result; } +#endif +#ifndef __ASSUME_ATFCTS if ((!(flag & AT_EACCESS) || ! __libc_enable_secure) -#ifndef __NR_laccess /* Linux so far has no laccess syscall. */ +# ifndef __NR_laccess /* Linux so far has no laccess syscall. */ && !(flag & AT_SYMLINK_NOFOLLOW) -#endif +# endif ) { /* If we are not set-uid or set-gid, access does the same. */ + char *buf = NULL; + + if (fd != AT_FDCWD && file[0] != '/') + { + size_t filelen = strlen (file); + static const char procfd[] = "/proc/self/fd/%d/%s"; + /* Buffer for the path name we are going to use. It consists of + - the string /proc/self/fd/ + - the file descriptor number + - the file name provided. + The final NUL is included in the sizeof. A bit of overhead + due to the format elements compensates for possible negative + numbers. */ + size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen; + buf = alloca (buflen); + + __snprintf (buf, buflen, procfd, fd, file); + file = buf; + } int result; INTERNAL_SYSCALL_DECL (err); -#ifdef __NR_laccess +# ifdef __NR_laccess if (flag & AT_SYMLINK_NOFOLLOW) result = INTERNAL_SYSCALL (laccess, err, 2, file, mode); else -#endif +# endif result = INTERNAL_SYSCALL (access, err, 2, file, mode); if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0)) @@ -86,6 +107,7 @@ faccessat (fd, file, mode, flag) return result; } +#endif struct stat64 stats; if (fstatat64 (fd, file, &stats, flag & AT_SYMLINK_NOFOLLOW)) diff --git a/sysdeps/unix/sysv/linux/fchmodat.c b/sysdeps/unix/sysv/linux/fchmodat.c index de35e4376f..8b420153f1 100644 --- a/sysdeps/unix/sysv/linux/fchmodat.c +++ b/sysdeps/unix/sysv/linux/fchmodat.c @@ -25,6 +25,7 @@ #include <unistd.h> #include <sys/types.h> #include <alloca.h> +#include <kernel-features.h> #include <sysdep.h> int @@ -47,6 +48,24 @@ fchmodat (fd, file, mode, flag) } #endif + int result; + +#ifdef __NR_fchmodat +# ifndef __ASSUME_ATFCTS + if (__have_atfcts >= 0) +# endif + { + result = INLINE_SYSCALL (fchmodat, 3, fd, file, mode); +# ifndef __ASSUME_ATFCTS + if (result == -1 && errno == ENOSYS) + __have_atfcts = -1; + else +# endif + return result; + } +#endif + +#ifndef __ASSUME_ATFCTS char *buf = NULL; if (fd != AT_FDCWD && file[0] != '/') @@ -67,14 +86,13 @@ fchmodat (fd, file, mode, flag) file = buf; } - int result; INTERNAL_SYSCALL_DECL (err); -#ifdef __NR_lchmod +# ifdef __NR_lchmod if (flag & AT_SYMLINK_NOFOLLOW) result = INTERNAL_SYSCALL (lchmod, err, 2, file, mode); else -#endif +# endif result = INTERNAL_SYSCALL (chmod, err, 2, file, mode); if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0)) @@ -84,4 +102,5 @@ fchmodat (fd, file, mode, flag) } return result; +#endif } diff --git a/sysdeps/unix/sysv/linux/fchownat.c b/sysdeps/unix/sysv/linux/fchownat.c index 10d87e87fc..0f731775b3 100644 --- a/sysdeps/unix/sysv/linux/fchownat.c +++ b/sysdeps/unix/sysv/linux/fchownat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005 Free Software Foundation, Inc. +/* Copyright (C) 2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -25,6 +25,8 @@ #include <sys/types.h> |
