| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
fork.c - description |
fork.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
begin : Mon Oct 18 2004 |
Copyright : (C) 2004-2025 by Leaflet |
| 5 |
copyright : (C) 2004 by Leaflet |
Email : leaflet@leafok.com |
|
email : leaflet@leafok.com |
|
| 6 |
***************************************************************************/ |
***************************************************************************/ |
| 7 |
|
|
| 8 |
/*************************************************************************** |
/*************************************************************************** |
| 9 |
* * |
* * |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
| 11 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
| 12 |
* the Free Software Foundation; either version 2 of the License, or * |
* the Free Software Foundation; either version 3 of the License, or * |
| 13 |
* (at your option) any later version. * |
* (at your option) any later version. * |
| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 19 |
#include "log.h" |
#include "log.h" |
| 20 |
#include "io.h" |
#include "io.h" |
| 21 |
#include "fork.h" |
#include "fork.h" |
| 22 |
|
#include "menu.h" |
| 23 |
#include <stdio.h> |
#include <stdio.h> |
| 24 |
#include <string.h> |
#include <string.h> |
| 25 |
|
#include <signal.h> |
| 26 |
#include <unistd.h> |
#include <unistd.h> |
| 27 |
#include <stdlib.h> |
#include <stdlib.h> |
| 28 |
|
#include <errno.h> |
| 29 |
|
|
| 30 |
int fork_server() |
int fork_server() |
| 31 |
{ |
{ |
| 41 |
} |
} |
| 42 |
else if (pid < 0) // Error |
else if (pid < 0) // Error |
| 43 |
{ |
{ |
| 44 |
|
log_error("fork() error (%d)\n", errno); |
| 45 |
return -1; |
return -1; |
| 46 |
} |
} |
| 47 |
|
|
| 68 |
return -4; |
return -4; |
| 69 |
} |
} |
| 70 |
|
|
| 71 |
|
SYS_child_process_count = 0; |
| 72 |
|
|
| 73 |
|
// Reset signal handler to default |
| 74 |
|
signal(SIGHUP, SIG_DFL); |
| 75 |
|
signal(SIGCHLD, SIG_DFL); |
| 76 |
|
signal(SIGTERM, SIG_DFL); |
| 77 |
|
|
| 78 |
bbs_main(); |
bbs_main(); |
| 79 |
|
|
| 80 |
|
// Child process exit |
| 81 |
|
SYS_server_exit = 1; |
| 82 |
|
|
| 83 |
if (close(socket_client) == -1) |
if (close(socket_client) == -1) |
| 84 |
{ |
{ |
| 85 |
log_error("Close client socket failed\n"); |
log_error("Close client socket failed\n"); |
| 90 |
close(STDOUT_FILENO); |
close(STDOUT_FILENO); |
| 91 |
|
|
| 92 |
log_std("Process exit normally\n"); |
log_std("Process exit normally\n"); |
|
|
|
| 93 |
log_end(); |
log_end(); |
| 94 |
|
|
| 95 |
// Exit child process normally |
_exit(0); |
| 96 |
exit(0); |
|
|
|
|
| 97 |
return 0; |
return 0; |
| 98 |
} |
} |