Date: Tue, 21 Nov 2000 06:35:44 -0800 From: "Chuck" <chuckw@wave.net> To: <freebsd-questions@FreeBSD.ORG> Subject: Having problem with 4.1 ...HELP!!! Message-ID: <LPBBLJHAFJEALBMABMBLEELICDAA.chuckw@wave.net>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Hi...
I have a server that I have just loaded 4.1 on and after I have loaded known
good chat perl scripts onto, the chat daemon dies if I try to send 2 things
at it at once... It's like it can't spawn a child process... I'm not sure
that it even gets that far... It hit's listen and listen returns "Bad File
Descriptor"...
To make a long story as short as possible, the chat scripts simply generate
HTML pages that have 2 text boxes on them... One is for messages to be
displayed in public and the other is for a message to be sent to one person
only... I can post a message in either without problem... If I post a
message in both at the same time it causes the chat daemon to die...
I have included the chat daemon script so that you can see how it is being
processed... I believe that it is a bug in 4.1 because these same exact
scripts run on 2.2.7 FreeBSD... Anyway if you have ANY idea I would love to
hear it...
Chuck...
[-- Attachment #2 --]
#!/usr/local/bin/perl
#
# This software is Copyright 1995 Doug Stevenson (doug+@osu.edu).
#
# Duplication of this code in any form for purposes other than backups
# is strictly prohibited without written consent of the author.
#
# You may freely modify the source code at your own risk. The author is
# not responsible for effects of this software before of after
# modification.
#
# not CGI runnable
exit(1) if defined($ENV{'REQUEST_METHOD'});
$chatdir = '/usr/local/www/cgi-bin/chat2';
require "$chatdir/chat-defs.pl";
require "$chatdir/chat-subs.pl";
require "$chatdir/chatd-subs.pl";
require 'getopts.pl';
#
# -k kills the currently running chatd, -r restarts it
#
&Getopts('krv');
if (defined($opt_k)) {
kill('TERM', &chatd_pid()) || die "Could not kill chatd.\n";
exit(0);
}
elsif (defined($opt_r)) {
kill('HUP', &chatd_pid()) || die "Could not restart chatd.\n";
exit(0);
}
elsif (defined($opt_v)) {
$verbose = 1;
}
else {
if (! &daemonize()) {
die "chatd: Could not start as a daemon\n";
}
}
#
# Set up signal handlers
#
$SIG{'HUP'} = 'reload'; # HUP forces a reload of all data files
$SIG{'TERM'} = 'handler'; # everything else cleans up and quits
$SIG{'KILL'} = 'handler';
$SIG{'QUIT'} = 'handler';
$SIG{'INT'} = 'handler';
#
# Get socket stuff ready to listen for messages
#
unlink($socket_path);
socket(CHAT,$AF_UNIX,$SOCK_STREAM,0) || die "socket: $!";
bind(CHAT, pack($sockaddr_un, $AF_UNIX, $socket_path)) || die "bind: $!\n";
listen(CHAT,5) || die "listen: $!";
select(CHAT); $| = 1; select(NS); $| = 1; select(STDOUT);
#
# The Big Loop
#
while (1) {
print "Waiting for connection..." if $verbose;
ACCEPT: {
if (!accept(NS,CHAT)) {
# probably got interrupted from a HUP for a reload
if ($! =~ /^Int/) {
redo ACCEPT;
}
# or, maybe they just want us dead, or error
else {
die "accept: $!\n";
}
}
}
#
# Child does all the dirty work
#
if (($child = fork) == 0) {
local($message, $forum, $writer);
print "got one!\n" if $verbose;
# command comes in as a null-separated list of arguments
chop($_ = <NS>);
local($command, $forum, $writer) = split(/\0/);
while (<NS>) { $message .= $_; }
close(NS);
if ($verbose) {
print "COMMAND $command, FORUM $forum, WRITER $writer\n";
print "WROTE: $message\n\n";
}
if ($command eq 'TALK') {
&announce($forum, $writer, $message);
}
elsif ($command =~ /^WHISPER (\d+)/) {
&whisper($forum, $1, $writer, $message);
}
elsif ($command eq 'LEAVE' ) {
&announce_exit($forum, $writer, $message);
}
exit(0);
}
waitpid(-1, 0);
close(NS);
}
##
## Subroutines
##
#
# Make me a daemon
#
sub daemonize {
local($pid);
FORK: {
if ($pid = fork) {
&drop_pid($pid) || die "Could not write pid to file $pidfile\n";
print "Chat Daemon started at pid $pid\n";
exit(0);
}
elsif (defined $pid) {;} # child...continues from here
elsif ($! =~ /No more process/) {
sleep 5;
redo FORK;
}
else {
return 0; # can't fork
}
}
return 1;
}
#
# Signal handler. Cleans up after the daemon and quits.
#
sub handler {
local($sig) = @_;
print "Caught SIG$sig, cleaning up and quitting...\n";
unlink($socket_path, $pidfile);
exit(0);
}
#
# Do a reload of the data files after a HUP signal.
#
sub reload {
print "\n\nReloading data...\n\n";
do "$chatdir/chat-defs.pl";
}
##
## end of chatd
##
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?LPBBLJHAFJEALBMABMBLEELICDAA.chuckw>
