From f3e9bc606c51dee5f224cb9734650937bf94f7c9 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Thu, 13 Aug 1998 19:32:43 +0000 Subject: [PATCH] integrated changed from rage.net glibc.patch --- clients/ud/main.c | 3 ++- include/lthread.h | 12 ++++++++++++ include/portable.h | 2 +- libraries/liblthread/thread.c | 10 ++++++++++ servers/slapd/charray.c | 6 +++++- servers/slapd/connection.c | 2 +- servers/slapd/daemon.c | 22 +++++++++++++++++++++- servers/slapd/main.c | 4 ++-- servers/slapd/result.c | 4 ++++ servers/slurpd/fm.c | 20 ++++++++++++++++++-- servers/slurpd/main.c | 2 +- servers/slurpd/replica.c | 2 +- servers/slurpd/ri.c | 12 +++++++++++- 13 files changed, 89 insertions(+), 12 deletions(-) diff --git a/clients/ud/main.c b/clients/ud/main.c index 86c0b7567f..be9508dba9 100644 --- a/clients/ud/main.c +++ b/clients/ud/main.c @@ -33,7 +33,8 @@ #include #endif /* defined( NeXT ) || defined( ultrix ) etc. */ #endif /* !DOS */ -#if defined( aix ) || defined( __NetBSD__ ) +#if defined( aix ) || defined( __NetBSD__ ) \ + || defined( __FreeBSD__ ) || defined( linux ) #include #endif /* aix || __NetBSD__ */ #include diff --git a/include/lthread.h b/include/lthread.h index 4a3b0a8072..d712a5e593 100644 --- a/include/lthread.h +++ b/include/lthread.h @@ -160,6 +160,18 @@ typedef cond_t pthread_cond_t; #define pthread_attr_setdetachstate( a, b ) \ pthread_attr_setdetach_np( a, b ) +#else /* end dce pthreads */ + +#if defined( POSIX_THREADS ) + +#define _THREAD + +#include + +#define pthread_mutexattr_default NULL +#define pthread_condattr_default NULL + +#endif /* posix threads */ #endif /* dce pthreads */ #endif /* mit pthreads */ #endif /* sunos5 */ diff --git a/include/portable.h b/include/portable.h index 0b855b1da0..48838109ad 100644 --- a/include/portable.h +++ b/include/portable.h @@ -120,7 +120,7 @@ * Are sys_errlist and sys_nerr declared in stdio.h? */ #ifndef SYSERRLIST_IN_STDIO -#if defined( freebsd ) || defined( linux ) +#if defined( freebsd ) || defined( __GLIBC__ ) && ( __GLIBC__ > 1 ) #define SYSERRLIST_IN_STDIO #endif #endif diff --git a/libraries/liblthread/thread.c b/libraries/liblthread/thread.c index 47d878ac76..f6e516f505 100644 --- a/libraries/liblthread/thread.c +++ b/libraries/liblthread/thread.c @@ -483,6 +483,16 @@ pthread_kill( pthread_t tid, int sig ) kill( getpid(), sig ); } +#else + +#if defined ( POSIX_THREADS ) + +void p_thread_yield( void ) +{ + sched_yield(); +} + +#endif /* posix threads */ #endif /* dce pthreads */ #endif /* mit pthreads */ #endif /* sunos5 lwp */ diff --git a/servers/slapd/charray.c b/servers/slapd/charray.c index b731cf1e90..e3b4d37feb 100644 --- a/servers/slapd/charray.c +++ b/servers/slapd/charray.c @@ -107,12 +107,15 @@ charray_dup( char **a ) } char ** -str2charray( char *str, char *brkstr ) +str2charray( char *str_in, char *brkstr ) { char **res; char *s; int i; + /* protect the input string from strtok */ + char *str = strdup( str_in ); + i = 1; for ( s = str; *s; s++ ) { if ( strchr( brkstr, *s ) != NULL ) { @@ -128,5 +131,6 @@ str2charray( char *str, char *brkstr ) } res[i] = NULL; + free( str ); return( res ); } diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 5c3ebdf708..df5618ad70 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -203,7 +203,7 @@ connection_activity( pthread_attr_init( &attr ); pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED ); - if ( pthread_create( &arg->co_op->o_tid, attr, + if ( pthread_create( &arg->co_op->o_tid, &attr, (void *) connection_operation, (void *) arg ) != 0 ) { Debug( LDAP_DEBUG_ANY, "pthread_create failed\n", 0, 0, 0 ); } else { diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 8d35debc81..c2006d398a 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -139,8 +139,16 @@ daemon( } (void) SIGNAL( SIGPIPE, SIG_IGN ); +#ifdef SIGSTKFLT + (void) SIGNAL( SIGSTKFLT, (void *) do_nothing ); +#else (void) SIGNAL( SIGUSR1, (void *) do_nothing ); +#endif +#ifdef SIGSTKFLT + (void) SIGNAL( SIGUNUSED, (void *) set_shutdown ); +#else (void) SIGNAL( SIGUSR2, (void *) set_shutdown ); +#endif (void) SIGNAL( SIGTERM, (void *) set_shutdown ); (void) SIGNAL( SIGINT, (void *) set_shutdown ); (void) SIGNAL( SIGHUP, (void *) set_shutdown ); @@ -365,8 +373,16 @@ set_shutdown() { Debug( LDAP_DEBUG_ANY, "slapd got shutdown signal\n", 0, 0, 0 ); slapd_shutdown = 1; +#ifdef SIGSTKFLT + pthread_kill( listener_tid, SIGSTKFLT ); +#else pthread_kill( listener_tid, SIGUSR1 ); +#endif +#ifdef SIGUNUSED + (void) SIGNAL( SIGUNUSED, (void *) set_shutdown ); +#else (void) SIGNAL( SIGUSR2, (void *) set_shutdown ); +#endif (void) SIGNAL( SIGTERM, (void *) set_shutdown ); (void) SIGNAL( SIGINT, (void *) set_shutdown ); (void) SIGNAL( SIGHUP, (void *) set_shutdown ); @@ -375,6 +391,10 @@ set_shutdown() static void do_nothing() { - Debug( LDAP_DEBUG_TRACE, "slapd got SIGUSR1\n", 0, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "slapd got do_nothing signal\n", 0, 0, 0 ); +#ifdef SIGSTKFLT + (void) SIGNAL( SIGSTKFLT, (void *) do_nothing ); +#else (void) SIGNAL( SIGUSR1, (void *) do_nothing ); +#endif } diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 01930b9709..70b21821b0 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -10,7 +10,7 @@ #include "slap.h" #include "ldapconfig.h" -extern void daemon(); +extern void slapd_daemon(); extern int lber_debug; extern char Versionstr[]; @@ -184,7 +184,7 @@ main( argc, argv ) pthread_attr_init( &attr ); pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED ); - if ( pthread_create( &listener_tid, attr, (void *) daemon, + if ( pthread_create( &listener_tid, &attr, (void *) slapd_daemon, (void *) port ) != 0 ) { Debug( LDAP_DEBUG_ANY, "listener pthread_create failed\n", 0, 0, 0 ); diff --git a/servers/slapd/result.c b/servers/slapd/result.c index 0ef82a7b3e..cdac39a0ab 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -121,7 +121,11 @@ send_ldap_result2( pthread_mutex_lock( &active_threads_mutex ); active_threads--; conn->c_writewaiter = 1; +#ifdef SIGSTKFLT + pthread_kill( listener_tid, SIGSTKFLT ); +#else pthread_kill( listener_tid, SIGUSR1 ); +#endif pthread_cond_wait( &conn->c_wcv, &active_threads_mutex ); pthread_mutex_unlock( &active_threads_mutex ); diff --git a/servers/slurpd/fm.c b/servers/slurpd/fm.c index 2d36838bb5..e5c0267e9f 100644 --- a/servers/slurpd/fm.c +++ b/servers/slurpd/fm.c @@ -77,12 +77,20 @@ fm( /* Set up our signal handlers: * SIG{TERM,INT,HUP} causes a shutdown - * SIGUSR1 - does nothing, used to wake up sleeping threads. - * SIGUSR2 - causes slurpd to read its administrative interface file. + * SIG(STKFLT|USR1) - does nothing, used to wake up sleeping threads. + * SIG(UNUSED|USR2) - causes slurpd to read its administrative interface file. * (not yet implemented). */ +#ifdef SIGSTKFLT + (void) SIGNAL( SIGSTKFLT, (void *) do_nothing ); +#else (void) SIGNAL( SIGUSR1, (void *) do_nothing ); +#endif +#ifdef SIGUNUSED + (void) SIGNAL( SIGUNUSED, (void *) do_admin ); +#else (void) SIGNAL( SIGUSR2, (void *) do_admin ); +#endif (void) SIGNAL( SIGTERM, (void *) set_shutdown ); (void) SIGNAL( SIGINT, (void *) set_shutdown ); (void) SIGNAL( SIGHUP, (void *) set_shutdown ); @@ -160,7 +168,11 @@ set_shutdown() int i; sglob->slurpd_shutdown = 1; /* set flag */ +#ifdef SIGSTKFLT + pthread_kill( sglob->fm_tid, SIGSTKFLT ); /* wake up file mgr */ +#else pthread_kill( sglob->fm_tid, SIGUSR1 ); /* wake up file mgr */ +#endif sglob->rq->rq_lock( sglob->rq ); /* lock queue */ pthread_cond_broadcast( &(sglob->rq->rq_more) ); /* wake repl threads */ for ( i = 0; i < sglob->num_replicas; i++ ) { @@ -181,7 +193,11 @@ set_shutdown() void do_nothing() { +#ifdef SIGSTKFLT + (void) SIGNAL( SIGSTKFLT, (void *) do_nothing ); +#else (void) SIGNAL( SIGUSR1, (void *) do_nothing ); +#endif } diff --git a/servers/slurpd/main.c b/servers/slurpd/main.c index a3b935faa5..98ffb2917c 100644 --- a/servers/slurpd/main.c +++ b/servers/slurpd/main.c @@ -121,7 +121,7 @@ main( * Start the main file manager thread (in fm.c). */ pthread_attr_init( &attr ); - if ( pthread_create( &(sglob->fm_tid), attr, (void *) fm, (void *) NULL ) + if ( pthread_create( &(sglob->fm_tid), &attr, (void *) fm, (void *) NULL ) != 0 ) { Debug( LDAP_DEBUG_ANY, "file manager pthread_create failed\n", 0, 0, 0 ); diff --git a/servers/slurpd/replica.c b/servers/slurpd/replica.c index ed25a62907..ce878390fd 100644 --- a/servers/slurpd/replica.c +++ b/servers/slurpd/replica.c @@ -59,7 +59,7 @@ start_replica_thread( pthread_attr_init( &attr ); pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED ); - if ( pthread_create( &(ri->ri_tid), attr, (void *) replicate, + if ( pthread_create( &(ri->ri_tid), &attr, (void *) replicate, (void *) ri ) != 0 ) { Debug( LDAP_DEBUG_ANY, "replica \"%s:%d\" pthread_create failed\n", ri->ri_hostname, ri->ri_port, 0 ); diff --git a/servers/slurpd/ri.c b/servers/slurpd/ri.c index cc478d1e6a..40d75eac79 100644 --- a/servers/slurpd/ri.c +++ b/servers/slurpd/ri.c @@ -60,7 +60,11 @@ Ri_process( int rc ; char *errmsg; +#ifdef SIGSTKFLT + (void) SIGNAL( SIGSTKFLT, (void *) do_nothing ); +#else (void) SIGNAL( SIGUSR1, (void *) do_nothing ); +#endif (void) SIGNAL( SIGPIPE, SIG_IGN ); if ( ri == NULL ) { Debug( LDAP_DEBUG_ANY, "Error: Ri_process: ri == NULL!\n", 0, 0, 0 ); @@ -146,7 +150,8 @@ Ri_process( /* - * Wake a replication thread which may be sleeping. Send it a SIGUSR1. + * Wake a replication thread which may be sleeping. + * Send it a SIG(STKFLT|USR1). */ static void Ri_wake( @@ -156,8 +161,13 @@ Ri_wake( if ( ri == NULL ) { return; } +#ifdef SIGSTKFLT + pthread_kill( ri->ri_tid, SIGSTKFLT ); + (void) SIGNAL( SIGSTKFLT, (void *) do_nothing ); +#else pthread_kill( ri->ri_tid, SIGUSR1 ); (void) SIGNAL( SIGUSR1, (void *) do_nothing ); +#endif } -- 2.39.5