summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/opendir.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC 268531,269079,269204:jhb2014-08-141-161/+204
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix various edge cases with rewinddir(), seekdir(), and telldir(): - In the unionfs case, opendir() and fdopendir() read the directory's full contents and cache it. This cache is not refreshed when rewinddir() is called, so rewinddir() will not notice updates to a directory. Fix this by splitting the code to fetch a directory's contents out of __opendir_common() into a new _filldir() function and call this from rewinddir() when operating on a unionfs directory. - If rewinddir() is called on a directory opened with fdopendir() before any directory entries are fetched, rewinddir() will not adjust the seek location of the backing file descriptor. If the file descriptor passed to fdopendir() had a non-zero offset, the rewinddir() will not rewind to the beginning. Fix this by always seeking back to 0 in rewinddir(). This means the dd_rewind hack can also be removed. - Add missing locking to rewinddir() - POSIX says that passing a location returned by telldir() to seekdir() after an intervening call to rewinddir() is undefined, so reclaim any pending telldir() cookies in the directory when rewinddir() is called. - If telldir() is called immediately after a call to seekdir(), POSIX requires the return value of telldir() to equal the value passed to seekdir(). The current seekdir code with SINGLEUSE enabled breaks this case as each call to telldir() allocates a new cookie. Instead, remove the SINGLEUSE code and change telldir() to look for an existing cookie for the directory's current location rather than always creating a new cookie. PR: 121656
* libc/opendir: Improve behaviour of union uniquifier:jilles2013-02-241-25/+26
| | | | | | | | | * Reopen the directory using openat(fd, ".", ...) instead of opening the pathname again. This fixes a race condition where the meaning of the pathname changes and allows a reopen with fdopendir(). * Always reopen the directory for union stacks, not only when DTF_REWIND is passed. Applications should be able to fchdir(dirfd(dir)) and *at(dirfd(dir), ...). DTF_REWIND now does nothing.
* libc: Use O_CLOEXEC for various internal file descriptors.jilles2012-09-291-1/+2
| | | | | | | | | This fixes a race condition where another thread may fork() before CLOEXEC is set, unintentionally passing the descriptor to the child process. This commit only adds O_CLOEXEC flags to open() or openat() calls where no fcntl(fd, F_SETFD, FD_CLOEXEC) follows. The separate fcntl() call still leaves a race window so it should be fixed later.
* Hide DIR definition by making it an opaque struct typedef.gleb2012-05-191-0/+1
| | | | | | | | | | Introduce dirfd() libc exported symbol replacing macro with same name, preserve _dirfd() macro for internal use. Replace dirp->dd_fd with dirfd() call. Avoid using dirfd as variable name to prevent shadowing global symbol. Sponsored by: Google Summer Of Code 2011
* Finally removed the stat() and fstat() calls from the opendir() code.ru2012-03-021-24/+14
| | | | | | | | | | | They were made excessive in r205424 by opening with O_DIRECTORY. Also eliminated the fcntl() call used to set FD_CLOEXEC by opening with O_CLOEXEC. (fdopendir() still checks that the passed descriptor is a directory, and sets FD_CLOEXEC on it.) Reviewed by: ed
* fdopendir(): Do not close the passed file descriptor on failure.jilles2011-11-221-4/+13
| | | | Reviewed by: delphij
* Let opendir() use O_DIRECTORY.ed2010-03-211-2/+2
| | | | | I am not removing the fstat() calls here, since we cannot yet assume people will always run kernels that respect O_DIRECTORY.
* Style: rename internal function to opendir_compar()ache2010-01-201-2/+2
| | | | Pointed by: bde
* Double checking my commit I found that comment saying thatache2010-01-181-7/+3
| | | | | | | | POSIX 2008 and XSI 7require strcoll() for opendir() is not true. I can't find such requirement in POSIX 2008 and XSI 7. So, back out that part of my commit, returning old strcmp(), and remove this misleading comment.
* a) Use strcoll() in opendir() and alphasort() as POSIX 2008 requires.ache2010-01-181-2/+2
| | | | | | | | | | | | | | | | | It also matches now how our 'ls' works for years. b) Remove comment expressed 2 fears: 1) One just simple describe how strcoll() works in _any_ context, not for directories only. Are we plan to remove strcoll() from everything just because it is little more complex than strcmp()? I doubt, and directories give nothing different here. Moreover, strcoll() used in 'ls' for years and nobody complaints yet. 2) Plain wrong statement about undefined strcoll() behaviour. strcoll() always gives predictable results, falling back to strcmp() on any trouble, see strcoll(3). No objections from -current list discussion.
* Do not rely on behaviour undefined by ANSI C, use thunks to adaptkib2010-01-051-2/+14
| | | | | | | | | | | alphasort-like interface to the comparision function required by qsort() and qsort_r(). For opendir() thunk and alphasort(), comment on why we deviated from POSIX by using strcmp() instead of strcoll(). Requested and reviewed by: bde MFC after: 2 weeks
* Modernize scandir(3) and alphasort(3) interfaces according to the IEEEkib2010-01-041-1/+2
| | | | | | | | | | | | | | | | | | | | Std 1003.1-2008. Both Linux and Solaris conforms to the new definitions, so we better follow too (older glibc used old BSDish alphasort prototype and corresponding type of the comparision function for scandir). While there, change the definitions of the functions to ANSI C and fix several style issues nearby. Remove requirement for "sys/types.h" include for functions from manpage. POSIX also requires that alphasort(3) sorts as if strcoll(3) was used, but leave the strcmp(3) call in the function for now. Adapt in-tree callers of scandir(3) to new declaration. The fact that select_sections() from catman(1) could modify supplied struct dirent is a bug. PR: standards/142255 MFC after: 2 weeks
* Implement fdopendir(3) by splitting __opendir2() into two parts, the upper partdelphij2008-04-161-5/+31
| | | | | | deals with the usual __opendir2() calls, and the rest part with an interface translator to expose fdopendir(3) functionality. Manual page was obtained from kib@'s work for *at(2) system calls.
* Style fixes to opendir.c:delphij2008-04-161-6/+3
| | | | | - Use /*- for copyright block; - ANSIfy.
* Per Regents of the University of Calfornia letter, remove advertisingimp2007-01-091-4/+0
| | | | | | clause. # If I've done so improperly on a file, please let me know.
* Avoid using void pointers in additive expressions.stefanf2004-08-141-1/+1
| | | | PR: 56653
* Make sure we initialise dirp->dd_size if we aren't reading a unionfsdfr2003-12-261-0/+1
| | | | | | directory. Special thanks to: valgrind
* Catch up with the renaming of the "union" filesystem to "unionfs".tjr2003-05-161-1/+1
| | | | | | | Fixes a problem where directory entries could show up twice: once on the top layer of the union stack, and once on the bottom layer. Approved by: re (rwatson)
* #include <string.h> for strcmp()'s prototype.tjr2003-01-041-0/+1
|
* Fix SCM ID's.obrien2002-02-011-2/+2
|
* Compensate for "Compensate for header dethreading" by backing it out.bde2001-10-101-2/+0
|
* Compensate for header dethreading.markm2001-05-011-0/+2
|
* Fix directory reads of MNT_UNION mounts, where entries present in bothjoerg2001-04-231-1/+2
| | | | | | | layers would be displayed twice. PR: bin/26498 Submitted by: Olliver Fromme <olli@secnetix.de>
* Fix style bug that was introduced.obrien2001-03-051-0/+1
|
* Remove _THREAD_SAFE and make libc thread-safe by default bydeischen2001-01-241-9/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | adding (weak definitions to) stubs for some of the pthread functions. If the threads library is linked in, the real pthread functions will pulled in. Use the following convention for system calls wrapped by the threads library: __sys_foo - actual system call _foo - weak definition to __sys_foo foo - weak definition to __sys_foo Change all libc uses of system calls wrapped by the threads library from foo to _foo. In order to define the prototypes for _foo(), we introduce namespace.h and un-namespace.h (suggested by bde). All files that need to reference these system calls, should include namespace.h before any standard includes, then include un-namespace.h after the standard includes and before any local includes. <db.h> is an exception and shouldn't be included in between namespace.h and un-namespace.h namespace.h will define foo to _foo, and un-namespace.h will undefine foo. Try to eliminate some of the recursive calls to MT-safe functions in libc/stdio in preparation for adding a mutex to FILE. We have recursive mutexes, but would like to avoid using them if possible. Remove uneeded includes of <errno.h> from a few files. Add $FreeBSD$ to a few files in order to pass commitprep. Approved by: -arch
* Move telldir position recording type definitions and prototypesdeischen2000-12-111-3/+7
| | | | | | | to "telldir.h" in order to prevent namespace pollution in <dirent.h> (which was including <sys/queue.h>). Add $FreeBSD$ to rewinddir.c and seekdir.c.
* Cleanup XXXdir functions to eliminate global hash table ofdeischen2000-12-061-0/+2
| | | | | | | | | | | | | | | | telldir positions. This will allow (future) locking on a per-DIR basis (for MT-safety). For now, this change does the following: o Remove the hash table from telldir.c. Recode to use queue macros. o Remove 'const' from 'telldir(const DIR *)'. o Remove 'register' variables as suggested in a recent thread. No response from: -current
* Simplify sytem call renaming. Instead of _foo() <-- _libc_foo <-- foo(),jasone2000-01-271-5/+5
| | | | | | | | | | | | | | | | | just use _foo() <-- foo(). In the case of a libpthread that doesn't do call conversion (such as linuxthreads and our upcoming libpthread), this is adequate. In the case of libc_r, we still need three names, which are now _thread_sys_foo() <-- _foo() <-- foo(). Convert all internal libc usage of: aio_suspend(), close(), fsync(), msync(), nanosleep(), open(), fcntl(), read(), and write() to _foo() instead of foo(). Remove all internal libc usage of: creat(), pause(), sleep(), system(), tcdrain(), wait(), and waitpid(). Make thread cancellation fully POSIX-compliant. Suggested by: deischen
* Add three-tier symbol naming in support of POSIX thread cancellationjasone2000-01-121-5/+7
| | | | | | points. For library functions, the pattern is __sleep() <-- _libc_sleep() <-- sleep(). The arrows represent weak aliases. For system calls, the pattern is _read() <-- _libc_read() <-- read().
* Replace memory leaking instances of realloc with non-leaking reallocf.imp1998-09-161-1/+1
| | | | | | | | | | | In some cases replace if (a == null) a = malloc(x); else a = realloc(a, x); with simple reallocf(a, x). Per ANSI-C, this is guaranteed to be the same thing. I've been running these on my system here w/o ill effects for some time. However, the CTM-express is at part 6 of 34 for the CAM changes, so I've not been able to do a build world with the CAM in the tree with these changes. Shouldn't impact anything, but...
* Cast pointer to a long instead of an int to keep a 64-bit compilerjb1998-03-091-1/+1
| | | | happy. The code works either way, but I like a clean compile.
* Fixed errors in the Lite2 merge. Some style changes were mismerged.bde1997-03-121-27/+28
| | | | | | | My changes to preserve errno across free() and close() and to report fstat() errors properly were blown away. Updated the FreeBSD changes to match the Lite2 style fixes.
* Merge from Lite2:peter1997-03-111-33/+200
| | | | | filesystem include updates, duplicate group suppression, cleanups, filesystem whiteout support (unionfs), bidir popen().
* Cache the result of getpagesize() so we only make one syscall.phk1996-05-021-10/+5
| | | | Use getpagesize instead of CLBYTES.
* stat() before open() because opening of special files may be harmful.bde1996-03-291-0/+10
|
* Fix bugs in opendir():bde1995-04-211-9/+23
| | | | | | | - it succeeded on non-directories (see POSIX 5.1.2.4). - it hung on (non-open) named pipes. - it leaked memory if the second malloc() failed. - it didn't preserve errno across errors in close().
* BSD 4.4 Lite Lib Sourcesrgrimes1994-05-271-0/+87
OpenPOWER on IntegriCloud