aboutsummaryrefslogtreecommitdiff
path: root/lib/libpthread
diff options
context:
space:
mode:
authorJohn Birrell <jb@FreeBSD.org>1998-09-30 06:29:54 +0000
committerJohn Birrell <jb@FreeBSD.org>1998-09-30 06:29:54 +0000
commit05f3e91279c3769a892dd11d1c779bdbf58aee6d (patch)
tree8add4506824a853c01932ab68d101998b20a51c6 /lib/libpthread
parent54059e9f3f0bf395e5a20208e87e21dd4eab8680 (diff)
downloadsrc-05f3e91279c3769a892dd11d1c779bdbf58aee6d.tar.gz
src-05f3e91279c3769a892dd11d1c779bdbf58aee6d.zip
Use snprintf instead of sprintf to avoid long source file paths from
launching an application into space when someone tries to debug it. The dead thread list now has it's own link pointer, so use that when reporting the grateful dead.
Notes
Notes: svn path=/head/; revision=39806
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/thread/thr_info.c43
1 files changed, 31 insertions, 12 deletions
diff --git a/lib/libpthread/thread/thr_info.c b/lib/libpthread/thread/thr_info.c
index f2e67ac02b4d..07877d167e33 100644
--- a/lib/libpthread/thread/thr_info.c
+++ b/lib/libpthread/thread/thr_info.c
@@ -57,6 +57,7 @@ static const struct s_thread_info thread_info[] = {
{PS_SELECT_WAIT , "Waiting on select"},
{PS_SLEEP_WAIT , "Sleeping"},
{PS_WAIT_WAIT , "Waiting process"},
+ {PS_SIGSUSPEND , "Suspended, waiting for a signal"},
{PS_SIGWAIT , "Waiting for a signal"},
{PS_JOIN , "Waiting to join"},
{PS_SUSPENDED , "Suspended"},
@@ -67,14 +68,15 @@ static const struct s_thread_info thread_info[] = {
void
_thread_dump_info(void)
{
- char s[128];
+ char s[512];
int fd;
int i;
int j;
pthread_t pthread;
/* Open the dump file for append and create it if necessary: */
- if ((fd = _thread_sys_open("/tmp/uthread.dump", O_RDWR | O_CREAT | O_APPEND, 0666)) < 0) {
+ if ((fd = _thread_sys_open("/tmp/uthread.dump",
+ O_RDWR | O_CREAT | O_APPEND, 0666)) < 0) {
/* Can't open the dump file. */
} else {
/* Output a header for active threads: */
@@ -82,14 +84,20 @@ _thread_dump_info(void)
_thread_sys_write(fd, s, strlen(s));
/* Enter a loop to report each thread in the global list: */
- for (pthread = _thread_link_list; pthread != NULL; pthread = pthread->nxt) {
+ for (pthread = _thread_link_list; pthread != NULL;
+ pthread = pthread->nxt) {
/* Find the state: */
- for (j = 0; j < (sizeof(thread_info) / sizeof(struct s_thread_info)) - 1; j++)
+ for (j = 0; j < (sizeof(thread_info) /
+ sizeof(struct s_thread_info)) - 1; j++)
if (thread_info[j].state == pthread->state)
break;
/* Output a record for the current thread: */
- sprintf(s, "--------------------\nThread %p (%s) prio %3d state %s [%s:%d]\n",
- pthread, (pthread->name == NULL) ? "":pthread->name, pthread->pthread_priority, thread_info[j].name,pthread->fname,pthread->lineno);
+ snprintf(s, sizeof(s),
+ "--------------------\nThread %p (%s) prio %3d state %s [%s:%d]\n",
+ pthread, (pthread->name == NULL) ?
+ "":pthread->name, pthread->pthread_priority,
+ thread_info[j].name,
+ pthread->fname,pthread->lineno);
_thread_sys_write(fd, s, strlen(s));
/* Check if this is the running thread: */
@@ -112,13 +120,19 @@ _thread_dump_info(void)
case PS_FDR_WAIT:
case PS_FDW_WAIT:
/* Write the lock details: */
- sprintf(s, "fd %d[%s:%d]", pthread->data.fd.fd, pthread->data.fd.fname, pthread->data.fd.branch);
+ snprintf(s, sizeof(s), "fd %d[%s:%d]",
+ pthread->data.fd.fd,
+ pthread->data.fd.fname,
+ pthread->data.fd.branch);
_thread_sys_write(fd, s, strlen(s));
- sprintf(s, "owner %pr/%pw\n", _thread_fd_table[pthread->data.fd.fd]->r_owner, _thread_fd_table[pthread->data.fd.fd]->w_owner);
+ snprintf(s, sizeof(s), "owner %pr/%pw\n",
+ _thread_fd_table[pthread->data.fd.fd]->r_owner,
+ _thread_fd_table[pthread->data.fd.fd]->w_owner);
_thread_sys_write(fd, s, strlen(s));
break;
case PS_SIGWAIT:
- sprintf(s, "sigmask 0x%08lx\n", (unsigned long)pthread->sigmask);
+ snprintf(s, sizeof(s), "sigmask 0x%08lx\n",
+ (unsigned long)pthread->sigmask);
_thread_sys_write(fd, s, strlen(s));
break;
@@ -146,9 +160,13 @@ _thread_dump_info(void)
* Enter a loop to report each thread in the global
* dead thread list:
*/
- for (pthread = _thread_dead; pthread != NULL; pthread = pthread->nxt) {
+ for (pthread = _thread_dead; pthread != NULL;
+ pthread = pthread->nxt_dead) {
/* Output a record for the current thread: */
- sprintf(s, "Thread %p prio %3d [%s:%d]\n", pthread, pthread->pthread_priority,pthread->fname,pthread->lineno);
+ snprintf(s, sizeof(s),
+ "Thread %p prio %3d [%s:%d]\n",
+ pthread, pthread->pthread_priority,
+ pthread->fname,pthread->lineno);
_thread_sys_write(fd, s, strlen(s));
}
}
@@ -165,7 +183,8 @@ _thread_dump_info(void)
*/
if (_thread_fd_table[i] != NULL) {
/* Report the file descriptor lock status: */
- sprintf(s, "fd[%3d] read owner %p count %d [%s:%d]\n write owner %p count %d [%s:%d]\n",
+ snprintf(s, sizeof(s),
+ "fd[%3d] read owner %p count %d [%s:%d]\n write owner %p count %d [%s:%d]\n",
i,
_thread_fd_table[i]->r_owner,
_thread_fd_table[i]->r_lockcount,