Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2002-06-06 00:58:59 +0400
committerJeff Johnston <jjohnstn@redhat.com>2002-06-06 00:58:59 +0400
commit39e65e0113e188e4177077407d337bb3a1ac1853 (patch)
tree7afb2759a870354f5267c72215acfcfc89bb12fa
parentea4e6ec8f9fe4a784d4ce2ef71037e05fb9a876d (diff)
2002-06-05 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/string.h[__linux__]: Add strsignal prototype. * libc/include/sys/lock.h: New file with default locking support. * libc/include/sys/reent.h: Add signal buffer support for strsignal and psignal. * libc/posix/Makefile.am: Add support for readdir_r.c. * libc/posix/Makefile.in: Regenerated. * libc/posix/closedir.c: Add locking support and hash table cleanup. * libc/posix/opendir.c: Add lock support. * libc/posix/readdir.c: Ditto. * libc/posix/rewinddir.c: Ditto. * libc/posix/scandir.c: Ditto. * libc/posix/seekdir.c: Ditto. * libc/posix/telldir.c: Ditto plus add _cleanupdir routine to clean up leftover hash table entries. * libc/posix/readdir_r.c: New file. * libc/sys/linux/Makefile.am: Add psignal.c and strsignal.c support. * libc/sys/linux/Makefile.in: Regenerated. * libc/sys/linux/sys/dirent.h: Add dd_lock to DIR structure. * libc/sys/linux/sys/signal.h: Add psignal prototype. * libc/sys/linux/psignal.c: New file. * libc/sys/linux/strsignal.c: Ditto.
-rw-r--r--newlib/ChangeLog24
-rw-r--r--newlib/libc/include/string.h2
-rw-r--r--newlib/libc/include/sys/lock.h20
-rw-r--r--newlib/libc/include/sys/reent.h15
-rw-r--r--newlib/libc/posix/Makefile.am2
-rw-r--r--newlib/libc/posix/Makefile.in7
-rw-r--r--newlib/libc/posix/closedir.c27
-rw-r--r--newlib/libc/posix/opendir.c7
-rw-r--r--newlib/libc/posix/readdir.c32
-rw-r--r--newlib/libc/posix/readdir_r.c108
-rw-r--r--newlib/libc/posix/rewinddir.c7
-rw-r--r--newlib/libc/posix/scandir.c37
-rw-r--r--newlib/libc/posix/seekdir.c8
-rw-r--r--newlib/libc/posix/telldir.c62
-rw-r--r--newlib/libc/sys/linux/Makefile.am56
-rw-r--r--newlib/libc/sys/linux/Makefile.in79
-rw-r--r--newlib/libc/sys/linux/psignal.c15
-rw-r--r--newlib/libc/sys/linux/strsignal.c63
-rw-r--r--newlib/libc/sys/linux/sys/dirent.h5
-rw-r--r--newlib/libc/sys/linux/sys/signal.h21
20 files changed, 539 insertions, 58 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 187bbcfef..942aafd57 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,27 @@
+2002-06-05 Jeff Johnston <jjohnstn@redhat.com>
+
+ * libc/include/string.h[__linux__]: Add strsignal prototype.
+ * libc/include/sys/lock.h: New file with default locking support.
+ * libc/include/sys/reent.h: Add signal buffer support for strsignal
+ and psignal.
+ * libc/posix/Makefile.am: Add support for readdir_r.c.
+ * libc/posix/Makefile.in: Regenerated.
+ * libc/posix/closedir.c: Add locking support and hash table cleanup.
+ * libc/posix/opendir.c: Add lock support.
+ * libc/posix/readdir.c: Ditto.
+ * libc/posix/rewinddir.c: Ditto.
+ * libc/posix/scandir.c: Ditto.
+ * libc/posix/seekdir.c: Ditto.
+ * libc/posix/telldir.c: Ditto plus add _cleanupdir routine to
+ clean up leftover hash table entries.
+ * libc/posix/readdir_r.c: New file.
+ * libc/sys/linux/Makefile.am: Add psignal.c and strsignal.c support.
+ * libc/sys/linux/Makefile.in: Regenerated.
+ * libc/sys/linux/sys/dirent.h: Add dd_lock to DIR structure.
+ * libc/sys/linux/sys/signal.h: Add psignal prototype.
+ * libc/sys/linux/psignal.c: New file.
+ * libc/sys/linux/strsignal.c: Ditto.
+
2002-06-03 Corinna Vinschen <corinna@vinschen.de>
* libc/include/sys/types.h: Don't define dev_t when compiling for
diff --git a/newlib/libc/include/string.h b/newlib/libc/include/string.h
index 069ca24a7..9db1767d6 100644
--- a/newlib/libc/include/string.h
+++ b/newlib/libc/include/string.h
@@ -74,6 +74,8 @@ char *_EXFUN(strupr,(char *));
const char *_EXFUN(strsignal, (int __signo));
#endif
int _EXFUN(strtosigno, (const char *__name));
+#elif defined(__linux__)
+char *_EXFUN(strsignal, (int __signo));
#endif
/* These function names are used on Windows and perhaps other systems. */
diff --git a/newlib/libc/include/sys/lock.h b/newlib/libc/include/sys/lock.h
new file mode 100644
index 000000000..efdd7316f
--- /dev/null
+++ b/newlib/libc/include/sys/lock.h
@@ -0,0 +1,20 @@
+#ifndef __SYS_LOCK_H__
+#define __SYS_LOCK_H__
+
+/* dummy lock routines for single-threaded aps */
+
+typedef int _LOCK_T;
+typedef int _LOCK_RECURSIVE_T;
+
+#define __LOCK_INIT(class,lock) static int lock = 0;
+#define __LOCK_INIT_RECURSIVE(class,lock) static int lock = 0;
+#define __lock_init(lock) {}
+#define __lock_init_recursive(lock) {}
+#define __lock_close(lock) {}
+#define __lock_close_recursive(lock) {}
+#define __lock_acquire(lock) {}
+#define __lock_acquire_recursive(lock) {}
+#define __lock_release(lock) {}
+#define __lock_release_recursive(lock) {}
+
+#endif /* __SYS_LOCK_H__ */
diff --git a/newlib/libc/include/sys/reent.h b/newlib/libc/include/sys/reent.h
index 1edfad696..f95d58e3e 100644
--- a/newlib/libc/include/sys/reent.h
+++ b/newlib/libc/include/sys/reent.h
@@ -229,6 +229,7 @@ struct _rand48 {
/* How big the some arrays are. */
#define _REENT_EMERGENCY_SIZE 25
#define _REENT_ASCTIME_SIZE 26
+#define _REENT_SIGNAL_SIZE 24
/*
* struct _reent
@@ -305,13 +306,14 @@ struct _reent
struct __sFILE *__sf; /* file descriptors */
struct __sFILE_fake __sf_fake; /* fake initial stdin/out/err */
struct _misc_reent *_misc; /* strtok, multibyte states */
+ char *_signal_buf; /* strsignal */
};
#define _REENT_INIT(var) \
{ (struct __sFILE *)&var.__sf_fake, (struct __sFILE *)&var.__sf_fake, \
(struct __sFILE *)&var.__sf_fake, 0, 0, _NULL, 0, 0, \
"C", _NULL, _NULL, 0, 0, _NULL, _NULL, _NULL, _NULL, _NULL, \
- { 0, _NULL, _NULL, 0 }, { _NULL, 0, _NULL }, _NULL, 0, _NULL }
+ { 0, _NULL, _NULL, 0 }, { _NULL, 0, _NULL }, _NULL, 0, _NULL, _NULL }
#define _REENT_INIT_PTR(var) \
{ var->_stdin = (struct __sFILE *)&var->__sf_fake; \
@@ -341,6 +343,7 @@ struct _reent
var->__sglue._iobs = _NULL; \
var->__sf = 0; \
var->_misc = _NULL; \
+ var->_signal_buf = _NULL; \
var->__sf_fake._p = _NULL; \
var->__sf_fake._r = 0; \
var->__sf_fake._w = 0; \
@@ -414,6 +417,9 @@ struct _reent
#define _REENT_CHECK_MISC(var) \
_REENT_CHECK(var, _misc, struct _misc_reent *, sizeof *((var)->_misc), _REENT_INIT_MISC(var))
+#define _REENT_CHECK_SIGNAL_BUF(var) \
+ _REENT_CHECK(var, _signal_buf, char *, _REENT_SIGNAL_SIZE, /* nothing */)
+
#define _REENT_SIGNGAM(ptr) ((ptr)->_gamma_signgam)
#define _REENT_RAND_NEXT(ptr) ((ptr)->_r48->_rand_next)
#define _REENT_RAND48_SEED(ptr) ((ptr)->_r48->_seed)
@@ -431,6 +437,7 @@ struct _reent
#define _REENT_MBTOWC_STATE(ptr)((ptr)->_misc->_mbtowc_state)
#define _REENT_WCTOMB_STATE(ptr)((ptr)->_misc->_wctomb_state)
#define _REENT_L64A_BUF(ptr) ((ptr)->_misc->_l64a_buf)
+#define _REENT_SIGNAL_BUF(ptr) ((ptr)->_signal_buf)
#else /* !_REENT_SMALL */
@@ -469,7 +476,7 @@ struct _reent
{
unsigned int _unused_rand;
char * _strtok_last;
- char _asctime_buf[26];
+ char _asctime_buf[_REENT_ASCTIME_SIZE];
struct __tm _localtime_buf;
int _gamma_signgam;
__extension__ unsigned long long _rand_next;
@@ -478,6 +485,7 @@ struct _reent
int _mbtowc_state;
int _wctomb_state;
char _l64a_buf[8];
+ char _signal_buf[_REENT_SIGNAL_SIZE];
} _reent;
/* Two next two fields were once used by malloc. They are no longer
used. They are used to preserve the space used before so as to
@@ -551,6 +559,7 @@ struct _reent
var->_new._reent._mbtowc_state = 0; \
var->_new._reent._wctomb_state = 0; \
var->_new._reent._l64a_buf[0] = '\0'; \
+ var->_new._reent._signal_buf[0] = '\0'; \
var->_atexit = _NULL; \
var->_atexit0._ind = 0; \
var->_atexit0._fns[0] = _NULL; \
@@ -568,6 +577,7 @@ struct _reent
#define _REENT_CHECK_ASCTIME_BUF(ptr) /* nothing */
#define _REENT_CHECK_EMERGENCY(ptr) /* nothing */
#define _REENT_CHECK_MISC(ptr) /* nothing */
+#define _REENT_CHECK_SIGNAL_BUF(ptr) /* nothing */
#define _REENT_SIGNGAM(ptr) ((ptr)->_new._reent._gamma_signgam)
#define _REENT_RAND_NEXT(ptr) ((ptr)->_new._reent._rand_next)
@@ -586,6 +596,7 @@ struct _reent
#define _REENT_MBTOWC_STATE(ptr)((ptr)->_new._reent._mbtowc_state)
#define _REENT_WCTOMB_STATE(ptr)((ptr)->_new._reent._wctomb_state)
#define _REENT_L64A_BUF(ptr) ((ptr)->_new._reent._l64a_buf)
+#define _REENT_SIGNAL_BUF(ptr) ((ptr)->_new._reent._signal_buf)
#endif /* !_REENT_SMALL */
diff --git a/newlib/libc/posix/Makefile.am b/newlib/libc/posix/Makefile.am
index 1274137f9..a43bcc687 100644
--- a/newlib/libc/posix/Makefile.am
+++ b/newlib/libc/posix/Makefile.am
@@ -7,7 +7,7 @@ INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
LIB_SOURCES = \
closedir.c opendir.c readdir.c rewinddir.c scandir.c seekdir.c \
telldir.c execl.c execle.c execlp.c execv.c execve.c execvp.c \
- popen.c creat.c isatty.c
+ popen.c creat.c isatty.c readdir_r.c
libposix_la_LDFLAGS = -Xcompiler -nostdlib
diff --git a/newlib/libc/posix/Makefile.in b/newlib/libc/posix/Makefile.in
index df94cf2cf..d955b243e 100644
--- a/newlib/libc/posix/Makefile.in
+++ b/newlib/libc/posix/Makefile.in
@@ -105,7 +105,7 @@ INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
LIB_SOURCES = \
closedir.c opendir.c readdir.c rewinddir.c scandir.c seekdir.c \
telldir.c execl.c execle.c execlp.c execv.c execve.c execvp.c \
- popen.c creat.c isatty.c
+ popen.c creat.c isatty.c readdir_r.c
libposix_la_LDFLAGS = -Xcompiler -nostdlib
@@ -138,14 +138,15 @@ lib_a_LIBADD =
@USE_LIBTOOL_FALSE@lib_a_OBJECTS = closedir.o opendir.o readdir.o \
@USE_LIBTOOL_FALSE@rewinddir.o scandir.o seekdir.o telldir.o execl.o \
@USE_LIBTOOL_FALSE@execle.o execlp.o execv.o execve.o execvp.o popen.o \
-@USE_LIBTOOL_FALSE@creat.o isatty.o
+@USE_LIBTOOL_FALSE@creat.o isatty.o readdir_r.o
LTLIBRARIES = $(noinst_LTLIBRARIES)
libposix_la_LIBADD =
@USE_LIBTOOL_TRUE@libposix_la_OBJECTS = closedir.lo opendir.lo \
@USE_LIBTOOL_TRUE@readdir.lo rewinddir.lo scandir.lo seekdir.lo \
@USE_LIBTOOL_TRUE@telldir.lo execl.lo execle.lo execlp.lo execv.lo \
-@USE_LIBTOOL_TRUE@execve.lo execvp.lo popen.lo creat.lo isatty.lo
+@USE_LIBTOOL_TRUE@execve.lo execvp.lo popen.lo creat.lo isatty.lo \
+@USE_LIBTOOL_TRUE@readdir_r.lo
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
diff --git a/newlib/libc/posix/closedir.c b/newlib/libc/posix/closedir.c
index 4ad6e4c97..57222f947 100644
--- a/newlib/libc/posix/closedir.c
+++ b/newlib/libc/posix/closedir.c
@@ -41,6 +41,9 @@ static char sccsid[] = "@(#)closedir.c 5.9 (Berkeley) 2/23/91";
#include <dirent.h>
#include <stdlib.h>
#include <unistd.h>
+#include <sys/lock.h>
+
+extern void _cleanupdir (DIR *dirp);
/*
* close a directory.
@@ -49,14 +52,26 @@ int
closedir(dirp)
register DIR *dirp;
{
- int fd;
+ int fd, rc;
+#ifdef HAVE_DD_LOCK
+ __lock_acquire_recursive(dirp->dd_lock);
+#endif
+ rc = 0;
fd = dirp->dd_fd;
- dirp->dd_fd = -1;
- dirp->dd_loc = 0;
- (void)free((void *)dirp->dd_buf);
- (void)free((void *)dirp);
- return(close(fd));
+ if (fd != -1) {
+ dirp->dd_fd = -1;
+ dirp->dd_loc = 0;
+ (void)free((void *)dirp->dd_buf);
+ (void)free((void *)dirp);
+ rc = close(fd);
+ _cleanupdir(dirp);
+ }
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+ __lock_close_recursive(dirp->dd_lock);
+#endif
+ return rc;
}
#endif /* ! HAVE_OPENDIR */
diff --git a/newlib/libc/posix/opendir.c b/newlib/libc/posix/opendir.c
index f924c0b52..de14edcad 100644
--- a/newlib/libc/posix/opendir.c
+++ b/newlib/libc/posix/opendir.c
@@ -41,6 +41,7 @@ static char sccsid[] = "@(#)opendir.c 5.11 (Berkeley) 2/23/91";
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
+#include <sys/lock.h>
/*
* open a directory.
@@ -78,6 +79,12 @@ opendir(name)
/*
* Set up seek point for rewinddir.
*/
+
+#ifdef HAVE_DD_LOCK
+ /* if we have a locking mechanism, initialize it */
+ __lock_init_recursive(dirp->dd_lock);
+#endif
+
return dirp;
}
diff --git a/newlib/libc/posix/readdir.c b/newlib/libc/posix/readdir.c
index 308330cb0..4de66e4f9 100644
--- a/newlib/libc/posix/readdir.c
+++ b/newlib/libc/posix/readdir.c
@@ -39,6 +39,8 @@ static char sccsid[] = "@(#)readdir.c 5.7 (Berkeley) 6/1/90";
#include <dirent.h>
+extern int getdents (int fd, void *dp, int count);
+
/*
* get next entry in a directory.
*/
@@ -46,29 +48,51 @@ struct dirent *
readdir(dirp)
register DIR *dirp; {
register struct dirent *dp;
-
+
+#ifdef HAVE_DD_LOCK
+ __lock_acquire_recursive(dirp->dd_lock);
+#endif
+
+ if (dirp->dd_fd == -1)
+ return NULL;
+
for (;;) {
if (dirp->dd_loc == 0) {
dirp->dd_size = getdents (dirp->dd_fd,
dirp->dd_buf,
dirp->dd_len);
- if (dirp->dd_size <= 0)
+ if (dirp->dd_size <= 0) {
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
return NULL;
+ }
}
if (dirp->dd_loc >= dirp->dd_size) {
dirp->dd_loc = 0;
continue;
}
dp = (struct dirent *)(dirp->dd_buf + dirp->dd_loc);
- if ((int)dp & 03) /* bogus pointer check */
+ if ((int)dp & 03) { /* bogus pointer check */
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
return NULL;
+ }
if (dp->d_reclen <= 0 ||
- dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc)
+ dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc) {
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
return NULL;
+ }
dirp->dd_loc += dp->d_reclen;
if (dp->d_ino == 0)
continue;
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
return (dp);
}
}
diff --git a/newlib/libc/posix/readdir_r.c b/newlib/libc/posix/readdir_r.c
new file mode 100644
index 000000000..805180cf5
--- /dev/null
+++ b/newlib/libc/posix/readdir_r.c
@@ -0,0 +1,108 @@
+#ifndef HAVE_OPENDIR
+
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/* this code is modified from readdir.c by Jeff Johnston, June 5, 2002 */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)readdir.c 5.7 (Berkeley) 6/1/90";
+#endif /* LIBC_SCCS and not lint */
+
+#include <dirent.h>
+#include <errno.h>
+#include <string.h>
+
+extern int getdents (int fd, void *dp, int count);
+
+/*
+ * get next entry in a directory using supplied dirent structure.
+ */
+int
+readdir_r(dirp, dp, dpp)
+ register DIR *dirp;
+ struct dirent *dp;
+ struct dirent **dpp; {
+
+struct dirent *tmpdp;
+
+#ifdef HAVE_DD_LOCK
+ __lock_acquire_recursive(dirp->dd_lock);
+#endif
+
+ if (dirp->dd_fd == -1) {
+ *dpp = NULL;
+ return errno = EBADF;
+ }
+
+ for (;;) {
+ if (dirp->dd_loc == 0) {
+ dirp->dd_size = getdents (dirp->dd_fd,
+ dirp->dd_buf,
+ dirp->dd_len);
+
+ if (dirp->dd_size <= 0) {
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
+ *dpp = NULL;
+ return errno;
+ }
+ }
+ if (dirp->dd_loc >= dirp->dd_size) {
+ dirp->dd_loc = 0;
+ continue;
+ }
+ tmpdp = (struct dirent *)(dirp->dd_buf + dirp->dd_loc);
+ memcpy (dp, tmpdp, sizeof(struct dirent));
+
+ if (dp->d_reclen <= 0 ||
+ dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc) {
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
+ *dpp = NULL;
+ return -1;
+ }
+ dirp->dd_loc += dp->d_reclen;
+ if (dp->d_ino == 0)
+ continue;
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
+ *dpp = dp;
+ return 0;
+ }
+}
+
+#endif /* ! HAVE_OPENDIR */
diff --git a/newlib/libc/posix/rewinddir.c b/newlib/libc/posix/rewinddir.c
index 6a3814b55..f7631f983 100644
--- a/newlib/libc/posix/rewinddir.c
+++ b/newlib/libc/posix/rewinddir.c
@@ -39,12 +39,19 @@ static char sccsid[] = "@(#)rewinddir.c 5.1 (Berkeley) 5/25/90";
#include <sys/types.h>
#include <dirent.h>
+#include <sys/lock.h>
void
rewinddir(dirp)
DIR *dirp;
{
+#ifdef HAVE_DD_LOCK
+ __lock_acquire_recursive(dirp->dd_lock);
+#endif
_seekdir((dirp), (off_t)0);
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
}
#endif /* ! HAVE_OPENDIR */
diff --git a/newlib/libc/posix/scandir.c b/newlib/libc/posix/scandir.c
index 6acaff739..bcbe57fbd 100644
--- a/newlib/libc/posix/scandir.c
+++ b/newlib/libc/posix/scandir.c
@@ -49,6 +49,7 @@ static char sccsid[] = "@(#)scandir.c 5.10 (Berkeley) 2/23/91";
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/lock.h>
/*
* The DIRSIZ macro gives the minimum record length which will hold
@@ -84,8 +85,15 @@ scandir(dirname, namelist, select, dcomp)
if ((dirp = opendir(dirname)) == NULL)
return(-1);
- if (fstat(dirp->dd_fd, &stb) < 0)
+#ifdef HAVE_DD_LOCK
+ __lock_acquire_recursive(dirp->dd_lock);
+#endif
+ if (fstat(dirp->dd_fd, &stb) < 0) {
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
return(-1);
+ }
/*
* estimate the array size by taking the size of the directory file
@@ -93,8 +101,12 @@ scandir(dirname, namelist, select, dcomp)
*/
arraysz = (stb.st_size / 24);
names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *));
- if (names == NULL)
+ if (names == NULL) {
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
return(-1);
+ }
nitems = 0;
while ((d = readdir(dirp)) != NULL) {
@@ -104,8 +116,12 @@ scandir(dirname, namelist, select, dcomp)
* Make a minimum size copy of the data
*/
p = (struct dirent *)malloc(DIRSIZ(d));
- if (p == NULL)
+ if (p == NULL) {
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
return(-1);
+ }
p->d_ino = d->d_ino;
p->d_reclen = d->d_reclen;
#ifdef _DIRENT_HAVE_D_NAMLEN
@@ -119,13 +135,21 @@ scandir(dirname, namelist, select, dcomp)
* realloc the maximum size.
*/
if (++nitems >= arraysz) {
- if (fstat(dirp->dd_fd, &stb) < 0)
+ if (fstat(dirp->dd_fd, &stb) < 0) {
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
return(-1); /* just might have grown */
+ }
arraysz = stb.st_size / 12;
names = (struct dirent **)realloc((char *)names,
arraysz * sizeof(struct dirent *));
- if (names == NULL)
+ if (names == NULL) {
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
return(-1);
+ }
}
names[nitems-1] = p;
}
@@ -133,6 +157,9 @@ scandir(dirname, namelist, select, dcomp)
if (nitems && dcomp != NULL)
qsort(names, nitems, sizeof(struct dirent *), dcomp);
*namelist = names;
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
return(nitems);
}
diff --git a/newlib/libc/posix/seekdir.c b/newlib/libc/posix/seekdir.c
index dab3bfb24..a945201c4 100644
--- a/newlib/libc/posix/seekdir.c
+++ b/newlib/libc/posix/seekdir.c
@@ -39,6 +39,7 @@ static char sccsid[] = "@(#)seekdir.c 5.7 (Berkeley) 6/1/90";
#include <sys/param.h>
#include <dirent.h>
+#include <sys/lock.h>
/*
* Seek to an entry in a directory.
@@ -49,8 +50,13 @@ seekdir(dirp, loc)
DIR *dirp;
long loc;
{
-
+#ifdef HAVE_DD_LOCK
+ __lock_acquire_recursive(dirp->dd_lock);
+#endif
_seekdir(dirp, loc);
+#ifdef HAVE_DD_LOCK
+ __lock_release_recursive(dirp->dd_lock);
+#endif
}
#endif /* ! HAVE_OPENDIR */
diff --git a/newlib/libc/posix/telldir.c b/newlib/libc/posix/telldir.c
index 30c003760..6022bbe19 100644
--- a/newlib/libc/posix/telldir.c
+++ b/newlib/libc/posix/telldir.c
@@ -41,6 +41,7 @@ static char sccsid[] = "@(#)telldir.c 5.9 (Berkeley) 2/23/91";
#include <dirent.h>
#include <stdlib.h>
#include <unistd.h>
+#include <sys/lock.h>
/*
* The option SINGLEUSE may be defined to say that a telldir
@@ -60,6 +61,7 @@ struct ddloc {
long loc_index; /* key associated with structure */
long loc_seek; /* magic cookie returned by getdirentries */
long loc_loc; /* offset of entry in buffer */
+ DIR *loc_dirp; /* DIR pointer */
};
#define NDIRHASH 32 /* Num of hash lists, must be a power of 2 */
@@ -67,6 +69,7 @@ struct ddloc {
static long dd_loccnt; /* Index of entry for sequential readdir's */
static struct ddloc *dd_hash[NDIRHASH]; /* Hash list heads for ddlocs */
+__LOCK_INIT(static, dd_hash_lock);
/*
* return a pointer into a directory
@@ -80,12 +83,22 @@ telldir(dirp)
if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL)
return (-1);
+
+#ifdef HAVE_DD_LOCK
+ __lock_acquire_recursive(dirp->dd_lock);
+ __lock_acquire(dd_hash_lock);
+#endif
index = dd_loccnt++;
lp->loc_index = index;
lp->loc_seek = dirp->dd_seek;
lp->loc_loc = dirp->dd_loc;
+ lp->loc_dirp = dirp;
lp->loc_next = dd_hash[LOCHASH(index)];
dd_hash[LOCHASH(index)] = lp;
+#ifdef HAVE_DD_LOCK
+ __lock_release(dd_hash_lock);
+ __lock_release_recursive(dirp->dd_lock);
+#endif
return (index);
}
@@ -103,6 +116,9 @@ _seekdir(dirp, loc)
struct dirent *dp;
extern long lseek();
+#ifdef HAVE_DD_LOCK
+ __lock_acquire(dd_hash_lock);
+#endif
prevlp = &dd_hash[LOCHASH(loc)];
lp = *prevlp;
while (lp != NULL) {
@@ -111,8 +127,12 @@ _seekdir(dirp, loc)
prevlp = &lp->loc_next;
lp = lp->loc_next;
}
- if (lp == NULL)
+ if (lp == NULL) {
+#ifdef HAVE_DD_LOCK
+ __lock_release(dd_hash_lock);
+#endif
return;
+ }
if (lp->loc_loc == dirp->dd_loc && lp->loc_seek == dirp->dd_seek)
goto found;
(void) lseek(dirp->dd_fd, lp->loc_seek, 0);
@@ -128,6 +148,46 @@ found:
*prevlp = lp->loc_next;
free((caddr_t)lp);
#endif
+#ifdef HAVE_DD_LOCK
+ __lock_release(dd_hash_lock);
+#endif
}
+/* clean out any hash entries from a closed directory */
+void
+_cleanupdir (dirp)
+ register DIR *dirp;
+{
+ int i;
+
+#ifdef HAVE_DD_LOCK
+ __lock_acquire(dd_hash_lock);
+#endif
+ for (i = 0; i < NDIRHASH; ++i) {
+ register struct ddloc *lp;
+ register struct ddloc *prevlp;
+ lp = dd_hash[i];
+ while (lp != NULL && lp->loc_dirp == dirp) {
+ dd_hash[i] = lp->loc_next;
+ prevlp = lp;
+ free((caddr_t)lp);
+ lp = prevlp->loc_next;
+ }
+ prevlp = lp;
+ while (lp != NULL) {
+ lp = lp->loc_next;
+ if (lp != NULL && lp->loc_dirp == dirp) {
+ prevlp->loc_next = lp->loc_next;
+ free((caddr_t)lp);
+ lp = prevlp;
+ }
+ else
+ prevlp = lp;
+ }
+ }
+#ifdef HAVE_DD_LOCK
+ __lock_release(dd_hash_lock);
+#endif
+
+}
#endif /* ! HAVE_OPENDIR */
diff --git a/newlib/libc/sys/linux/Makefile.am b/newlib/libc/sys/linux/Makefile.am
index f2c4baee6..fccb24dc3 100644
--- a/newlib/libc/sys/linux/Makefile.am
+++ b/newlib/libc/sys/linux/Makefile.am
@@ -10,13 +10,55 @@ SUBLIBS = \
$(LINUX_MACH_LIB)
LIB_SOURCES = \
- brk.c cfspeed.c flockfile.c funlockfile.c gethostname.c getoptlong.c \
- getreent.c ids.c inode.c io.c io64.c linux.c mmap.c \
- pread.c pread64.c process.c pwrite.c pwrite64.c raise.c realpath.c \
- rename.c resource.c sched.c select.c seteuid.c shm_open.c shm_unlink.c \
- sig.c sigaction.c sigqueue.c signal.c siglongjmp.c sigset.c sigwait.c \
- socket.c sleep.c stack.c sysconf.c sysctl.c systat.c system.c \
- tcdrain.c tcsendbrk.c termios.c time.c usleep.c wait.c
+ brk.c \
+ cfspeed.c \
+ flockfile.c \
+ funlockfile.c \
+ gethostname.c \
+ getoptlong.c \
+ getreent.c \
+ ids.c \
+ inode.c \
+ io.c \
+ io64.c \
+ linux.c \
+ mmap.c \
+ pread.c \
+ pread64.c \
+ process.c \
+ psignal.c \
+ pwrite.c \
+ pwrite64.c \
+ raise.c \
+ realpath.c \
+ rename.c \
+ resource.c \
+ sched.c \
+ select.c \
+ seteuid.c \
+ shm_open.c \
+ shm_unlink.c \
+ sig.c \
+ sigaction.c \
+ sigqueue.c \
+ signal.c \
+ siglongjmp.c \
+ sigset.c \
+ sigwait.c \
+ socket.c \
+ sleep.c \
+ stack.c \
+ strsignal.c \
+ sysconf.c \
+ sysctl.c \
+ systat.c \
+ system.c \
+ tcdrain.c \
+ tcsendbrk.c \
+ termios.c \
+ time.c \
+ usleep.c \
+ wait.c
# This will handle both /usr/src/linux-2.4/include/asm/signal.h (in Red Hat Linux 7.1)
# and also /usr/src/linux/include/asm/signal.h in older versions of Red Hat Linux
diff --git a/newlib/libc/sys/linux/Makefile.in b/newlib/libc/sys/linux/Makefile.in
index b89d6734b..d32595349 100644
--- a/newlib/libc/sys/linux/Makefile.in
+++ b/newlib/libc/sys/linux/Makefile.in
@@ -101,13 +101,55 @@ SUBLIBS = \
LIB_SOURCES = \
- brk.c cfspeed.c flockfile.c funlockfile.c gethostname.c getoptlong.c \
- getreent.c ids.c inode.c io.c io64.c linux.c mmap.c \
- pread.c pread64.c process.c pwrite.c pwrite64.c raise.c realpath.c \
- rename.c resource.c sched.c select.c seteuid.c shm_open.c shm_unlink.c \
- sig.c sigaction.c sigqueue.c signal.c siglongjmp.c sigset.c sigwait.c \
- socket.c sleep.c stack.c sysconf.c sysctl.c systat.c system.c \
- tcdrain.c tcsendbrk.c termios.c time.c usleep.c wait.c
+ brk.c \
+ cfspeed.c \
+ flockfile.c \
+ funlockfile.c \
+ gethostname.c \
+ getoptlong.c \
+ getreent.c \
+ ids.c \
+ inode.c \
+ io.c \
+ io64.c \
+ linux.c \
+ mmap.c \
+ pread.c \
+ pread64.c \
+ process.c \
+ psignal.c \
+ pwrite.c \
+ pwrite64.c \
+ raise.c \
+ realpath.c \
+ rename.c \
+ resource.c \
+ sched.c \
+ select.c \
+ seteuid.c \
+ shm_open.c \
+ shm_unlink.c \
+ sig.c \
+ sigaction.c \
+ sigqueue.c \
+ signal.c \
+ siglongjmp.c \
+ sigset.c \
+ sigwait.c \
+ socket.c \
+ sleep.c \
+ stack.c \
+ strsignal.c \
+ sysconf.c \
+ sysctl.c \
+ systat.c \
+ system.c \
+ tcdrain.c \
+ tcsendbrk.c \
+ termios.c \
+ time.c \
+ usleep.c \
+ wait.c
# This will handle both /usr/src/linux-2.4/include/asm/signal.h (in Red Hat Linux 7.1)
@@ -140,26 +182,27 @@ LIBS = @LIBS@
@USE_LIBTOOL_FALSE@lib_a_OBJECTS = brk.o cfspeed.o flockfile.o \
@USE_LIBTOOL_FALSE@funlockfile.o gethostname.o getoptlong.o getreent.o \
@USE_LIBTOOL_FALSE@ids.o inode.o io.o io64.o linux.o mmap.o pread.o \
-@USE_LIBTOOL_FALSE@pread64.o process.o pwrite.o pwrite64.o raise.o \
-@USE_LIBTOOL_FALSE@realpath.o rename.o resource.o sched.o select.o \
-@USE_LIBTOOL_FALSE@seteuid.o shm_open.o shm_unlink.o sig.o sigaction.o \
-@USE_LIBTOOL_FALSE@sigqueue.o signal.o siglongjmp.o sigset.o sigwait.o \
-@USE_LIBTOOL_FALSE@socket.o sleep.o stack.o sysconf.o sysctl.o systat.o \
-@USE_LIBTOOL_FALSE@system.o tcdrain.o tcsendbrk.o termios.o time.o \
-@USE_LIBTOOL_FALSE@usleep.o wait.o
+@USE_LIBTOOL_FALSE@pread64.o process.o psignal.o pwrite.o pwrite64.o \
+@USE_LIBTOOL_FALSE@raise.o realpath.o rename.o resource.o sched.o \
+@USE_LIBTOOL_FALSE@select.o seteuid.o shm_open.o shm_unlink.o sig.o \
+@USE_LIBTOOL_FALSE@sigaction.o sigqueue.o signal.o siglongjmp.o \
+@USE_LIBTOOL_FALSE@sigset.o sigwait.o socket.o sleep.o stack.o \
+@USE_LIBTOOL_FALSE@strsignal.o sysconf.o sysctl.o systat.o system.o \
+@USE_LIBTOOL_FALSE@tcdrain.o tcsendbrk.o termios.o time.o usleep.o \
+@USE_LIBTOOL_FALSE@wait.o
LTLIBRARIES = $(noinst_LTLIBRARIES)
@USE_LIBTOOL_TRUE@liblinux_la_DEPENDENCIES =
@USE_LIBTOOL_TRUE@liblinux_la_OBJECTS = brk.lo cfspeed.lo flockfile.lo \
@USE_LIBTOOL_TRUE@funlockfile.lo gethostname.lo getoptlong.lo \
@USE_LIBTOOL_TRUE@getreent.lo ids.lo inode.lo io.lo io64.lo linux.lo \
-@USE_LIBTOOL_TRUE@mmap.lo pread.lo pread64.lo process.lo pwrite.lo \
-@USE_LIBTOOL_TRUE@pwrite64.lo raise.lo realpath.lo rename.lo \
+@USE_LIBTOOL_TRUE@mmap.lo pread.lo pread64.lo process.lo psignal.lo \
+@USE_LIBTOOL_TRUE@pwrite.lo pwrite64.lo raise.lo realpath.lo rename.lo \
@USE_LIBTOOL_TRUE@resource.lo sched.lo select.lo seteuid.lo shm_open.lo \
@USE_LIBTOOL_TRUE@shm_unlink.lo sig.lo sigaction.lo sigqueue.lo \
@USE_LIBTOOL_TRUE@signal.lo siglongjmp.lo sigset.lo sigwait.lo \
-@USE_LIBTOOL_TRUE@socket.lo sleep.lo stack.lo sysconf.lo sysctl.lo \
-@USE_LIBTOOL_TRUE@systat.lo system.lo tcdrain.lo tcsendbrk.lo \
+@USE_LIBTOOL_TRUE@socket.lo sleep.lo stack.lo strsignal.lo sysconf.lo \
+@USE_LIBTOOL_TRUE@sysctl.lo systat.lo system.lo tcdrain.lo tcsendbrk.lo \
@USE_LIBTOOL_TRUE@termios.lo time.lo usleep.lo wait.lo
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
diff --git a/newlib/libc/sys/linux/psignal.c b/newlib/libc/sys/linux/psignal.c
new file mode 100644
index 000000000..f5fedc9fa
--- /dev/null
+++ b/newlib/libc/sys/linux/psignal.c
@@ -0,0 +1,15 @@
+/* libc/sys/linux/psignal.c - print signal message to stderr */
+
+/* Copyright 2002, Red Hat Inc. */
+
+#include <stdio.h>
+#include <string.h>
+
+void
+psignal (int sig, const char *s)
+{
+ if (s != NULL)
+ fprintf (stderr, "%s: %s\n", s, strsignal (sig));
+ else
+ fprintf (stderr, "%s\n", strsignal (sig));
+}
diff --git a/newlib/libc/sys/linux/strsignal.c b/newlib/libc/sys/linux/strsignal.c
new file mode 100644
index 000000000..3f95e18a7
--- /dev/null
+++ b/newlib/libc/sys/linux/strsignal.c
@@ -0,0 +1,63 @@
+#include <string.h>
+#include <signal.h>
+#include <stdio.h>
+#include <reent.h>
+
+static const char *sigstring[] =
+ {
+ "Signal 0",
+ "Hangup",
+ "Interrupt",
+ "Quit",
+ "Illegal instruction",
+ "Trace/breakpoint trap",
+ "IOT trap",
+ "EMT trap",
+ "Floating point exception",
+ "Killed",
+ "Bus error",
+ "Segmentation fault",
+ "Bad system call",
+ "Broken pipe",
+ "Alarm clock",
+ "Terminated",
+ "Urgent I/O condition",
+ "Stopped (signal)",
+ "Stopped",
+ "Continued",
+ "Child exited",
+ "Stopped (tty input)",
+ "Stopped (tty output)",
+ "I/O possible",
+ "CPU time limit exceeded",
+ "File size limit exceeded",
+ "Virtual timer expired",
+ "Profiling timer expired",
+ "Window changed",
+ "Resource lost",
+ "User defined signal 1",
+ "User defined signal 2"
+ };
+
+char *
+strsignal (int sig)
+{
+ if (sig < 0 || sig >= __SIGRTMIN)
+ {
+ char *buffer;
+ struct _reent *ptr;
+
+ ptr = _REENT;
+
+ _REENT_CHECK_SIGNAL_BUF(ptr);
+ buffer = _REENT_SIGNAL_BUF(ptr);
+
+ if (sig < 0 || sig > __SIGRTMAX)
+ siprintf (buffer, "Unknown signal %d", sig);
+ else
+ siprintf (buffer, "Real-time signal %d", sig - __SIGRTMIN);
+ return buffer;
+ }
+ else
+ return sigstring[sig];
+}
diff --git a/newlib/libc/sys/linux/sys/dirent.h b/newlib/libc/sys/linux/sys/dirent.h
index ab6b58d26..79949cb0b 100644
--- a/newlib/libc/sys/linux/sys/dirent.h
+++ b/newlib/libc/sys/linux/sys/dirent.h
@@ -8,8 +8,12 @@
#include <sys/types.h>
#include <linux/dirent.h>
+#define _LIBC
+#include <sys/lock.h>
+#undef _LIBC
#define HAVE_NO_D_NAMLEN /* no struct dirent->d_namlen */
+#define HAVE_DD_LOCK /* have locking mechanism */
#define MAXNAMLEN 255 /* sizeof(struct dirent.d_name)-1 */
@@ -21,6 +25,7 @@ typedef struct {
char *dd_buf; /* buffer */
int dd_len; /* buffer length */
int dd_size; /* amount of data in buffer */
+ _LOCK_RECURSIVE_T dd_lock;
} DIR;
diff --git a/newlib/libc/sys/linux/sys/signal.h b/newlib/libc/sys/linux/sys/signal.h
index 3367ca8b7..73e9c7921 100644
--- a/newlib/libc/sys/linux/sys/signal.h
+++ b/newlib/libc/sys/linux/sys/signal.h
@@ -30,16 +30,17 @@
#include <_ansi.h>
-int _EXFUN(kill, (int, int));
-int _EXFUN(sigaction, (int, const struct sigaction *, struct sigaction *));
-int _EXFUN(sigaddset, (sigset_t *, const int));
-int _EXFUN(sigdelset, (sigset_t *, const int));
-int _EXFUN(sigismember, (const sigset_t *, int));
-int _EXFUN(sigfillset, (sigset_t *));
-int _EXFUN(sigemptyset, (sigset_t *));
-int _EXFUN(sigpending, (sigset_t *));
-int _EXFUN(sigsuspend, (const sigset_t *));
-int _EXFUN(sigpause, (int));
+int _EXFUN(kill, (int, int));
+_VOID _EXFUN(psignal, (int, const char *));
+int _EXFUN(sigaction, (int, const struct sigaction *, struct sigaction *));
+int _EXFUN(sigaddset, (sigset_t *, const int));
+int _EXFUN(sigdelset, (sigset_t *, const int));
+int _EXFUN(sigismember, (const sigset_t *, int));
+int _EXFUN(sigfillset, (sigset_t *));
+int _EXFUN(sigemptyset, (sigset_t *));
+int _EXFUN(sigpending, (sigset_t *));
+int _EXFUN(sigsuspend, (const sigset_t *));
+int _EXFUN(sigpause, (int));
#ifndef _POSIX_SOURCE
extern const char *const sys_siglist[];