/[LeafOK_CVS]/lbbs/src/fork.c
ViewVC logotype

Diff of /lbbs/src/fork.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 by sysadm, Mon Oct 11 11:15:33 2004 UTC Revision 1.6 by sysadm, Thu Oct 21 17:28:46 2004 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                            fork.c  -  description                            fork.c  -  description
3                               -------------------                               -------------------
4      begin                : Mon Oct 11 2004      begin                : Mon Oct 18 2004
5      copyright            : (C) 2004 by Leaf      copyright            : (C) 2004 by Leaflet
6      email                : leaflet@leafok.com      email                : leaflet@leafok.com
7   ***************************************************************************/   ***************************************************************************/
8    
# Line 15  Line 15 
15   *                                                                         *   *                                                                         *
16   ***************************************************************************/   ***************************************************************************/
17    
18   #include "common.h"  #include "common.h"
19    
20    int
21    fork_server(int sock_server, int sock_client, struct sockaddr_in * p_sin)
22    {
23      int pid;
24          
25      if (pid = fork ())
26        return 0;
27      else if (pid < 0)
28        return -1;
29    
30      log_std ("Child process start\n");
31      
32      if (close(sock_server) == -1)
33        {
34          log_error("Close server socket failed\n");
35          return -2;
36        }
37      
38      socket_client = sock_client;
39      strcpy(hostaddr_client,(const char *)inet_ntoa(p_sin->sin_addr));
40      port_client = ntohs(p_sin->sin_port);
41    
42      //Redirect Output
43      close(1);
44      if (dup2 (socket_client, 1) == -1)
45        {
46          log_error("Redirect stdout to client socket failed\n");
47          return -3;
48        }
49    
50      bbs_main();
51      
52      if (close(sock_client) == -1)
53        {
54          log_error("Close client socket failed\n");
55        }
56    
57      log_std ("Child process exit\n");
58    
59      log_end();
60    
61      //Exit child process normally
62      exit(0);
63    
64      return 0;
65    }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1