Ejemplo n.º 1
0
int 
ldap_pvt_thread_rdwr_init( ldap_pvt_thread_rdwr_t *rwlock )
{
	struct ldap_int_thread_rdwr_s *rw;

	assert( rwlock != NULL );

	rw = (struct ldap_int_thread_rdwr_s *) LDAP_CALLOC( 1,
		sizeof( struct ldap_int_thread_rdwr_s ) );
	if ( !rw )
		return LDAP_NO_MEMORY;

	/* we should check return results */
	ldap_pvt_thread_mutex_init( &rw->ltrw_mutex );
	ldap_pvt_thread_cond_init( &rw->ltrw_read );
	ldap_pvt_thread_cond_init( &rw->ltrw_write );

	rw->ltrw_valid = LDAP_PVT_THREAD_RDWR_VALID;

	*rwlock = rw;
	return 0;
}
Ejemplo n.º 2
0
int mdb_tool_entry_open(
	BackendDB *be, int mode )
{
	/* In Quick mode, commit once per 500 entries */
	mdb_writes = 0;
	if ( slapMode & SLAP_TOOL_QUICK )
		mdb_writes_per_commit = MDB_WRITES_PER_COMMIT;
	else
		mdb_writes_per_commit = 1;

	/* Set up for threaded slapindex */
	if (( slapMode & (SLAP_TOOL_QUICK|SLAP_TOOL_READONLY)) == SLAP_TOOL_QUICK ) {
		if ( !mdb_tool_info ) {
			struct mdb_info *mdb = (struct mdb_info *) be->be_private;
			ldap_pvt_thread_mutex_init( &mdb_tool_index_mutex );
			ldap_pvt_thread_cond_init( &mdb_tool_index_cond_main );
			ldap_pvt_thread_cond_init( &mdb_tool_index_cond_work );
			if ( mdb->mi_nattrs ) {
				int i;
#if 0			/* threaded indexing has no performance advantage */
				mdb_tool_threads = slap_tool_thread_max - 1;
#endif
				if ( mdb_tool_threads > 1 ) {
					mdb_tool_index_rec = ch_calloc( mdb->mi_nattrs, sizeof( IndexRec ));
					mdb_tool_index_tcount = mdb_tool_threads - 1;
					for (i=1; i<mdb_tool_threads; i++) {
						int *ptr = ch_malloc( sizeof( int ));
						*ptr = i;
						ldap_pvt_thread_pool_submit( &connection_pool,
							mdb_tool_index_task, ptr );
					}
					mdb_tool_info = mdb;
				}
			}
		}
	}

	return 0;
}
Ejemplo n.º 3
0
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);
		}
	}
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
int 
ldap_pvt_thread_rmutex_init( ldap_pvt_thread_rmutex_t *rmutex )
{
	struct ldap_int_thread_rmutex_s *rm;

	assert( rmutex != NULL );

	rm = (struct ldap_int_thread_rmutex_s *) LDAP_CALLOC( 1,
		sizeof( struct ldap_int_thread_rmutex_s ) );
	if ( !rm )
		return LDAP_NO_MEMORY;

	/* we should check return results */
	ldap_pvt_thread_mutex_init( &rm->ltrm_mutex );
	ldap_pvt_thread_cond_init( &rm->ltrm_cond );

	rm->ltrm_valid = LDAP_PVT_THREAD_RMUTEX_VALID;

	*rmutex = rm;
	return 0;
}
Ejemplo n.º 6
0
void
slapi_int_connection_init_pb( Slapi_PBlock *pb, ber_tag_t tag )
{
	Connection		*conn;
	Operation		*op;
	ber_len_t		max = sockbuf_max_incoming;

	conn = (Connection *) slapi_ch_calloc( 1, sizeof(Connection) );

	LDAP_STAILQ_INIT( &conn->c_pending_ops );

	op = (Operation *) slapi_ch_calloc( 1, sizeof(OperationBuffer) );
	op->o_hdr = &((OperationBuffer *) op)->ob_hdr;
	op->o_controls = ((OperationBuffer *) op)->ob_controls;

	op->o_callback = (slap_callback *) slapi_ch_calloc( 1, sizeof(slap_callback) );
	op->o_callback->sc_response = slapi_int_response;
	op->o_callback->sc_cleanup = NULL;
	op->o_callback->sc_private = pb;
	op->o_callback->sc_next = NULL;

	conn->c_pending_ops.stqh_first = op;

	/* connection object authorization information */
	conn->c_authtype = LDAP_AUTH_NONE;
	BER_BVZERO( &conn->c_authmech );
	BER_BVZERO( &conn->c_dn );
	BER_BVZERO( &conn->c_ndn );

	conn->c_listener = &slapi_listener;
	ber_dupbv( &conn->c_peer_domain, (struct berval *)&slap_unknown_bv );
	ber_dupbv( &conn->c_peer_name, (struct berval *)&slap_unknown_bv );

	LDAP_STAILQ_INIT( &conn->c_ops );

	BER_BVZERO( &conn->c_sasl_bind_mech );
	conn->c_sasl_authctx = NULL;
	conn->c_sasl_sockctx = NULL;
	conn->c_sasl_extra = NULL;

	conn->c_sb = ber_sockbuf_alloc();

	ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );

	conn->c_currentber = NULL;

	/* should check status of thread calls */
	ldap_pvt_thread_mutex_init( &conn->c_mutex );
	ldap_pvt_thread_mutex_init( &conn->c_write1_mutex );
	ldap_pvt_thread_mutex_init( &conn->c_write2_mutex );
	ldap_pvt_thread_cond_init( &conn->c_write1_cv );
	ldap_pvt_thread_cond_init( &conn->c_write2_cv );

	ldap_pvt_thread_mutex_lock( &conn->c_mutex );

	conn->c_n_ops_received = 0;
	conn->c_n_ops_executing = 0;
	conn->c_n_ops_pending = 0;
	conn->c_n_ops_completed = 0;

	conn->c_n_get = 0;
	conn->c_n_read = 0;
	conn->c_n_write = 0;

	conn->c_protocol = LDAP_VERSION3; 

	conn->c_activitytime = conn->c_starttime = slap_get_time();

	/*
	 * A real connection ID is required, because syncrepl associates
	 * pending CSNs with unique ( connection, operation ) tuples.
	 * Setting a fake connection ID will cause slap_get_commit_csn()
	 * to return a stale value.
	 */
	connection_assign_nextid( conn );

	conn->c_conn_state  = 0x01;	/* SLAP_C_ACTIVE */
	conn->c_struct_state = 0x02;	/* SLAP_C_USED */

	conn->c_ssf = conn->c_transport_ssf = local_ssf;
	conn->c_tls_ssf = 0;

	backend_connection_init( conn );

	conn->c_send_ldap_result = slap_send_ldap_result;
	conn->c_send_search_entry = slap_send_search_entry;
	conn->c_send_ldap_extended = slap_send_ldap_extended;
	conn->c_send_search_reference = slap_send_search_reference;

	/* operation object */
	op->o_tag = tag;
	op->o_protocol = LDAP_VERSION3; 
	BER_BVZERO( &op->o_authmech );
	op->o_time = slap_get_time();
	op->o_do_not_cache = 1;
	op->o_threadctx = ldap_pvt_thread_pool_context();
	op->o_tmpmemctx = NULL;
	op->o_tmpmfuncs = &ch_mfuncs;
	op->o_conn = conn;
	op->o_connid = conn->c_connid;
	op->o_bd = frontendDB;

	/* extensions */
	slapi_int_create_object_extensions( SLAPI_X_EXT_OPERATION, op );
	slapi_int_create_object_extensions( SLAPI_X_EXT_CONNECTION, conn );

	pb->pb_rs = (SlapReply *)slapi_ch_calloc( 1, sizeof(SlapReply) );
	pb->pb_op = op;
	pb->pb_conn = conn;
	pb->pb_intop = 1;

	ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
}