diff options
author | deischen <deischen@FreeBSD.org> | 1999-08-05 12:08:10 +0000 |
---|---|---|
committer | deischen <deischen@FreeBSD.org> | 1999-08-05 12:08:10 +0000 |
commit | 9161b0a7904cd5f5ec64dfebc31201ccdf41c2f9 (patch) | |
tree | fded8c38645f1509bdaf35c512fd84076a5ce350 /lib | |
parent | 4df48d07f1726a1f451ba70d0bcdd288e3c2803a (diff) | |
download | FreeBSD-src-9161b0a7904cd5f5ec64dfebc31201ccdf41c2f9.zip FreeBSD-src-9161b0a7904cd5f5ec64dfebc31201ccdf41c2f9.tar.gz |
Fix thread initialization to allow for the case where stdio file
descriptors are not opened.
PR: bin/12853
Reviewed by: jb
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc_r/uthread/pthread_private.h | 6 | ||||
-rw-r--r-- | lib/libc_r/uthread/uthread_fd.c | 12 | ||||
-rw-r--r-- | lib/libc_r/uthread/uthread_init.c | 20 | ||||
-rw-r--r-- | lib/libkse/thread/thr_init.c | 20 | ||||
-rw-r--r-- | lib/libkse/thread/thr_private.h | 6 | ||||
-rw-r--r-- | lib/libpthread/thread/thr_init.c | 20 | ||||
-rw-r--r-- | lib/libpthread/thread/thr_private.h | 6 |
7 files changed, 51 insertions, 39 deletions
diff --git a/lib/libc_r/uthread/pthread_private.h b/lib/libc_r/uthread/pthread_private.h index d6a6eb1..65203d5 100644 --- a/lib/libc_r/uthread/pthread_private.h +++ b/lib/libc_r/uthread/pthread_private.h @@ -20,7 +20,7 @@ * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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) @@ -31,7 +31,7 @@ * * Private thread definitions for the uthread kernel. * - * $Id: pthread_private.h,v 1.23 1999/07/11 05:56:35 jasone Exp $ + * $Id: pthread_private.h,v 1.24 1999/07/12 16:09:30 dt Exp $ */ #ifndef _PTHREAD_PRIVATE_H @@ -817,7 +817,7 @@ SCLASS const int dtablecount #endif SCLASS int _thread_dtablesize /* Descriptor table size. */ #ifdef GLOBAL_PTHREAD_PRIVATE -= 1024; += 0; #else ; #endif diff --git a/lib/libc_r/uthread/uthread_fd.c b/lib/libc_r/uthread/uthread_fd.c index f0c973b..6040a7b 100644 --- a/lib/libc_r/uthread/uthread_fd.c +++ b/lib/libc_r/uthread/uthread_fd.c @@ -20,7 +20,7 @@ * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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) @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_fd.c,v 1.10 1999/03/23 05:07:55 jb Exp $ + * $Id: uthread_fd.c,v 1.11 1999/06/20 08:28:18 jb Exp $ * */ #include <errno.h> @@ -94,13 +94,13 @@ _thread_fd_table_init(int fd) TAILQ_INIT(&entry->w_queue); /* Get the flags for the file: */ - if (fd >= 3 && (entry->flags = - _thread_sys_fcntl(fd, F_GETFL, 0)) == -1) { + if (((fd >= 3) || (_pthread_stdio_flags[fd] == -1)) && + (entry->flags = _thread_sys_fcntl(fd, F_GETFL, 0)) == -1) { ret = -1; - } + } else { /* Check if a stdio descriptor: */ - if (fd < 3) + if ((fd < 3) && (_pthread_stdio_flags[fd] != -1)) /* * Use the stdio flags read by * _pthread_init() to avoid diff --git a/lib/libc_r/uthread/uthread_init.c b/lib/libc_r/uthread/uthread_init.c index 90a91cc..c80427a 100644 --- a/lib/libc_r/uthread/uthread_init.c +++ b/lib/libc_r/uthread/uthread_init.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_init.c,v 1.15 1999/07/11 05:56:37 jasone Exp $ + * $Id: uthread_init.c,v 1.16 1999/07/12 16:09:30 dt Exp $ */ /* Allocate space for global thread variables here: */ @@ -124,8 +124,9 @@ _thread_init(void) /* Get the standard I/O flags before messing with them : */ for (i = 0; i < 3; i++) - if ((_pthread_stdio_flags[i] = - _thread_sys_fcntl(i,F_GETFL, NULL)) == -1) + if (((_pthread_stdio_flags[i] = + _thread_sys_fcntl(i,F_GETFL, NULL)) == -1) && + (errno != EBADF)) PANIC("Cannot get stdio flags"); /* @@ -282,6 +283,9 @@ _thread_init(void) } /* Allocate memory for the file descriptor table: */ if ((_thread_fd_table = (struct fd_table_entry **) malloc(sizeof(struct fd_table_entry *) * _thread_dtablesize)) == NULL) { + /* Avoid accesses to file descriptor table on exit: */ + _thread_dtablesize = 0; + /* * Cannot allocate memory for the file descriptor * table, so abort this process. @@ -306,11 +310,11 @@ _thread_init(void) } /* Initialize stdio file descriptor table entries: */ - if ((_thread_fd_table_init(0) != 0) || - (_thread_fd_table_init(1) != 0) || - (_thread_fd_table_init(2) != 0)) { - PANIC("Cannot initialize stdio file descriptor " - "table entries"); + for (i = 0; i < 3; i++) { + if ((_thread_fd_table_init(i) != 0) && + (errno != EBADF)) + PANIC("Cannot initialize stdio file " + "descriptor table entry"); } } } diff --git a/lib/libkse/thread/thr_init.c b/lib/libkse/thread/thr_init.c index 90a91cc..c80427a 100644 --- a/lib/libkse/thread/thr_init.c +++ b/lib/libkse/thread/thr_init.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_init.c,v 1.15 1999/07/11 05:56:37 jasone Exp $ + * $Id: uthread_init.c,v 1.16 1999/07/12 16:09:30 dt Exp $ */ /* Allocate space for global thread variables here: */ @@ -124,8 +124,9 @@ _thread_init(void) /* Get the standard I/O flags before messing with them : */ for (i = 0; i < 3; i++) - if ((_pthread_stdio_flags[i] = - _thread_sys_fcntl(i,F_GETFL, NULL)) == -1) + if (((_pthread_stdio_flags[i] = + _thread_sys_fcntl(i,F_GETFL, NULL)) == -1) && + (errno != EBADF)) PANIC("Cannot get stdio flags"); /* @@ -282,6 +283,9 @@ _thread_init(void) } /* Allocate memory for the file descriptor table: */ if ((_thread_fd_table = (struct fd_table_entry **) malloc(sizeof(struct fd_table_entry *) * _thread_dtablesize)) == NULL) { + /* Avoid accesses to file descriptor table on exit: */ + _thread_dtablesize = 0; + /* * Cannot allocate memory for the file descriptor * table, so abort this process. @@ -306,11 +310,11 @@ _thread_init(void) } /* Initialize stdio file descriptor table entries: */ - if ((_thread_fd_table_init(0) != 0) || - (_thread_fd_table_init(1) != 0) || - (_thread_fd_table_init(2) != 0)) { - PANIC("Cannot initialize stdio file descriptor " - "table entries"); + for (i = 0; i < 3; i++) { + if ((_thread_fd_table_init(i) != 0) && + (errno != EBADF)) + PANIC("Cannot initialize stdio file " + "descriptor table entry"); } } } diff --git a/lib/libkse/thread/thr_private.h b/lib/libkse/thread/thr_private.h index d6a6eb1..65203d5 100644 --- a/lib/libkse/thread/thr_private.h +++ b/lib/libkse/thread/thr_private.h @@ -20,7 +20,7 @@ * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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) @@ -31,7 +31,7 @@ * * Private thread definitions for the uthread kernel. * - * $Id: pthread_private.h,v 1.23 1999/07/11 05:56:35 jasone Exp $ + * $Id: pthread_private.h,v 1.24 1999/07/12 16:09:30 dt Exp $ */ #ifndef _PTHREAD_PRIVATE_H @@ -817,7 +817,7 @@ SCLASS const int dtablecount #endif SCLASS int _thread_dtablesize /* Descriptor table size. */ #ifdef GLOBAL_PTHREAD_PRIVATE -= 1024; += 0; #else ; #endif diff --git a/lib/libpthread/thread/thr_init.c b/lib/libpthread/thread/thr_init.c index 90a91cc..c80427a 100644 --- a/lib/libpthread/thread/thr_init.c +++ b/lib/libpthread/thread/thr_init.c @@ -29,7 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: uthread_init.c,v 1.15 1999/07/11 05:56:37 jasone Exp $ + * $Id: uthread_init.c,v 1.16 1999/07/12 16:09:30 dt Exp $ */ /* Allocate space for global thread variables here: */ @@ -124,8 +124,9 @@ _thread_init(void) /* Get the standard I/O flags before messing with them : */ for (i = 0; i < 3; i++) - if ((_pthread_stdio_flags[i] = - _thread_sys_fcntl(i,F_GETFL, NULL)) == -1) + if (((_pthread_stdio_flags[i] = + _thread_sys_fcntl(i,F_GETFL, NULL)) == -1) && + (errno != EBADF)) PANIC("Cannot get stdio flags"); /* @@ -282,6 +283,9 @@ _thread_init(void) } /* Allocate memory for the file descriptor table: */ if ((_thread_fd_table = (struct fd_table_entry **) malloc(sizeof(struct fd_table_entry *) * _thread_dtablesize)) == NULL) { + /* Avoid accesses to file descriptor table on exit: */ + _thread_dtablesize = 0; + /* * Cannot allocate memory for the file descriptor * table, so abort this process. @@ -306,11 +310,11 @@ _thread_init(void) } /* Initialize stdio file descriptor table entries: */ - if ((_thread_fd_table_init(0) != 0) || - (_thread_fd_table_init(1) != 0) || - (_thread_fd_table_init(2) != 0)) { - PANIC("Cannot initialize stdio file descriptor " - "table entries"); + for (i = 0; i < 3; i++) { + if ((_thread_fd_table_init(i) != 0) && + (errno != EBADF)) + PANIC("Cannot initialize stdio file " + "descriptor table entry"); } } } diff --git a/lib/libpthread/thread/thr_private.h b/lib/libpthread/thread/thr_private.h index d6a6eb1..65203d5 100644 --- a/lib/libpthread/thread/thr_private.h +++ b/lib/libpthread/thread/thr_private.h @@ -20,7 +20,7 @@ * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 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) @@ -31,7 +31,7 @@ * * Private thread definitions for the uthread kernel. * - * $Id: pthread_private.h,v 1.23 1999/07/11 05:56:35 jasone Exp $ + * $Id: pthread_private.h,v 1.24 1999/07/12 16:09:30 dt Exp $ */ #ifndef _PTHREAD_PRIVATE_H @@ -817,7 +817,7 @@ SCLASS const int dtablecount #endif SCLASS int _thread_dtablesize /* Descriptor table size. */ #ifdef GLOBAL_PTHREAD_PRIVATE -= 1024; += 0; #else ; #endif |