File: blootbot

package info (click to toggle)
blootbot 1.1.0-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,420 kB
  • ctags: 586
  • sloc: perl: 15,941; sh: 154; makefile: 56; sql: 45
file content (90 lines) | stat: -rwxr-xr-x 2,089 bytes parent folder | download
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
#!/usr/bin/perl

# infobot  -- copyright kevin lenzo (c) 1997-1999
# blootbot -- copyright david sobon (c) 1999-infinity

use strict;
use vars qw($bot_base_dir $bot_src_dir $bot_state_dir $bot_data_dir
	    $bot_config_dir $bot_log_dir $bot_run_dir $bot_pid $memusage %param
);

BEGIN {
    $bot_config_dir	= '/etc/blootbot';
    $bot_pid       = $$;

    require "$bot_config_dir/directories";
    $bot_base_dir = $bot_state_dir;

    require "$bot_src_dir/logger.pl";
    require "$bot_src_dir/core.pl";
    require "$bot_src_dir/interface.pl";
    require "$bot_src_dir/modules.pl";

    # load the configuration (params) file.
    &setupConfig();

    &showProc();	# to get the first value.
    &status("Initial memory usage: $memusage kB");
    &loadCoreModules();
    &loadDBModules();
    &loadFactoidsModules();
    &loadIRCModules();

    &status("Memory usage after loading modules: $memusage kB");
}

# prevent duplicate processes of the same bot
&duperuncheck();

# initialize everything 
&startup();	# first time initialization.
&setup();

if (!&IsParam("Interface") or $param{'Interface'} =~ /IRC/) {
    # launch the irc event loop
    &ircloop();
} else {
    &cliloop();
}

exit 0;  # just so you don't look farther down in this file :)

# --- support routines

# FIXME.
#   add arguments, basically '-h' and '--help', heh.
#

# added by the xk
sub duperuncheck {
    my $pid	= $$;
    my $file	= $file{PID};

    if ( -f $file) {
	open(PIDFILE,$file) or die "error: cannot open $file.";
	my $thispid = <PIDFILE> || "NULL\n";
	close PIDFILE;
	chop $thispid;

	if ($thispid =~ /^\D$/) {
	    &staus("warning: pidfile is invalid; wiping out.");
	} else {
	    if ( -d "/proc/$thispid/") {
		&ERROR("bot is already running from this directory.");
		&ERROR("if this is incorrect, erase '*.pid'.");
		&ERROR("verify with 'ps -axu | grep $thispid'.");
		exit 1;
	    } else {
		&status("warning: stale $file found; wiping.");
	    }
	}
    }

    open(PIDFILE,">$file") or die "error: cannot write to $file.";
    print PIDFILE "$pid\n";
    close PIDFILE;

    return 0;
}

1;