/[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.10 by sysadm, Sun Mar 20 17:37:14 2005 UTC Revision 1.13 by sysadm, Wed Apr 30 09:18:19 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2                            fork.c  -  description                                                    fork.c  -  description
3                               -------------------                                                           -------------------
4      begin                : Mon Oct 18 2004          begin                : Mon Oct 18 2004
5      copyright            : (C) 2004 by Leaflet          copyright            : (C) 2004 by Leaflet
6      email                : leaflet@leafok.com          email                : leaflet@leafok.com
7   ***************************************************************************/   ***************************************************************************/
8    
9  /***************************************************************************  /***************************************************************************
# Line 16  Line 16 
16   ***************************************************************************/   ***************************************************************************/
17    
18  #include "common.h"  #include "common.h"
19    #include "bbs_main.h"
20    #include "log.h"
21  #include "io.h"  #include "io.h"
22    #include "fork.h"
23  #include <string.h>  #include <string.h>
24    #include <unistd.h>
25    #include <stdlib.h>
26    
27  int  int fork_server()
 fork_server ()  
28  {  {
29    int pid;          int pid;
30    
31    if (pid = fork ())          if (pid = fork())
32      return 0;          {
33    else if (pid < 0)                  SYS_child_process_count++;
34      return -1;                  log_std("Child process (%d) start\n", pid);
35                    return 0;
36    log_std ("Child process start\n");          }
37            else if (pid < 0)
38    if (close (socket_server) == -1)                  return -1;
39      {  
40        log_error ("Close server socket failed\n");          if (close(socket_server) == -1)
41        return -2;          {
42      }                  log_error("Close server socket failed\n");
43                    return -2;
44    //Redirect Input          }
45    close (0);  
46    if (dup2 (socket_client, 0) == -1)          // Redirect Input
47      {          close(0);
48        log_error ("Redirect stdin to client socket failed\n");          if (dup2(socket_client, 0) == -1)
49        return -3;          {
50      }                  log_error("Redirect stdin to client socket failed\n");
51                    return -3;
52    //Redirect Output          }
53    close (1);  
54    if (dup2 (socket_client, 1) == -1)          // Redirect Output
55      {          close(1);
56        log_error ("Redirect stdout to client socket failed\n");          if (dup2(socket_client, 1) == -1)
57        return -4;          {
58      }                  log_error("Redirect stdout to client socket failed\n");
59                    return -4;
60    bbs_main ();          }
61    
62    if (close (socket_client) == -1)          bbs_main();
63      {  
64        log_error ("Close client socket failed\n");          if (close(socket_client) == -1)
65      }          {
66                    log_error("Close client socket failed\n");
67    log_std ("Child process exit\n");          }
68    
69    //Close Input and Output for client          // Close Input and Output for client
70    close (0);          close(0);
71    close (1);          close(1);
72    
73    log_end ();          log_std("Process exit normally\n");
74    
75    //Exit child process normally          log_end();
   exit (0);  
76    
77    return 0;          // Exit child process normally
78            exit(0);
79    
80            return 0;
81  }  }


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

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