Date: Fri, 24 Nov 2000 16:50:26 -0800 From: "Chuck" <chuckw@wave.net> To: <freebsd-questions@FreeBSD.ORG> Subject: Am I going to have to switch to LINUX? Message-ID: <LPBBLJHAFJEALBMABMBLOEMLCDAA.chuckw@wave.net>
next in thread | raw e-mail | index | archive | help
I need help... Here's my dilemma... I have a server that was running some chat scripts written in perl... They were running on FreeBSD 2.2.7 just fine... I got the idea to upgrade my hardware and software to FreeBSD 4.1... I get an error every time I try to send 2 things to the chat daemon at once... It causes an error that said "Accept : bad file descriptor" ... Here is what the code that sets up the chat daemon looks like... Afterward this is the script that sends the chat messages to the chat daemon... Is there any variable that I need to set that is different between the versions... If I send one request to the chat deamon at a time it works fine... If I send more than one thing to it the chat daemon crashes... I'm about to give up and use a different operating system... Chuck... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ chatd (perl script) # # 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 ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ chat-subs.pl (perl script) # Send a command to the chat daemon. Needs forum, writer number, and # a message to send. # sub chat { local($command, $forum, $writer, $message) = @_; if (socket(S,$AF_UNIX,$SOCK_STREAM,0) && connect(S,pack($sockaddr_un,$AF_UNIX,$socket_path))) { select(S); $| = 1; select(STDOUT); print S "$command\0$forum\0$writer\n"; print S $message; close(S); } else { print <<EOH; <HTML><HEAD><TITLE>$server Chat Error: Could not connect</TITLE></HEAD> $background <H1>Error: Could not connect to Chat Daemon</H1> <P>Use the "back" button on your browser to return to the previous page and try again. If this error persists for <B>over 15 minutes</B>, please e-mail me <A HREF="mailto:$chatmaster">$chatmaster</A> regarding this error.</P></BODY></HTML> EOH exit(0); } } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?LPBBLJHAFJEALBMABMBLOEMLCDAA.chuckw>