void lutil_CommenceStartupProcessing( char *lpszServiceName, void (*stopper)(int) ) { hlutil_ServiceStatus = RegisterServiceCtrlHandler( lpszServiceName, (LPHANDLER_FUNCTION)lutil_ServiceCtrlHandler); stopfunc = stopper; /* initialize the Service Status structure */ lutil_ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; lutil_ServiceStatus.dwCurrentState = SERVICE_START_PENDING; lutil_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; lutil_ServiceStatus.dwWin32ExitCode = NO_ERROR; lutil_ServiceStatus.dwServiceSpecificExitCode = 0; lutil_ServiceStatus.dwCheckPoint = 1; lutil_ServiceStatus.dwWaitHint = SCM_NOTIFICATION_INTERVAL * 2; SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus); /* start up a thread to keep sending SERVICE_START_PENDING to the Service Control Manager * until the slapd listener is completed and listening. Only then should we send * SERVICE_RUNNING to the Service Control Manager. */ ldap_pvt_thread_cond_init( &started_event ); if ( started_event == NULL) { /* failed to create the event to determine when the startup process is complete so * tell the Service Control Manager to wait another 30 seconds before deploying its * assasin */ lutil_ServiceStatus.dwCheckPoint++; lutil_ServiceStatus.dwWaitHint = THIRTY_SECONDS; SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus); } else { /* start a thread to report the progress to the service control manager * until the started_event is fired. */ if ( ldap_pvt_thread_create( &start_status_tid, 0, start_status_routine, NULL ) == 0 ) { } else { /* failed to create the thread that tells the Service Control Manager that the * service startup is proceeding. * tell the Service Control Manager to wait another 30 seconds before deploying its * assasin. */ lutil_ServiceStatus.dwCheckPoint++; lutil_ServiceStatus.dwWaitHint = THIRTY_SECONDS; SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus); } } }
void WINAPI lutil_ServiceCtrlHandler( IN DWORD Opcode) { switch (Opcode) { case SERVICE_CONTROL_STOP: case SERVICE_CONTROL_SHUTDOWN: lutil_ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING; lutil_ServiceStatus.dwCheckPoint++; lutil_ServiceStatus.dwWaitHint = SCM_NOTIFICATION_INTERVAL * 2; SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus); ldap_pvt_thread_cond_init( &stopped_event ); if ( stopped_event == NULL ) { /* the event was not created. We will ask the service control manager for 30 * seconds to shutdown */ lutil_ServiceStatus.dwCheckPoint++; lutil_ServiceStatus.dwWaitHint = THIRTY_SECONDS; SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus); } else { /* start a thread to report the progress to the service control manager * until the stopped_event is fired. */ if ( ldap_pvt_thread_create( &stop_status_tid, 0, stop_status_routine, NULL ) == 0 ) { } else { /* failed to create the thread that tells the Service Control Manager that the * service stopping is proceeding. * tell the Service Control Manager to wait another 30 seconds before deploying its * assasin. */ lutil_ServiceStatus.dwCheckPoint++; lutil_ServiceStatus.dwWaitHint = THIRTY_SECONDS; SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus); } } stopfunc( -1 ); break; case SERVICE_CONTROL_INTERROGATE: SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus); break; } return; }
int slapd_daemon( void ) { int rc; connections_init(); #define SLAPD_LISTENER_THREAD 1 #if defined( SLAPD_LISTENER_THREAD ) { ldap_pvt_thread_t listener_tid; /* listener as a separate THREAD */ rc = ldap_pvt_thread_create( &listener_tid, 0, slapd_daemon_task, NULL ); if ( rc != 0 ) { #ifdef NEW_LOGGING LDAP_LOG( CONNECTION, ERR, "slapd_daemon: listener ldap_pvt_thread_create failed (%d).\n", rc, 0, 0 ); #else Debug( LDAP_DEBUG_ANY, "listener ldap_pvt_thread_create failed (%d)\n", rc, 0, 0 ); #endif return rc; } /* wait for the listener thread to complete */ ldap_pvt_thread_join( listener_tid, (void *) NULL ); } #else /* experimental code */ slapd_daemon_task( NULL ); #endif return 0; }
static int do_time( ) { struct timeval tv; time_t now, prevt, start; int r1new, r2new; int dt, dr1, dr2, rr1, rr2; int dr10, dr20; int i; gethostname(hname, sizeof(hname)); printf("%s(tid)\tdeltaT\tauth1\tauth2\trate1\trate2\tRate1+2\n", hname); srand(getpid()); prevt = start = time(0L); for ( i = 0; i<threads; i++ ) { ldap_pvt_thread_t thr; r1binds[i] = i; ldap_pvt_thread_create( &thr, 1, my_task, (void *)&r1binds[i] ); } for (;;) { tv.tv_sec = interval; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); now = time(0L); dt = now - prevt; prevt = now; dr10 = 0; dr20 = 0; for ( i = 0; i < threads; i++ ) { r1new = r1binds[i]; r2new = r2binds[i]; dr1 = r1new - r1old[i]; dr2 = r2new - r2old[i]; rr1 = dr1 / dt; rr2 = dr2 / dt; printf("%s(%d)\t%d\t%d\t%d\t%d\t%d\t%d\n", hname, i, dt, dr1, dr2, rr1, rr2, rr1 + rr2); dr10 += dr1; dr20 += dr2; r1old[i] = r1new; r2old[i] = r2new; } if ( i > 1 ) { rr1 = dr10 / dt; rr2 = dr20 / dt; printf("%s(sum)\t%d\t%d\t%d\t%d\t%d\t%d\n", hname, 0, dr10, dr20, rr1, rr2, rr1 + rr2); } if ( now - start >= tdur ) { finish = 1; break; } } return 0; }
int main( int argc, char **argv ) { int i; char *uri = NULL; char *host = "localhost"; int port = -1; char *manager = NULL; struct berval passwd = { 0, NULL }; char outstr[BUFSIZ]; int ptpass; int testfail = 0; tester_init( "slapd-mtread", TESTER_READ ); /* by default, tolerate referrals and no such object */ tester_ignore_str2errlist( "REFERRAL,NO_SUCH_OBJECT" ); while ( (i = getopt( argc, argv, "ACc:D:e:Ff:H:h:i:L:l:M:m:p:r:t:T:w:v" )) != EOF ) { switch ( i ) { case 'A': noattrs++; break; case 'C': chaserefs++; break; case 'H': /* the server uri */ uri = strdup( optarg ); break; case 'h': /* the servers host */ host = strdup( optarg ); break; case 'i': tester_ignore_str2errlist( optarg ); break; case 'N': nobind++; break; case 'v': verbose++; break; case 'p': /* the servers port */ if ( lutil_atoi( &port, optarg ) != 0 ) { usage( argv[0] ); } break; case 'D': /* the servers manager */ manager = strdup( optarg ); break; case 'w': /* the server managers password */ passwd.bv_val = strdup( optarg ); passwd.bv_len = strlen( optarg ); memset( optarg, '*', passwd.bv_len ); break; case 'c': /* the number of connections */ if ( lutil_atoi( &noconns, optarg ) != 0 ) { usage( argv[0] ); } break; case 'e': /* DN to search for */ entry = strdup( optarg ); break; case 'f': /* the search request */ filter = strdup( optarg ); break; case 'F': force++; break; case 'l': /* the number of loops */ if ( lutil_atoi( &loops, optarg ) != 0 ) { usage( argv[0] ); } break; case 'L': /* the number of outerloops */ if ( lutil_atoi( &outerloops, optarg ) != 0 ) { usage( argv[0] ); } break; case 'M': /* the number of R/W threads */ if ( lutil_atoi( &rwthreads, optarg ) != 0 ) { usage( argv[0] ); } if (rwthreads > MAX_THREAD) rwthreads = MAX_THREAD; break; case 'm': /* the number of threads */ if ( lutil_atoi( &threads, optarg ) != 0 ) { usage( argv[0] ); } if (threads > MAX_THREAD) threads = MAX_THREAD; break; case 'r': /* the number of retries */ if ( lutil_atoi( &retries, optarg ) != 0 ) { usage( argv[0] ); } break; case 't': /* delay in seconds */ if ( lutil_atoi( &delay, optarg ) != 0 ) { usage( argv[0] ); } break; case 'T': attrs = ldap_str2charray( optarg, "," ); if ( attrs == NULL ) { usage( argv[0] ); } break; default: usage( argv[0] ); break; } } if (( entry == NULL ) || ( port == -1 && uri == NULL )) usage( argv[0] ); if ( *entry == '\0' ) { fprintf( stderr, "%s: invalid EMPTY entry DN.\n", argv[0] ); exit( EXIT_FAILURE ); } if ( argv[optind] != NULL ) { attrs = &argv[optind]; } if (noconns < 1) noconns = 1; if (noconns > MAXCONN) noconns = MAXCONN; lds = (LDAP **) calloc( sizeof(LDAP *), noconns); if (lds == NULL) { fprintf( stderr, "%s: Memory error: calloc noconns.\n", argv[0] ); exit( EXIT_FAILURE ); } uri = tester_uri( uri, host, port ); /* One connection and one connection only */ do_conn( uri, manager, &passwd, &ld, nobind, retries, 0 ); lds[0] = ld; for(i = 1; i < noconns; i++) { do_conn( uri, manager, &passwd, &lds[i], nobind, retries, i ); } ldap_pvt_thread_initialize(); snprintf(outstr, BUFSIZ, "MT Test Start: conns: %d (%s)", noconns, uri); tester_error(outstr); snprintf(outstr, BUFSIZ, "Threads: RO: %d RW: %d", threads, rwthreads); tester_error(outstr); /* Set up read only threads */ for ( i = 0; i < threads; i++ ) { ldap_pvt_thread_create( &rtid[i], 0, do_onethread, &rtid[i]); snprintf(outstr, BUFSIZ, "Created RO thread %d", i); thread_verbose(-1, outstr); } /* Set up read/write threads */ for ( i = 0; i < rwthreads; i++ ) { ldap_pvt_thread_create( &rwtid[i], 0, do_onerwthread, &rwtid[i]); snprintf(outstr, BUFSIZ, "Created RW thread %d", i + MAX_THREAD); thread_verbose(-1, outstr); } ptpass = outerloops * loops; /* wait for read only threads to complete */ for ( i = 0; i < threads; i++ ) ldap_pvt_thread_join(rtid[i], NULL); /* wait for read/write threads to complete */ for ( i = 0; i < rwthreads; i++ ) ldap_pvt_thread_join(rwtid[i], NULL); for(i = 0; i < noconns; i++) { if ( lds[i] != NULL ) { ldap_unbind_ext( lds[i], NULL, NULL ); } } free( lds ); for ( i = 0; i < threads; i++ ) { snprintf(outstr, BUFSIZ, "RO thread %d pass=%d fail=%d", i, rt_pass[i], rt_fail[i]); tester_error(outstr); if (rt_fail[i] != 0 || rt_pass[i] != ptpass) { snprintf(outstr, BUFSIZ, "FAIL RO thread %d", i); tester_error(outstr); testfail++; } } for ( i = 0; i < rwthreads; i++ ) { snprintf(outstr, BUFSIZ, "RW thread %d pass=%d fail=%d", i + MAX_THREAD, rwt_pass[i], rwt_fail[i]); tester_error(outstr); if (rwt_fail[i] != 0 || rwt_pass[i] != ptpass) { snprintf(outstr, BUFSIZ, "FAIL RW thread %d", i); tester_error(outstr); testfail++; } } snprintf(outstr, BUFSIZ, "MT Test complete" ); tester_error(outstr); if (testfail) exit( EXIT_FAILURE ); exit( EXIT_SUCCESS ); }