xref: /titanic_54/usr/src/cmd/sendmail/libmilter/handler.c (revision 058561cbaa119a6f2659bc27ef343e1b47266bb2)
17c478bd9Sstevel@tonic-gate /*
2*058561cbSjbeck  *  Copyright (c) 1999-2003, 2006 Sendmail, Inc. and its suppliers.
37c478bd9Sstevel@tonic-gate  *	All rights reserved.
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
67c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
77c478bd9Sstevel@tonic-gate  * the sendmail distribution.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  */
107c478bd9Sstevel@tonic-gate 
117c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
127c478bd9Sstevel@tonic-gate 
137c478bd9Sstevel@tonic-gate #include <sm/gen.h>
14*058561cbSjbeck SM_RCSID("@(#)$Id: handler.c,v 8.38 2006/11/02 02:38:22 ca Exp $")
157c478bd9Sstevel@tonic-gate 
167c478bd9Sstevel@tonic-gate #include "libmilter.h"
177c478bd9Sstevel@tonic-gate 
18*058561cbSjbeck #if !_FFR_WORKERS_POOL
197c478bd9Sstevel@tonic-gate /*
207c478bd9Sstevel@tonic-gate **  HANDLE_SESSION -- Handle a connected session in its own context
217c478bd9Sstevel@tonic-gate **
227c478bd9Sstevel@tonic-gate **	Parameters:
237c478bd9Sstevel@tonic-gate **		ctx -- context structure
247c478bd9Sstevel@tonic-gate **
257c478bd9Sstevel@tonic-gate **	Returns:
267c478bd9Sstevel@tonic-gate **		MI_SUCCESS/MI_FAILURE
277c478bd9Sstevel@tonic-gate */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate int
307c478bd9Sstevel@tonic-gate mi_handle_session(ctx)
317c478bd9Sstevel@tonic-gate 	SMFICTX_PTR ctx;
327c478bd9Sstevel@tonic-gate {
337c478bd9Sstevel@tonic-gate 	int ret;
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate 	if (ctx == NULL)
367c478bd9Sstevel@tonic-gate 		return MI_FAILURE;
377c478bd9Sstevel@tonic-gate 	ctx->ctx_id = (sthread_t) sthread_get_id();
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate 	/*
407c478bd9Sstevel@tonic-gate 	**  Detach so resources are free when the thread returns.
417c478bd9Sstevel@tonic-gate 	**  If we ever "wait" for threads, this call must be removed.
427c478bd9Sstevel@tonic-gate 	*/
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate 	if (pthread_detach(ctx->ctx_id) != 0)
457c478bd9Sstevel@tonic-gate 		ret = MI_FAILURE;
467c478bd9Sstevel@tonic-gate 	else
477c478bd9Sstevel@tonic-gate 		ret = mi_engine(ctx);
487c478bd9Sstevel@tonic-gate 	if (ValidSocket(ctx->ctx_sd))
497c478bd9Sstevel@tonic-gate 	{
507c478bd9Sstevel@tonic-gate 		(void) closesocket(ctx->ctx_sd);
517c478bd9Sstevel@tonic-gate 		ctx->ctx_sd = INVALID_SOCKET;
527c478bd9Sstevel@tonic-gate 	}
537c478bd9Sstevel@tonic-gate 	if (ctx->ctx_reply != NULL)
547c478bd9Sstevel@tonic-gate 	{
557c478bd9Sstevel@tonic-gate 		free(ctx->ctx_reply);
567c478bd9Sstevel@tonic-gate 		ctx->ctx_reply = NULL;
577c478bd9Sstevel@tonic-gate 	}
587c478bd9Sstevel@tonic-gate 	if (ctx->ctx_privdata != NULL)
597c478bd9Sstevel@tonic-gate 	{
607c478bd9Sstevel@tonic-gate 		smi_log(SMI_LOG_WARN,
617c478bd9Sstevel@tonic-gate 			"%s: private data not NULL",
627c478bd9Sstevel@tonic-gate 			ctx->ctx_smfi->xxfi_name);
637c478bd9Sstevel@tonic-gate 	}
647c478bd9Sstevel@tonic-gate 	mi_clr_macros(ctx, 0);
657c478bd9Sstevel@tonic-gate 	free(ctx);
667c478bd9Sstevel@tonic-gate 	ctx = NULL;
677c478bd9Sstevel@tonic-gate 	return ret;
687c478bd9Sstevel@tonic-gate }
69*058561cbSjbeck #endif /* !_FFR_WORKERS_POOL */
70