2003-08-13 01:53:07 +00:00
/*
Unix SMB / CIFS implementation .
2005-01-30 00:54:57 +00:00
2003-08-13 01:53:07 +00:00
process model : process ( 1 process handles all client connections )
2005-01-30 00:54:57 +00:00
2003-08-13 01:53:07 +00:00
Copyright ( C ) Andrew Tridgell 2003
Copyright ( C ) James J Myers 2003 < myersjj @ samba . org >
2004-07-13 21:04:56 +00:00
Copyright ( C ) Stefan ( metze ) Metzmacher 2004
2003-08-13 01:53:07 +00:00
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 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2003-08-13 01:53:07 +00: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 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2003-08-13 01:53:07 +00:00
*/
# include "includes.h"
2006-03-26 01:23:40 +00:00
# include "smbd/process_model.h"
2006-11-07 12:03:01 +00:00
# include "system/filesys.h"
2007-01-10 10:52:09 +00:00
# include "cluster/cluster.h"
2003-08-13 01:53:07 +00:00
/*
called when the process model is selected
*/
2008-12-29 20:24:57 +01:00
static void single_model_init ( struct tevent_context * ev )
2005-01-14 01:32:56 +00:00
{
2003-08-13 01:53:07 +00:00
}
/*
2005-01-30 00:54:57 +00:00
called when a listening socket becomes readable .
2003-08-13 01:53:07 +00:00
*/
2008-12-29 20:24:57 +01:00
static void single_accept_connection ( struct tevent_context * ev ,
2008-01-05 19:03:43 -06:00
struct loadparm_context * lp_ctx ,
2008-02-05 14:51:01 +11:00
struct socket_context * listen_socket ,
2008-12-29 20:24:57 +01:00
void ( * new_conn ) ( struct tevent_context * ,
2008-01-05 19:03:43 -06:00
struct loadparm_context * ,
struct socket_context * ,
2007-01-10 10:52:09 +00:00
struct server_id , void * ) ,
2009-02-02 08:41:28 +01:00
void * private_data )
2003-08-13 01:53:07 +00:00
{
2004-09-20 12:31:07 +00:00
NTSTATUS status ;
2008-02-05 14:51:01 +11:00
struct socket_context * connected_socket ;
2004-07-13 21:04:56 +00:00
2003-08-13 01:53:07 +00:00
/* accept an incoming connection. */
2008-02-05 14:51:01 +11:00
status = socket_accept ( listen_socket , & connected_socket ) ;
2004-09-20 12:31:07 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2006-09-22 03:49:24 +00:00
DEBUG ( 0 , ( " single_accept_connection: accept: %s \n " , nt_errstr ( status ) ) ) ;
2008-02-04 17:53:01 +11:00
/* this looks strange, but is correct.
We can only be here if woken up from select , due to
an incomming connection .
We need to throttle things until the system clears
enough resources to handle this new socket .
If we don ' t then we will spin filling the log and
causing more problems . We don ' t panic as this is
probably a temporary resource constraint */
2005-10-12 11:04:01 +00:00
sleep ( 1 ) ;
2003-12-13 10:58:48 +00:00
return ;
}
2004-07-13 21:04:56 +00:00
2009-02-02 08:41:28 +01:00
talloc_steal ( private_data , connected_socket ) ;
2004-09-26 03:05:04 +00:00
2008-02-04 17:53:01 +11:00
/* The cluster_id(0, fd) cannot collide with the incrementing
* task below , as the first component is 0 , not 1 */
2008-02-05 14:51:01 +11:00
new_conn ( ev , lp_ctx , connected_socket ,
2009-02-02 08:41:28 +01:00
cluster_id ( 0 , socket_get_fd ( connected_socket ) ) , private_data ) ;
2003-08-13 01:53:07 +00:00
}
2005-01-30 02:55:30 +00:00
/*
called to startup a new task
*/
2008-12-29 20:24:57 +01:00
static void single_new_task ( struct tevent_context * ev ,
2008-01-05 19:03:43 -06:00
struct loadparm_context * lp_ctx ,
2008-02-04 17:53:01 +11:00
const char * service_name ,
2008-12-29 20:24:57 +01:00
void ( * new_task ) ( struct tevent_context * , struct loadparm_context * , struct server_id , void * ) ,
2009-02-02 08:41:28 +01:00
void * private_data )
2005-01-30 02:55:30 +00:00
{
2008-02-04 17:53:01 +11:00
static uint32_t taskid = 0 ;
/* We use 1 so we cannot collide in with cluster ids generated
* in the accept connection above , and unlikly to collide with
* PIDs from process modal standard ( don ' t run samba as
* init ) */
2009-02-02 08:41:28 +01:00
new_task ( ev , lp_ctx , cluster_id ( 1 , taskid + + ) , private_data ) ;
2005-01-30 02:55:30 +00:00
}
2004-07-13 21:04:56 +00:00
2005-01-30 02:55:30 +00:00
/* called when a task goes down */
2008-12-29 20:24:57 +01:00
static void single_terminate ( struct tevent_context * ev , struct loadparm_context * lp_ctx , const char * reason )
2003-12-13 23:25:15 +00:00
{
2005-02-16 01:48:11 +00:00
DEBUG ( 2 , ( " single_terminate: reason[%s] \n " , reason ) ) ;
2004-02-02 13:43:03 +00:00
}
2006-03-09 17:48:41 +00:00
/* called to set a title of a task or connection */
2008-12-29 20:24:57 +01:00
static void single_set_title ( struct tevent_context * ev , const char * title )
2006-03-09 17:48:41 +00:00
{
}
2007-09-03 13:13:25 +00:00
const struct model_ops single_ops = {
2005-01-14 01:32:56 +00:00
. name = " single " ,
. model_init = single_model_init ,
2005-01-30 02:55:30 +00:00
. new_task = single_new_task ,
2005-01-14 01:32:56 +00:00
. accept_connection = single_accept_connection ,
2005-01-30 02:55:30 +00:00
. terminate = single_terminate ,
2006-03-09 17:48:41 +00:00
. set_title = single_set_title ,
2005-01-14 01:32:56 +00:00
} ;
2003-08-13 01:53:07 +00:00
/*
2005-01-30 00:54:57 +00:00
initialise the single process model , registering ourselves with the
process model subsystem
2003-08-13 01:53:07 +00:00
*/
2004-02-02 13:43:03 +00:00
NTSTATUS process_model_single_init ( void )
2003-08-13 01:53:07 +00:00
{
2005-01-30 00:54:57 +00:00
return register_process_model ( & single_ops ) ;
2003-08-13 01:53:07 +00:00
}