Here is my code posted before,
#the code here would be creating IO::Socket::SSL connection for the
client to connect with.
#run as daemon
sub handle_connection{
$dbh = DBI->connect("DBI:mysql:test_mrtg", "root",
'password'),{RaiseError => 1, AutoCommit => 0} || die ("Cannot connect
to database");
#$outpath =
"/usr/home/extol/testing/SocketProgramming/MRTG/THREAD/serverAlert.log";
$s = shift;
$output = shift || $s;
#$s->autoflush(1);
$exit = 0;
#print $s "Welcome to $0; Send me the new log.....\n";
my ($peer_cert, $subject_name, $issuer_name, $date, $str);
if( ! $s ) {
warn "error: ", $s->errstr, "\n";
$exit = 1;
break;
}
while(<$s>){
if( ref($s) eq "IO::Socket::SSL") {
$subject_name =
$s->peer_certificate("subject");
$issuer_name = $s->peer_certificate("issuer");
print $_;
chomp($_);
if(/done/i)
{
last;
}
else{
@info = split(/\s+/, $_);
$date = $info[0];
$type = $info[1];
$service = $info[2];
$hostname = $info[3];
$sourceIP = $info[4];
$destIP = $info[5];
$customer = $info[6];
$count = $info[7];
$downtime = $info[8];
$uptime = $info[9];
$checked = $info[10];
lock($date);
lock($type);
lock($service);
lock($hostname);
lock($sourceIP);
lock($destIP);
lock($customer);
lock($count);
lock($downtime);
lock($uptime);
lock($checked);
#check if the same record exist in the summary table. If does,
update the table
$checksame = "select count(*) from summary
where Type = '$type' AND Service = '$service' AND Hostname =
'$hostname' AND sourceIP = '$sourceIP' AND destIp = '$destIP' AND
customer = '$customer' AND Checked = 0 ";
$checkexist = $dbh->prepare($checksame);
$checkexist->execute or die "can't check\n";
$countsame = $checkexist->fetchrow_array;
if($countsame > 0) #the record exist
{
$sqlconfig = "update summary set Date
= '$date',CountDown = '$count',Downtime = '$downtime', Uptime =
'$uptime', Checked = '$checked' WHERE Type = '$type' AND Service =
'$service' AND Hostname = '$hostname' AND sourceIP = '$sourceIP' AND
destIp ='$destIP' AND customer = '$customer' AND Checked = 0";
$update = $dbh->prepare($sqlconfig);
$update->execute or die "can't update
uptime\n";
}
else
{
#insert into the database
$sql = "insert into summary values
('$date','$type','$service','$hostname','$sourceIP','$destIP','$customer','$count','$downtime','$uptime',0,'$checked')";
$insert = $dbh->prepare($sql);
$insert->execute or die "cannot be insert\n";
}
$checkexist->finish();
#query the database to get the record with the above information
$sql = "select * from summary where (CountDown >=3
AND SendMail = 0) OR (Checked = 1 AND SendMail = 0) OR (CountDown >=3
AND SendMail = 1 AND Checked = 0)";
$send = $dbh->prepare($sql);
$send->execute or die "cannot execute\n";
while(@row = $send->fetchrow_array)
{
$DataDate = $row[0];
$DataType = $row[1];
$DataService = $row[2];
$DataHostname = $row[3];
$DataIP = $row[4];
$DataDest = $row[5];
$DataCustomer = $row[6];
$DataCount = $row[7];
$DataDown = $row[8];
$DataUp = $row[9];
lock($DataDate);
lock($DataType);
lock($DataService);
lock($DataHostname);
lock($DataIP);
lock($DataDest);
lock($DataCustomer);
lock($DataCount);
lock($DataDown);
lock($DataUp);
#send Alert by using above information
#$subject = "TESTING!!Alerts from $DataType";
#$message = "\r\n \t Date : $DataDate \r\n \t
Type : $DataType \r\n \t Service : $DataService \r\n \t IP : $DataIP
\r\n \t Destination : $DataDest \r\n \t Customer : $DataCustomer \r\n
\t Number of Down Time : $DataCount \r\n \t Last Down Time : $DataDown
\r\n \t Up Time : $DataUp \r\n\r\n";
#`/usr/local/mss_dev/tcpmail/mailalert
"$subject" "$message"`;
#send message to server on extol side
#print "Extol :$DataDate $DataType $DataService $DataHostname
$DataIP $DataDest $DataCustomer $DataCount $DataDown $DataUp\n";
#after send alert, set SendMail flag to 1
$set = "update summary set SendMail = 1 where
Date='$DataDate' AND Type='$DataType' AND Service='$DataService' AND
Hostname='$DataHostname' AND sourceIP = '$DataIP' AND destIP =
'$DataDest' AND customer = '$DataCustomer' AND CountDown = '$DataDown'
AND Uptime = '$DataUp' OR (Checked = 1 AND SendMail = 0) OR (Checked =
0 AND SendMail = 0)";
$setMail = $dbh->prepare($set);
$setMail->execute or die "cannot update
SendMail\n";
}
$send->finish();
}
}
else{
$exit = 1;
}
last if ($exit == 1);
}
$dbh->disconnect;
}
while(1){
while(($s = $sock->accept())) {
$s->autoflush(1);
$thread = threads->create(\&handle_connection, $s);
$thread->detach;
}
}
The scenario is: This server do accept connections from different
clients and storing the data from different client into the database.
However, after running some time, the out of memory error and the
program stopped. Therefore, I would like to check the errors from the
core file to find the bugs. I try to debug the program many times, but
the error still occur.
Ben said:
I have errors in my program and i think Perl5.8.6.core is where all
the erros logged. However, it's in unreadable form. Is there anyway to
open the file and read?
This is a core dump (you are using a Unix machine, right?). Can you
provide a minimal script that causes it to happen? Perl should never
core dump, so someone should file a bug.
Ben
--
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based
on the strictest morality. [Samuel Butler, paraphrased] (e-mail address removed)