Skip to content

Commit

Permalink
* include/fcntl.h: Declare __have_atfcts.
Browse files Browse the repository at this point in the history
	* 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.
  • Loading branch information
Ulrich Drepper committed Jan 20, 2006
1 parent 93c0402 commit 7c65e90
Show file tree
Hide file tree
Showing 25 changed files with 731 additions and 75 deletions.
30 changes: 30 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 4 additions & 0 deletions include/fcntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion io/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions io/Versions
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,7 @@ libc {
readlinkat;
symlinkat;
unlinkat;

ppoll;
}
}
76 changes: 76 additions & 0 deletions io/ppoll.c
Original file line number Diff line number Diff line change
@@ -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
21 changes: 20 additions & 1 deletion io/sys/poll.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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. */
Expand All @@ -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 */
2 changes: 2 additions & 0 deletions misc/pselect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions nptl/ChangeLog
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
50 changes: 49 additions & 1 deletion nptl/tst-cancel4.c
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -523,6 +523,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)
{
Expand Down Expand Up @@ -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),
Expand Down
62 changes: 42 additions & 20 deletions sysdeps/unix/sysv/linux/faccessat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
Expand All @@ -86,6 +107,7 @@ faccessat (fd, file, mode, flag)

return result;
}
#endif

struct stat64 stats;
if (fstatat64 (fd, file, &stats, flag & AT_SYMLINK_NOFOLLOW))
Expand Down
Loading

0 comments on commit 7c65e90

Please sign in to comment.