--- lbbs/src/fork.c 2004/10/18 08:17:25 1.2 +++ lbbs/src/fork.c 2004/10/19 02:12:28 1.5 @@ -1,8 +1,8 @@ /*************************************************************************** - bbsd.c - description + fork.c - description ------------------- begin : Mon Oct 18 2004 - copyright : (C) 2004 by leaf + copyright : (C) 2004 by Leaflet email : leaflet@leafok.com ***************************************************************************/ @@ -16,8 +16,41 @@ ***************************************************************************/ #include "common.h" -#include -#include -#include -#include -#include + +int +fork_server(int sock_server, int sock_client, struct sockaddr_in * p_sin) +{ + int pid; + + if (pid = fork ()) + return 0; + else if (pid < 0) + return -1; + + log_std ("Child process start\n"); + + if (close(sock_server) == -1) + { + log_error("Close server socket failed\n"); + } + + socket_client = sock_client; + strcpy(hostaddr_client,inet_ntoa(p_sin->sin_addr)); + port_client = ntohs(p_sin->sin_port); + + bbs_main(); + + if (close(sock_client) == -1) + { + log_error("Close client socket failed\n"); + } + + log_std ("Child process exit\n"); + + log_end(); + + //Exit child process normally + exit(0); + + return 0; +}