diff options
author | Jay Sorg <jay.sorg@gmail.com> | 2012-05-26 13:23:02 -0700 |
---|---|---|
committer | Jay Sorg <jay.sorg@gmail.com> | 2012-05-26 13:23:02 -0700 |
commit | c7bd96ba854b7e37071e9d3c70ec39b0e8717ef8 (patch) | |
tree | 5c617131be1ccb9c31104d9bfedd75739745c21c /xrdp/xrdp_listen.c | |
parent | 7fa4f936e43577c3529b10610ccf7ddcb2bd9fbe (diff) | |
download | xrdp-proprietary-c7bd96ba854b7e37071e9d3c70ec39b0e8717ef8.tar.gz xrdp-proprietary-c7bd96ba854b7e37071e9d3c70ec39b0e8717ef8.zip |
xrdp: added -f command line option to fork on connections
Diffstat (limited to 'xrdp/xrdp_listen.c')
-rw-r--r-- | xrdp/xrdp_listen.c | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/xrdp/xrdp_listen.c b/xrdp/xrdp_listen.c index 23f532a8..665d5f36 100644 --- a/xrdp/xrdp_listen.c +++ b/xrdp/xrdp_listen.c @@ -181,6 +181,44 @@ xrdp_listen_get_port_address(char* port, int port_bytes, } /*****************************************************************************/ +static int APP_CC +xrdp_listen_fork(struct xrdp_listen* self, struct trans* server_trans) +{ + int pid; + char text[256]; + struct xrdp_process* process; + + pid = g_fork(); + if (pid == 0) + { + /* child */ + /* recreate some main globals */ + xrdp_child_fork(); + /* recreate the process done wait object, not used in fork mode */ + g_tcp_close((int)(self->pro_done_event)); + pid = g_getpid(); + g_snprintf(text, 255, "xrdp_%8.8x_listen_pro_done_event", pid); + self->pro_done_event = g_create_wait_obj(text); + self->process_list = list_create(); + /* delete listener, child need not listen */ + trans_delete(self->listen_trans); + self->listen_trans = 0; + /* new connect instance */ + process = xrdp_process_create(self, 0); + process->server_trans = server_trans; + g_process = process; + xrdp_process_run(0); + xrdp_process_delete(process); + /* mark this process to exit */ + g_set_term(1); + return 0; + } + /* parent */ + trans_delete(server_trans); + return 0; +} + +/*****************************************************************************/ /* a new connection is coming in */ int DEFAULT_CC xrdp_listen_conn_in(struct trans* self, struct trans* new_self) @@ -189,6 +227,10 @@ xrdp_listen_conn_in(struct trans* self, struct trans* new_self) struct xrdp_listen* lis; lis = (struct xrdp_listen*)(self->callback_data); + if (lis->startup_params->fork) + { + return xrdp_listen_fork(lis, new_self); + } process = xrdp_process_create(lis, lis->pro_done_event); if (xrdp_listen_add_pro(lis, process) == 0) { @@ -208,8 +250,7 @@ xrdp_listen_conn_in(struct trans* self, struct trans* new_self) /*****************************************************************************/ /* wait for incoming connections */ int APP_CC -xrdp_listen_main_loop(struct xrdp_listen* self, - struct xrdp_startup_params* startup_param) +xrdp_listen_main_loop(struct xrdp_listen* self) { int error; int robjs_count; @@ -226,7 +267,7 @@ xrdp_listen_main_loop(struct xrdp_listen* self, self->status = 1; if (xrdp_listen_get_port_address(port, sizeof(port), address, sizeof(address), - startup_param) != 0) + self->startup_params) != 0) { g_writeln("xrdp_listen_main_loop: xrdp_listen_get_port failed"); self->status = -1; @@ -276,7 +317,7 @@ xrdp_listen_main_loop(struct xrdp_listen* self, } if (trans_check_wait_objs(self->listen_trans) != 0) { - break; + break; } } /* stop listening */ |