Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Nov 1995 11:52:59 -0500 (EST)
From:      "Jonathan M. Bresler" <jmb@kryten.Atinc.COM>
To:        Jerry Kendall <Jerry.Kendall@vmicls.com>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: Seting up a mirror for FreeBSD
Message-ID:  <Pine.3.89.9511301117.E6978-0100000@kryten.atinc.com>
In-Reply-To: <9511301525.AA09975.gonzo@vmicls.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 30 Nov 1995, Jerry Kendall wrote:

> Still unable to setup a mirror for freebsd....
> 

you may have a bad version of chat2.pl.     

*** /usr/local/lib/perl/chat2.pl.orig	Mon Jan 24 18:28:30 1994
--- /usr/local/lib/perl/chat2.pl	Thu Nov 17 19:30:38 1994
***************
*** 1,12 ****
! ## chat.pl: chat with a server
! ## V2.01.alpha.7 91/06/16
! ## Randal L. Schwartz
  
  package chat;
  
  $sockaddr = 'S n a4 x8';
! chop($thishost = `hostname`); $thisaddr = (gethostbyname($thishost))[4];
! $thisproc = pack($sockaddr, 2, 0, $thisaddr);
  
  # *S = symbol for current I/O, gets assigned *chatsymbol....
  $next = "chatsymbol000000"; # next one
--- 1,43 ----
! # chat.pl: chat with a server
! # Based on: V2.01.alpha.7 91/06/16
! # Randal L. Schwartz (was <merlyn@iwarp.intel.com>)
! # multihome additions by A.Macpherson@bnr.co.uk
! # allow for /dev/pts based systems by Joe Doupnik <JRD@CC.USU.EDU>
! # $Id: chat2.pl,v 2.2 1993/12/14 11:09:03 lmjm Exp lmjm $
! # $Log: chat2.pl,v $
! # Revision 2.2  1993/12/14  11:09:03  lmjm
! # Only include sys/socket.ph if not already there.
! # Allow for system 5.
! #
! # Revision 2.1  1993/06/28  15:11:07  lmjm
! # Full 2.1 release
! #
  
  package chat;
  
+ unless( defined &'PF_INET ){
+ 	eval "sub ATT { 0; } sub INTEL { 0; }";
+ 	do 'sys/socket.ph';
+ }
+ 
+ 
+ if( defined( &main'PF_INET ) ){
+ 	$pf_inet = &main'PF_INET;
+ 	$sock_stream = &main'SOCK_STREAM;
+ 	local($name, $aliases, $proto) = getprotobyname( 'tcp' );
+ 	$tcp_proto = $proto;
+ }
+ else {
+ 	# XXX hardwired $PF_INET, $SOCK_STREAM, 'tcp'
+ 	# but who the heck would change these anyway? (:-)
+ 	$pf_inet = 2;
+ 	$sock_stream = 1;
+ 	$tcp_proto = 6;
+ }
+ 
+ 
  $sockaddr = 'S n a4 x8';
! chop( $thishost = `(hostname || uname -n || uuname -l) 2>/dev/null` );
  
  # *S = symbol for current I/O, gets assigned *chatsymbol....
  $next = "chatsymbol000000"; # next one
***************
*** 21,26 ****
--- 52,61 ----
  
  	local($serveraddr,$serverproc);
  
+ 	# We may be multi-homed, start with 0, fixup once connexion is made
+ 	$thisaddr = "\0\0\0\0" ;
+ 	$thisproc = pack($sockaddr, 2, 0, $thisaddr);
+ 
  	*S = ++$next;
  	if ($server =~ /^(\d+)+\.(\d+)\.(\d+)\.(\d+)$/) {
  		$serveraddr = pack('C4', $1, $2, $3, $4);
***************
*** 30,38 ****
  		$serveraddr = $x[4];
  	}
  	$serverproc = pack($sockaddr, 2, $port, $serveraddr);
! 	unless (socket(S, 2, 1, 6)) {
! 		# XXX hardwired $AF_SOCKET, $SOCK_STREAM, 'tcp'
! 		# but who the heck would change these anyway? (:-)
  		($!) = ($!, close(S)); # close S while saving $!
  		return undef;
  	}
--- 65,71 ----
  		$serveraddr = $x[4];
  	}
  	$serverproc = pack($sockaddr, 2, $port, $serveraddr);
! 	unless (socket(S, $pf_inet, $sock_stream, $tcp_proto)) {
  		($!) = ($!, close(S)); # close S while saving $!
  		return undef;
  	}
***************
*** 44,49 ****
--- 77,89 ----
  		($!) = ($!, close(S)); # close S while saving $!
  		return undef;
  	}
+ # We opened with the local address set to ANY, at this stage we know
+ # which interface we are using.  This is critical if our machine is
+ # multi-homed, with IP forwarding off, so fix-up.
+ 	local($fam,$lport);
+ 	($fam,$lport,$thisaddr) = unpack($sockaddr, getsockname(S));
+ 	$thisproc = pack($sockaddr, 2, 0, $thisaddr);
+ # end of post-connect fixup
  	select((select(S), $| = 1)[0]);
  	$next; # return symbol for switcharound
  }
***************
*** 59,67 ****
  	local($thisport) = shift || 0;
  	local($thisproc_local) = pack($sockaddr, 2, $thisport, $thisaddr);
  	local(*NS) = "__" . time;
! 	unless (socket(NS, 2, 1, 6)) {
! 		# XXX hardwired $AF_SOCKET, $SOCK_STREAM, 'tcp'
! 		# but who the heck would change these anyway? (:-)
  		($!) = ($!, close(NS));
  		return undef;
  	}
--- 99,105 ----
  	local($thisport) = shift || 0;
  	local($thisproc_local) = pack($sockaddr, 2, $thisport, $thisaddr);
  	local(*NS) = "__" . time;
! 	unless (socket(NS, $pf_inet, $sock_stream, $tcp_proto)) {
  		($!) = ($!, close(NS));
  		return undef;
  	}
***************
*** 90,96 ****
  	local(*TTY) = "__TTY" . time;
  	local($pty,$tty) = &_getpty(S,TTY);
  	die "Cannot find a new pty" unless defined $pty;
! 	local($pid) = fork;
  	die "Cannot fork: $!" unless defined $pid;
  	unless ($pid) {
  		close STDIN; close STDOUT; close STDERR;
--- 128,134 ----
  	local(*TTY) = "__TTY" . time;
  	local($pty,$tty) = &_getpty(S,TTY);
  	die "Cannot find a new pty" unless defined $pty;
! 	$pid = fork;
  	die "Cannot fork: $!" unless defined $pid;
  	unless ($pid) {
  		close STDIN; close STDOUT; close STDERR;
***************
*** 108,117 ****
  		die "Cannot exec @cmd: $!";
  	}
  	close(TTY);
- 	$PID{$next} = $pid;
  	$next; # return symbol for switcharound
  }
  
  # $S is the read-ahead buffer
  
  ## $return = &chat'expect([$handle,] $timeout_time,
--- 146,179 ----
  		die "Cannot exec @cmd: $!";
  	}
  	close(TTY);
  	$next; # return symbol for switcharound
  }
  
+ # &chat'read([$handle,] $buf, $ntoread )
+ # blocking read. returns no. of bytes read and puts data in $buf.
+ # If called with ntoread < 0 then just do the accept and return 0.
+ sub read { ## public
+ 	if ($_[0] =~ /$nextpat/) {
+ 		*S = shift;
+ 	}
+ 	*chatreadbuf = shift;
+ 	$chatreadn = shift;
+ 	
+ 	if (defined $S{"needs_accept"}) { # is it a listen socket?
+ 		local(*NS) = $S{"needs_accept"};
+ 		delete $S{"needs_accept"};
+ 		$S{"needs_close"} = *NS;
+ 		unless(accept(S,NS)) {
+ 			($!) = ($!, close(S), close(NS));
+ 			return undef;
+ 		}
+ 		select((select(S), $| = 1)[0]);
+ 	}
+ 	if( $chatreadn > 0 ){
+ 		return sysread(S, $chatreadbuf, $chatreadn );
+ 	}
+ }
+ 
  # $S is the read-ahead buffer
  
  ## $return = &chat'expect([$handle,] $timeout_time,
***************
*** 224,229 ****
--- 286,295 ----
  		 		select($rmask, undef, undef, $endtime - time);
  			if ($nfound) {
  				$nread = sysread(S, $thisbuf, 1024);
+ 				if( $chat'debug ){
+ 					print STDERR "sysread $nread ";
+ 					print STDERR ">>$thisbuf<<\n";
+ 				}
  				if ($nread > 0) {
  					$S .= $thisbuf;
  				} else {
***************
*** 252,257 ****
--- 318,327 ----
  		*S = shift;
  	}
  	print S @_;
+ 	if( $chat'debug ){
+ 		print STDERR "printed:";
+ 		print STDERR @_;
+ 	}
  }
  
  ## &chat'close([$handle,])
***************
*** 259,273 ****
  ## like close $handle
  
  sub close { ## public
- 	local($pid);
  	if ($_[0] =~ /$nextpat/) {
- 		$pid = $PID{$_[0]};
  	 	*S = shift;
- 	} else {
- 		$pid = $PID{$next};
  	}
  	close(S);
- 	waitpid($pid,0);
  	if (defined $S{"needs_close"}) { # is it a listen socket?
  		local(*NS) = $S{"needs_close"};
  		delete $S{"needs_close"};
--- 329,338 ----
***************
*** 314,329 ****
  # internal procedure to get the next available pty.
  # opens pty on handle PTY, and matching tty on handle TTY.
  # returns undef if can't find a pty.
  
  sub _getpty { ## private
  	local($_PTY,$_TTY) = @_;
  	$_PTY =~ s/^([^']+)$/(caller)[$[]."'".$1/e;
  	$_TTY =~ s/^([^']+)$/(caller)[$[]."'".$1/e;
! 	local($pty,$tty);
  	for $bank (112..127) {
! 		next unless -e sprintf("/dev/pty%c0", $bank);
  		for $unit (48..57) {
! 			$pty = sprintf("/dev/pty%c%c", $bank, $unit);
  			open($_PTY,"+>$pty") || next;
  			select((select($_PTY), $| = 1)[0]);
  			($tty = $pty) =~ s/pty/tty/;
--- 379,400 ----
  # internal procedure to get the next available pty.
  # opens pty on handle PTY, and matching tty on handle TTY.
  # returns undef if can't find a pty.
+ # Modify "/dev/pty" to "/dev/pts" for Dell Unix v2.2 (aka SVR4.04). Joe Doupnik.
  
  sub _getpty { ## private
  	local($_PTY,$_TTY) = @_;
  	$_PTY =~ s/^([^']+)$/(caller)[$[]."'".$1/e;
  	$_TTY =~ s/^([^']+)$/(caller)[$[]."'".$1/e;
! 	local($pty, $tty, $kind);
! 	if( -e "/dev/pts000" ){		## mods by Joe Doupnik Dec 1992
! 		$kind = "pts";		## SVR4 Streams
! 	} else {
! 		$kind = "pty";		## BSD Clist stuff
! 	}
  	for $bank (112..127) {
! 		next unless -e sprintf("/dev/$kind%c0", $bank);
  		for $unit (48..57) {
! 			$pty = sprintf("/dev/$kind%c%c", $bank, $unit);
  			open($_PTY,"+>$pty") || next;
  			select((select($_PTY), $| = 1)[0]);
  			($tty = $pty) =~ s/pty/tty/;


Jonathan M. Bresler        FreeBSD Postmaster         jmb@FreeBSD.ORG
play go. ride bike. hack FreeBSD.--ah the good life 
i am moving to a new job.                 PLEASE USE: jmb@FreeBSD.ORG




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.3.89.9511301117.E6978-0100000>