| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
bbsd.c - description |
fork.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
begin : Mon Oct 18 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 |
|
|
| 16 |
***************************************************************************/ |
***************************************************************************/ |
| 17 |
|
|
| 18 |
#include "common.h" |
#include "common.h" |
| 19 |
#include <unistd.h> |
|
| 20 |
#include <signal.h> |
int |
| 21 |
#include <sys/param.h> |
fork_server(int sock_server, int sock_client, struct sockaddr * p_sin) |
| 22 |
#include <sys/types.h> |
{ |
| 23 |
#include <sys/stat.h> |
int pid; |
| 24 |
|
char temp[256]; |
| 25 |
|
|
| 26 |
|
if (pid = fork ()) |
| 27 |
|
return 0; |
| 28 |
|
else if (pid < 0) |
| 29 |
|
return -1; |
| 30 |
|
|
| 31 |
|
sprintf(temp, "Child process [%d] start\n", getpid()); |
| 32 |
|
log_std (temp); |
| 33 |
|
|
| 34 |
|
if (close(sock_server) == -1) |
| 35 |
|
{ |
| 36 |
|
log_error("Close server socket failed\n"); |
| 37 |
|
} |
| 38 |
|
|
| 39 |
|
bbs_main(); |
| 40 |
|
|
| 41 |
|
if (close(sock_client) == -1) |
| 42 |
|
{ |
| 43 |
|
log_error("Close client socket failed\n"); |
| 44 |
|
} |
| 45 |
|
|
| 46 |
|
sprintf(temp, "Child process [%d] exit\n", getpid()); |
| 47 |
|
log_std (temp); |
| 48 |
|
|
| 49 |
|
log_end(); |
| 50 |
|
|
| 51 |
|
//Exit child process normally |
| 52 |
|
exit(0); |
| 53 |
|
|
| 54 |
|
return 0; |
| 55 |
|
} |