From owner-freebsd-questions Fri Nov 24 16:51:33 2000 Delivered-To: freebsd-questions@freebsd.org Received: from tidal.wave.net (unknown [198.68.31.227]) by hub.freebsd.org (Postfix) with ESMTP id D0C3437B479 for ; Fri, 24 Nov 2000 16:51:28 -0800 (PST) Received: from jj ([208.7.50.47]) by tidal.wave.net (8.9.3/8.9.3) with SMTP id QAA77310 for ; Fri, 24 Nov 2000 16:51:26 -0800 (PST) (envelope-from chuckw@wave.net) From: "Chuck" To: Subject: Am I going to have to switch to LINUX? Date: Fri, 24 Nov 2000 16:50:26 -0800 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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($_ = ); local($command, $forum, $writer) = split(/\0/); while () { $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 <$server Chat Error: Could not connect $background

Error: Could not connect to Chat Daemon

Use the "back" button on your browser to return to the previous page and try again. If this error persists for over 15 minutes, please e-mail me $chatmaster regarding this error.

EOH exit(0); } } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message