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

Annotation of /lbbs/src/fork.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (hide annotations)
Wed Apr 30 09:18:19 2025 UTC (10 months, 2 weeks ago) by sysadm
Branch: MAIN
Changes since 1.12: +5 -0 lines
Content type: text/x-csrc
Add missing header files
Update compile dependency

1 sysadm 1.1 /***************************************************************************
2 sysadm 1.12 fork.c - description
3     -------------------
4     begin : Mon Oct 18 2004
5     copyright : (C) 2004 by Leaflet
6     email : leaflet@leafok.com
7 sysadm 1.1 ***************************************************************************/
8    
9     /***************************************************************************
10     * *
11     * This program is free software; you can redistribute it and/or modify *
12     * it under the terms of the GNU General Public License as published by *
13     * the Free Software Foundation; either version 2 of the License, or *
14     * (at your option) any later version. *
15     * *
16     ***************************************************************************/
17    
18 sysadm 1.2 #include "common.h"
19 sysadm 1.13 #include "bbs_main.h"
20     #include "log.h"
21 sysadm 1.7 #include "io.h"
22 sysadm 1.13 #include "fork.h"
23 sysadm 1.7 #include <string.h>
24 sysadm 1.13 #include <unistd.h>
25     #include <stdlib.h>
26 sysadm 1.3
27 sysadm 1.12 int fork_server()
28 sysadm 1.3 {
29 sysadm 1.12 int pid;
30 sysadm 1.10
31 sysadm 1.12 if (pid = fork())
32     {
33     SYS_child_process_count++;
34     log_std("Child process (%d) start\n", pid);
35     return 0;
36     }
37     else if (pid < 0)
38     return -1;
39    
40     if (close(socket_server) == -1)
41     {
42     log_error("Close server socket failed\n");
43     return -2;
44     }
45    
46     // Redirect Input
47     close(0);
48     if (dup2(socket_client, 0) == -1)
49     {
50     log_error("Redirect stdin to client socket failed\n");
51     return -3;
52     }
53    
54     // Redirect Output
55     close(1);
56     if (dup2(socket_client, 1) == -1)
57     {
58     log_error("Redirect stdout to client socket failed\n");
59     return -4;
60     }
61    
62     bbs_main();
63    
64     if (close(socket_client) == -1)
65     {
66     log_error("Close client socket failed\n");
67     }
68    
69     // Close Input and Output for client
70     close(0);
71     close(1);
72 sysadm 1.9
73 sysadm 1.12 log_std("Process exit normally\n");
74 sysadm 1.11
75 sysadm 1.12 log_end();
76 sysadm 1.3
77 sysadm 1.12 // Exit child process normally
78     exit(0);
79 sysadm 1.3
80 sysadm 1.12 return 0;
81 sysadm 1.3 }

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