Skip site navigation (1)Skip section navigation (2)
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
This is a multi-part message in MIME format.

------=_NextPart_000_0000_01C05385.46937AC0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

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...

------=_NextPart_000_0000_01C05385.46937AC0
Content-Type: application/octet-stream;
	name="chatd"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="chatd"

#!/usr/local/bin/perl=0A=
#=0A=
# This software is Copyright 1995 Doug Stevenson (doug+@osu.edu).=0A=
#=0A=
# Duplication of this code in any form for purposes other than backups=0A=
# is strictly prohibited without written consent of the author.=0A=
#=0A=
# You may freely modify the source code at your own risk.  The author is=0A=
# not responsible for effects of this software before of after=0A=
# modification.=0A=
#=0A=
=0A=
# not CGI runnable=0A=
exit(1) if defined($ENV{'REQUEST_METHOD'});=0A=
=0A=
$chatdir =3D '/usr/local/www/cgi-bin/chat2';=0A=
require "$chatdir/chat-defs.pl";=0A=
require "$chatdir/chat-subs.pl";=0A=
require "$chatdir/chatd-subs.pl";=0A=
require 'getopts.pl';=0A=
=0A=
#=0A=
# -k kills the currently running chatd, -r restarts it=0A=
#=0A=
&Getopts('krv');=0A=
=0A=
if (defined($opt_k)) {=0A=
    kill('TERM', &chatd_pid()) || die "Could not kill chatd.\n";=0A=
    exit(0);=0A=
}=0A=
elsif (defined($opt_r)) {=0A=
    kill('HUP', &chatd_pid()) || die "Could not restart chatd.\n";=0A=
    exit(0);=0A=
}=0A=
elsif (defined($opt_v)) {=0A=
    $verbose =3D 1;=0A=
}=0A=
else {=0A=
    if (! &daemonize()) {=0A=
	die "chatd: Could not start as a daemon\n";=0A=
    }=0A=
}=0A=
=0A=
=0A=
#=0A=
# Set up signal handlers=0A=
#=0A=
$SIG{'HUP'}  =3D 'reload';	# HUP forces a reload of all data files=0A=
$SIG{'TERM'} =3D 'handler';	# everything else cleans up and quits=0A=
$SIG{'KILL'} =3D 'handler';=0A=
$SIG{'QUIT'} =3D 'handler';=0A=
$SIG{'INT'}  =3D 'handler';=0A=
=0A=
#=0A=
# Get socket stuff ready to listen for messages=0A=
#=0A=
unlink($socket_path);=0A=
socket(CHAT,$AF_UNIX,$SOCK_STREAM,0) || die "socket: $!";=0A=
bind(CHAT, pack($sockaddr_un, $AF_UNIX, $socket_path)) || die "bind: =
$!\n";=0A=
listen(CHAT,5) || die "listen: $!";=0A=
select(CHAT); $| =3D 1; select(NS); $| =3D 1; select(STDOUT);=0A=
=0A=
=0A=
#=0A=
# The Big Loop=0A=
#=0A=
while (1) {=0A=
    print "Waiting for connection..." if $verbose;=0A=
=0A=
  ACCEPT: {=0A=
      if (!accept(NS,CHAT)) {=0A=
	  # probably got interrupted from a HUP for a reload=0A=
	  if ($! =3D~ /^Int/) {=0A=
	      redo ACCEPT;=0A=
	  }=0A=
	  # or, maybe they just want us dead, or error=0A=
	  else {=0A=
	      die "accept: $!\n";=0A=
	  }=0A=
      }=0A=
  }=0A=
=0A=
    #=0A=
    # Child does all the dirty work=0A=
    #=0A=
    if (($child =3D fork) =3D=3D 0) {=0A=
	local($message, $forum, $writer);=0A=
	print "got one!\n" if $verbose;=0A=
=0A=
	# command comes in as a null-separated list of arguments=0A=
	chop($_ =3D <NS>);=0A=
	local($command, $forum, $writer) =3D split(/\0/);=0A=
	while (<NS>) { $message .=3D $_; }=0A=
	close(NS);=0A=
=0A=
	if ($verbose) {=0A=
	    print "COMMAND $command, FORUM $forum, WRITER $writer\n";=0A=
	    print "WROTE: $message\n\n";=0A=
	}=0A=
=0A=
	if ($command eq 'TALK') {=0A=
	    &announce($forum, $writer, $message);=0A=
	}=0A=
	elsif ($command =3D~ /^WHISPER (\d+)/) {=0A=
	    &whisper($forum, $1, $writer, $message);=0A=
	}=0A=
        elsif ($command eq 'LEAVE' ) {=0A=
	       &announce_exit($forum, $writer, $message);=0A=
        }=0A=
	exit(0);=0A=
    }=0A=
=0A=
    waitpid(-1, 0);=0A=
    close(NS);=0A=
}=0A=
=0A=
=0A=
=0A=
##=0A=
## Subroutines=0A=
##=0A=
=0A=
#=0A=
# Make me a daemon=0A=
#=0A=
sub daemonize {=0A=
    local($pid);=0A=
=0A=
  FORK: {=0A=
      if ($pid =3D fork) {=0A=
	  &drop_pid($pid) || die "Could not write pid to file $pidfile\n";=0A=
	  print "Chat Daemon started at pid $pid\n";=0A=
	  exit(0);=0A=
      }=0A=
      elsif (defined $pid) {;}	# child...continues from here=0A=
      elsif ($! =3D~ /No more process/) {=0A=
	  sleep 5;=0A=
	  redo FORK;=0A=
      }=0A=
      else {=0A=
	  return 0;		# can't fork=0A=
      }=0A=
  }=0A=
    return 1;=0A=
}=0A=
=0A=
=0A=
=0A=
#=0A=
# Signal handler.  Cleans up after the daemon and quits.=0A=
#=0A=
sub handler {=0A=
    local($sig) =3D @_;=0A=
    print "Caught SIG$sig, cleaning up and quitting...\n";=0A=
    unlink($socket_path, $pidfile);=0A=
    exit(0);=0A=
}=0A=
=0A=
=0A=
#=0A=
# Do a reload of the data files after a HUP signal.=0A=
#=0A=
sub reload {=0A=
    print "\n\nReloading data...\n\n";=0A=
    do "$chatdir/chat-defs.pl";=0A=
}=0A=
=0A=
=0A=
##=0A=
## end of chatd=0A=
##=0A=

------=_NextPart_000_0000_01C05385.46937AC0--



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?LPBBLJHAFJEALBMABMBLEELICDAA.chuckw>