This repository has been archived by the owner on Jan 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjanus
98 lines (87 loc) · 2.28 KB
/
janus
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env perl
# Copyright (C) 2007-2009 Daniel De Graaf
# Modificiations (C) 2011 - 2012 Brenton Edgar Scott
# Released under the GNU Affero General Public License v3
use strict;
use warnings;
BEGIN {
# Support for taint mode: we don't acually need most of these protections
# as the person running janus.pl is assumed to have shell access anyway.
# The real benefit of taint mode is protecting IRC-sourced data
$_ = $ENV{PATH};
s/:.(:|$)/$1/;
s/~/$ENV{HOME}/g;
/(.*)/;
$ENV{PATH} = $1;
$ENV{SHELL} = '/bin/sh';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
do './src/Janus.pm' or die $@;
}
our $VERSION = '1.12';
if ($^P) {
# $^P is nonzero if run inside perl -d
print "Debug mode, log outputs to console\n";
require Log::Debug;
no warnings 'once';
@Log::listeners = $Log::Debug::INST;
Log::dump_queue();
}
$| = 1;
$SIG{PIPE} = 'IGNORE';
$SIG{CHLD} = 'IGNORE';
$Conffile::conffile = $ARGV[0] if @ARGV;
Janus::load('Conffile') and Conffile::read_conf();
unless (%Conffile::netconf) {
print "Could not start:\n";
require Log::Debug;
no warnings 'once';
@Log::listeners = $Log::Debug::INST;
Log::dump_queue();
exit 1;
}
my $mplexdaemon = 'c-src/multiplex';
$mplexdaemon = 'c-src/multiplex.exe' if $^O eq 'cygwin';
my $runmode = $Conffile::netconf{set}{runmode};
$runmode = 'debug' if $^P;
unless ($runmode) {
if (-x $mplexdaemon) {
$runmode = 'mplex-daemon';
} else {
$runmode = 'uproc-daemon';
}
$runmode =~ s/-daemon// if $Conffile::netconf{set}{nofork};
}
if ($runmode =~ s/-daemon$//) {
open STDIN, '/dev/null' or die $!;
if (-t STDOUT) {
open STDOUT, '>daemon.log' or die $!;
open STDERR, '>&', \*STDOUT or die $!;
}
my $pid = fork;
die $! unless defined $pid;
if ($pid) {
if ($Conffile::netconf{set}{pidfile}) {
open P, '>', $Conffile::netconf{set}{pidfile} or die $!;
print P $pid,"\n";
close P;
}
exit 0;
}
require POSIX;
POSIX::setsid;
}
if ($runmode eq 'mplex') {
exec { $mplexdaemon } 'janus', @ARGV;
exit 1;
}
if ($runmode ne 'uproc' && $runmode ne 'debug') {
Log::warn('Invalid value for runmode in configuration');
}
Log::timestamp($Janus::time);
Janus::load('Connection') or die;
Event::insert_full(+{ type => 'INIT' });
Event::insert_full(+{ type => 'RUN' });
eval {
&Connection::ts_simple while 1;
};
Log::err("Aborting, error=$@");