3 # This file is part of the breadcrumbs daemon (bcd).
4 # Copyright (C) 2007 Pasqualino Ferrentino
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # Contact: lino.ferrentino@yahoo.it (in Italian, English or German).
27 # use threads::shared;
30 use lib
("$FindBin::Bin/../lib");
33 use Bcd
::Errors
::ErrorCodes
;
34 use Bcd
::Clients
::ClientsListeners
;
36 use Carp
; $SIG{__DIE__
} = \
&Carp
::confess
;
38 #use IO::Socket::INET;
42 #use Bcd::Bots::Manager;
43 use Bcd
::Clients
::Listener
;
46 #use POSIX ":sys_wait_h";
51 BCD_VERSION
=> '0.10.1.0',
54 #$SIG{CHLD} = 'IGNORE';
56 #sub spawn; # forward declaration
63 # daemonize the program
71 #let's see if the user wants to test...
75 # 'script' => \$script,
79 #pod2usage(2) if $help;
81 # die "Cannot script without test" if ($script == 1 and $test == 0);
83 # my $PORT = 9000; # pick something not in use
88 # print "----- Using test database, you can connect to port $PORT ----\n";
89 # Bcd::Clients::Listener->use_test_database();
91 # print "----- Using normal db, you can connect to port $PORT ----\n";
94 # my %files_to_delete;
95 # my $queue_of_files_to_delete = new Thread::Queue;
97 # #the manager should be instantiated first of all, because it
98 # #initializes the cache...
99 # Bcd::Bots::Manager->instance($test);
100 # my $clients_listeners = Bcd::Clients::ClientsListeners->instance
101 # ($script, \%files_to_delete, $queue_of_files_to_delete);
104 # use constant EOL => "\015\012";
110 # my $server = IO::Socket::INET->new( Proto => 'tcp',
111 # LocalPort => $PORT,
112 # Listen => SOMAXCONN,
115 # die "can't setup server" unless $server;
116 # my $sel = new IO::Select($server);
119 # print "[Server $0 accepting clients]\n";
124 # if (@ready = $sel->can_read(1)){
125 # foreach my $fh (@ready){
126 # my $client = $server->accept();
128 # $client->autoflush(1);
132 # print $client greetings();
133 # print $client EOL();
136 # my $name = gethostbyaddr($client->peeraddr, AF_INET);
137 # print "connection from $name [",inet_ntoa($client->peeraddr), "] at port $PORT\n";
138 # $clients_listeners->a_new_client_has_arrived($client);
143 # #print "nothing... let's see if there is a close pending\n";
144 # #ok, nothing has arrived, close the old channels...
145 # if ($queue_of_files_to_delete->pending() > 0){
147 # #print $client "I want to quit you NOW $client\n";
148 # my $num = $queue_of_files_to_delete->dequeue();
149 # #print "................ I will delete the $num \n";
150 # #print Dumper (\%files_to_delete);
151 # my $fh = delete $files_to_delete{$num};
163 #print Dumper(\@ARGV);
165 #this creates the model and the command factory!
166 Bcd
::Data
::Model
->instance();
167 #my $server = Bcd->new(port => $PORT, pid_file => './cippo.pid', setsid => 1);
168 #my $server = Bcd->new(port => $PORT, pid_file => './cippo.pid', background => 1);
169 my $server = Bcd
->new(pid_file
=> './bcd.pid');
178 if (!defined($pid = fork)) {
179 die "cannot fork: $!";
182 return; # I'm the parent
185 # else I'm the child -- go spawn
186 exit main_client_parser
($client);
191 my $ver = BCD_VERSION
();
192 my $greetings = "bcd version $ver, Copyright (C) 2007 Pasqualino Ferrentino\n";
193 $greetings .= "bcd comes with ABSOLUTELY NO WARRANTY; for details\n";
194 $greetings .= "see the file COPYING in the distribution directory.\n";
195 $greetings .= "This is free software, and you are welcome\n";
196 $greetings .= "to redistribute it under certain conditions;\n";
197 $greetings .= "see the file COPYING for details.\n";
205 chdir '/' or die "Can't chdir to /: $!";
206 open STDIN
, '/dev/null' or die "Can't read /dev/null: $!";
207 #open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!";
208 open STDERR
, '>>/dev/null' or die "Can't write to /dev/null: $!";
209 defined(my $pid = fork) or die "Can't fork: $!";
211 setsid
or die "Can't start a new session: $!";
217 bcd.pl - Breadcrumbs daemon
224 --help display this help and exits
225 --test use test database and test port (usually 9001)
226 --script write all the commands in a script file
230 Run the bcd daemon, you should use it to run the breadcrumbs site.
234 Pasqualino Ferrentino
238 This library is free software, you can redistribute it and/or modify
239 it under the same terms as Perl itself.