-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprerun.php
82 lines (67 loc) · 2.15 KB
/
prerun.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?
/*
Copyright (C) 2006 Erik Bonder <[email protected]>
This file is part of DeFault.Chat.
DeFault.Chat is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeFault.Chat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeFault.Chat; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
?>
<?
$sock = array();
foreach ( $bind as $a )
{
echo 'starting server at '.$a[host].':'.$a[port].'...';
if ( ( $s = @socket_create( AF_INET, SOCK_STREAM, 0) ) < 0 ) exit( 'socket_create() failed: '.socket_strerror( socket_last_error() ).NL );
if ( !@socket_bind( $s, $a[host], $a[port] ) ) exit( 'socket_bind() failed: '.socket_strerror( socket_last_error() ).NL );
if ( !@socket_listen( $s, 5 ) ) exit( 'socket_listen() failed: '.socket_strerror( socket_last_error() ).NL );
$sock[] = $s;
echo 'OK'.NL;
}
if ( file_exists( 'log/error' ) ) rename( 'log/error', 'log/error.'.date( 'YmdHis' ) );
if ( !DEBUG )
{
$pid = @pcntl_fork();
if ( $pid == -1 ) exit( 'pcntl_fork() failed' );
if ( $pid )
{
$f = fopen( 'chat3.pid', 'w' );
fwrite( $f, $pid );
fclose( $f );
exit;
}
if ( !( $pid = @posix_setsid() ) ) exit( 'posix_setsid() failed' );
error_reporting( 0 );
}
$sig_term = false;
function cleanup() {
foreach ($GLOBALS[socks] as $s) {
socket_shutdown($s);
socket_close($s);
}
foreach ($GLOBALS[sock] as $s) {
socket_shutdown($s);
socket_close($s);
}
debug('exit'.NL);
exit;
}
function sig_handler($signo) {
switch ($signo) {
case SIGTERM:
debug('SIGTERM'.NL);
cleanup();
break;
default:
}
}
pcntl_signal(SIGTERM, "sig_handler");
?>