X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fdaemon.c;h=2893a905f90c1f05de7eb85f2332dd0cd2605439;hb=8da81d42c7b31191c175aa0a8a9439b66594f3c3;hp=52c2afd86a6357475ef292d6e5136abd69a222df;hpb=495ea2c13cfb00bd74c3021250ce6ddb99fe04dc;p=openldap diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 52c2afd86a..2893a905f9 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2004 The OpenLDAP Foundation. + * Copyright 1998-2005 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,9 +40,9 @@ #include "ldap_rq.h" -#define HAVE_EPOLL 1 +#undef HAVE_EPOLL -#ifdef HAVE_EPOLL +#if defined(HAVE_SYS_EPOLL_H) && defined(HAVE_EPOLL) #include #endif @@ -72,6 +72,7 @@ int slap_inet4or6 = AF_INET; time_t starttime; ber_socket_t dtblsize; slap_ssf_t local_ssf = LDAP_PVT_SASL_LOCAL_SSF; +struct runqueue_s slapd_rq; Listener **slap_listeners = NULL; @@ -82,7 +83,7 @@ static int emfile; static int waking; #define WAKE_LISTENER(w) \ -do { if (w && waking < 5) { tcp_write( wake_sds[1], "0", 1 ); waking++;} } while(0) +do { if (w && waking < 5) { waking++; tcp_write( wake_sds[1], "0", 1 ); } } while(0) volatile sig_atomic_t slapd_shutdown = 0, slapd_gentle_shutdown = 0; volatile sig_atomic_t slapd_abrupt_shutdown = 0; @@ -117,7 +118,6 @@ static struct slap_daemon { #define SLAP_EVENTS_ARE_INDEXED 0 #define SLAP_SOCK_IX(s) (slap_daemon.sd_index[s]) #define SLAP_SOCK_EP(s) (slap_daemon.sd_epolls[SLAP_SOCK_IX(s)]) -#define SLAP_SOCK_FD(s) (SLAP_SOCK_EP(s).data.fd) #define SLAP_SOCK_EV(s) (SLAP_SOCK_EP(s).events) #define SLAP_SOCK_IS_ACTIVE(s) (SLAP_SOCK_IX(s) != -1) #define SLAP_SOCK_NOT_ACTIVE(s) (SLAP_SOCK_IX(s) == -1) @@ -140,7 +140,7 @@ static struct slap_daemon { epoll_ctl(slap_daemon.sd_epfd, EPOLL_CTL_MOD, s, \ &SLAP_SOCK_EP(s)); \ } \ -} while(0) \ +} while(0) #define SLAP_SOCK_SET_READ(s) SLAP_SET_SOCK(s, EPOLLIN) #define SLAP_SOCK_SET_WRITE(s) SLAP_SET_SOCK(s, EPOLLOUT) @@ -155,7 +155,8 @@ static struct slap_daemon { /* If a Listener address is provided, store that as the epoll data. * Otherwise, store the address of this socket's slot in the - * index array. + * index array. If we can't do this add, the system is out of + * resources and we need to shutdown. */ #define SLAP_ADD_SOCK(s, l) do { \ int rc; \ @@ -165,6 +166,11 @@ static struct slap_daemon { rc = epoll_ctl(slap_daemon.sd_epfd, EPOLL_CTL_ADD, s, \ &SLAP_SOCK_EP(s)); \ if ( rc == 0 ) slap_daemon.sd_nfds++; \ + else { \ + Debug( LDAP_DEBUG_ANY, "daemon: epoll_ctl ADD failed, errno %d, shutting down\n", \ + errno, 0, 0 ); \ + slapd_shutdown = 2; \ + } \ } while(0) #define SLAP_EV_LISTENER(ptr) (((int *)(ptr) >= slap_daemon.sd_index && \ @@ -225,7 +231,7 @@ static struct slap_daemon { #define SLAP_EVENT_INIT \ AC_MEMCPY( &readfds, &slap_daemon.sd_readers, sizeof(fd_set) ); \ if ( nwriters ) \ - AC_MEMCPY( &writefds, &slap_daemon.sd_writers, sizeof(fd_set) ); + AC_MEMCPY( &writefds, &slap_daemon.sd_writers, sizeof(fd_set) ) #ifdef FD_SETSIZE #define CHK_SETSIZE \ @@ -972,8 +978,14 @@ static int slap_open_listener( #endif #ifdef LDAP_PF_LOCAL case AF_LOCAL: - addrlen = sizeof(struct sockaddr_un); - break; +#ifdef LOCAL_CREDS + { + int one = 1; + setsockopt(l.sl_sd, 0, LOCAL_CREDS, &one, sizeof one); + } +#endif + addrlen = sizeof(struct sockaddr_un); + break; #endif } @@ -1477,6 +1489,7 @@ slapd_daemon_task( int l; time_t last_idle_check = 0; struct timeval idle; + int ebadf = 0; #define SLAPD_IDLE_CHECK_LIMIT 4 @@ -1567,7 +1580,6 @@ slapd_daemon_task( int at; ber_socket_t nfds, nrfds, nwfds; #define SLAPD_EBADF_LIMIT 16 - int ebadf = 0; time_t now; @@ -1643,24 +1655,24 @@ slapd_daemon_task( else tvp = NULL; - ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex ); - rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat ); + ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); + rtask = ldap_pvt_runqueue_next_sched( &slapd_rq, &cat ); while ( cat && cat->tv_sec && cat->tv_sec <= now ) { - if ( ldap_pvt_runqueue_isrunning( &syncrepl_rq, rtask )) { - ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, 0 ); + if ( ldap_pvt_runqueue_isrunning( &slapd_rq, rtask )) { + ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 ); } else { - ldap_pvt_runqueue_runtask( &syncrepl_rq, rtask ); - ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, 0 ); - ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex ); + ldap_pvt_runqueue_runtask( &slapd_rq, rtask ); + ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 ); + ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); ldap_pvt_thread_pool_submit( &connection_pool, rtask->routine, (void *) rtask ); - ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex ); + ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); } - rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat ); + rtask = ldap_pvt_runqueue_next_sched( &slapd_rq, &cat ); } - ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex ); + ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); - if ( cat != NULL ) { + if ( cat && cat->tv_sec ) { time_t diff = difftime( cat->tv_sec, now ); if ( diff == 0 ) diff = tdelta; @@ -1708,10 +1720,12 @@ slapd_daemon_task( case 0: /* timeout - let threads run */ ebadf = 0; +#ifndef HAVE_YIELDING_SELECT Debug( LDAP_DEBUG_CONNS, "daemon: select timeout - yielding\n", 0, 0, 0 ); ldap_pvt_thread_yield(); +#endif continue; default: /* something happened - deal with it */ @@ -1723,19 +1737,16 @@ slapd_daemon_task( /* FALL THRU */ } - /* We don't need to examine the event status for wake_sds; - * if waking is set and we woke up, we'll read whatever - * we can. - */ - if ( waking ) { +#if SLAP_EVENTS_ARE_INDEXED + if ( SLAP_EVENT_IS_READ( wake_sds[0] )) { char c[BUFSIZ]; tcp_read( wake_sds[0], c, sizeof(c) ); waking = 0; ns--; + SLAP_EVENT_CLR_READ( wake_sds[0] ); continue; } -#if SLAP_EVENTS_ARE_INDEXED /* The event slot equals the descriptor number - this is * true for Unix select and poll. We treat Windows select * like this too, even though it's a kludge. @@ -1767,7 +1778,9 @@ slapd_daemon_task( /* bypass the following tests if no descriptors left */ if ( ns <= 0 ) { +#ifndef HAVE_YIELDING_SELECT ldap_pvt_thread_yield(); +#endif continue; } @@ -1841,6 +1854,7 @@ slapd_daemon_task( } slapd_close( wd ); } + SLAP_EVENT_CLR_WRITE( wd ); } for ( i = 0; nrfds > 0; i++ ) @@ -1877,12 +1891,23 @@ slapd_daemon_task( * all other connections last (as we do for select), we would need * to use multiple event handles and cascade them. * - * That seems like a bit of hassle. So the wake_sds check has moved - * above. For epoll and kqueue we can associate arbitrary data with + * That seems like a bit of hassle. So the wake_sds check has been + * skipped. For epoll and kqueue we can associate arbitrary data with * an event, so we could use pointers to the listener structure * instead of just the file descriptor. For /dev/poll we have to * search the listeners array for a matching descriptor. */ + /* if waking is set and we woke up, we'll read whatever + * we can. + */ + if ( waking ) { + char c[BUFSIZ]; + tcp_read( wake_sds[0], c, sizeof(c) ); + waking = 0; + ns--; + continue; + } + #ifdef LDAP_DEBUG Debug( LDAP_DEBUG_CONNS, "daemon: activity on:", 0, 0, 0 ); @@ -1951,7 +1976,9 @@ slapd_daemon_task( } #endif /* SLAP_EVENTS_ARE_INDEXED */ +#ifndef HAVE_YIELDING_SELECT ldap_pvt_thread_yield(); +#endif } if( slapd_shutdown == 1 ) {