2005-01-30 05:55:30 +03:00
/*
Unix SMB / CIFS implementation .
helper functions for task based servers ( nbtd , winbind etc )
Copyright ( C ) Andrew Tridgell 2005
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2005-01-30 05:55:30 +03:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-01-30 05:55:30 +03:00
*/
# include "includes.h"
# include "process_model.h"
2005-02-03 14:56:03 +03:00
# include "lib/events/events.h"
2006-03-09 20:48:41 +03:00
# include "smbd/service.h"
2005-01-30 05:55:30 +03:00
# include "smbd/service_task.h"
2005-06-05 10:53:07 +04:00
# include "lib/messaging/irpc.h"
2007-10-01 22:52:55 +04:00
# include "param/param.h"
2005-01-30 05:55:30 +03:00
/*
terminate a task service
*/
2005-06-26 03:53:14 +04:00
void task_server_terminate ( struct task_server * task , const char * reason )
2005-01-30 05:55:30 +03:00
{
2005-01-31 19:36:17 +03:00
struct event_context * event_ctx = task - > event_ctx ;
2005-01-30 05:55:30 +03:00
const struct model_ops * model_ops = task - > model_ops ;
2005-06-26 03:53:14 +04:00
DEBUG ( 0 , ( " task_server_terminate: [%s] \n " , reason ) ) ;
2005-01-30 05:55:30 +03:00
model_ops - > terminate ( event_ctx , reason ) ;
2007-07-19 07:57:44 +04:00
/* don't free this above, it might contain the 'reason' being printed */
talloc_free ( task ) ;
2005-01-30 05:55:30 +03:00
}
/* used for the callback from the process model code */
struct task_state {
void ( * task_init ) ( struct task_server * ) ;
const struct model_ops * model_ops ;
} ;
/*
called by the process model code when the new task starts up . This then calls
the server specific startup code
*/
2007-01-10 13:52:09 +03:00
static void task_server_callback ( struct event_context * event_ctx ,
struct server_id server_id , void * private )
2005-01-30 05:55:30 +03:00
{
struct task_state * state = talloc_get_type ( private , struct task_state ) ;
struct task_server * task ;
task = talloc ( event_ctx , struct task_server ) ;
if ( task = = NULL ) return ;
task - > event_ctx = event_ctx ;
task - > model_ops = state - > model_ops ;
task - > server_id = server_id ;
2007-10-01 22:52:55 +04:00
task - > msg_ctx = messaging_init ( task ,
lp_messaging_path ( task , global_loadparm ) ,
task - > server_id , task - > event_ctx ) ;
2005-01-30 05:55:30 +03:00
if ( ! task - > msg_ctx ) {
2005-06-26 03:53:14 +04:00
task_server_terminate ( task , " messaging_init() failed " ) ;
2005-01-30 05:55:30 +03:00
return ;
}
state - > task_init ( task ) ;
}
/*
startup a task based server
*/
NTSTATUS task_server_startup ( struct event_context * event_ctx ,
const struct model_ops * model_ops ,
void ( * task_init ) ( struct task_server * ) )
{
struct task_state * state ;
state = talloc ( event_ctx , struct task_state ) ;
NT_STATUS_HAVE_NO_MEMORY ( state ) ;
state - > task_init = task_init ;
state - > model_ops = model_ops ;
model_ops - > new_task ( event_ctx , task_server_callback , state ) ;
return NT_STATUS_OK ;
}
2006-03-09 20:48:41 +03:00
/*
setup a task title
*/
void task_server_set_title ( struct task_server * task , const char * title )
{
task - > model_ops - > set_title ( task - > event_ctx , title ) ;
}