From muir@idiom.com Sun Jun 20 15:51:25 1999
Return-Path: <muir@idiom.com>
Received: from idiom.com (idiom.com [209.157.64.1])
	by hub.freebsd.org (Postfix) with ESMTP id 0F5E414FF5
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 20 Jun 1999 15:51:23 -0700 (PDT)
	(envelope-from muir@idiom.com)
Received: (from muir@localhost)
	by idiom.com (8.9.3/8.9.3) id PAA97334;
	Sun, 20 Jun 1999 15:51:22 -0700 (PDT)
Message-Id: <199906202251.PAA97334@idiom.com>
Date: Sun, 20 Jun 1999 15:51:22 -0700 (PDT)
From: David Muir Sharnoff <muir@idiom.com>
Reply-To: muir@idiom.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: Sys::Hostname.pm hangs forever
X-Send-Pr-Version: 3.2

>Number:         12311
>Category:       bin
>Synopsis:       Hostname.pm hangs forever
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    markm
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jun 20 16:00:01 PDT 1999
>Closed-Date:    Wed Aug 11 22:19:07 PDT 1999
>Last-Modified:  Tue Apr 29 00:38:55 UTC 2008
>Originator:     David Muir Sharnoff
>Release:        FreeBSD 3.2-RELEASE i386
>Organization:
Idiom
>Environment:

>Description:

	

>How-To-Repeat:

	The following will hang forever

	perl -MSys::Hostname -e '$SIG{"CHLD"} = "IGNORE"; hostname();'

>Fix:


I'm not sure what the real problem is, but the following change to
Hostname.pm will cause the problem to go away.

Index: contrib/perl5/lib/Sys//Hostname.pm
===================================================================
RCS file: /usr/cvs/src/contrib/perl5/lib/Sys/Hostname.pm,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 Hostname.pm
*** Hostname.pm	1998/09/09 06:59:55	1.1.1.1
--- Hostname.pm	1999/06/20 22:23:54
***************
*** 94,100 ****
      # method 3 - trusty old hostname command
      || eval {
  	local $SIG{__DIE__};
! 	$host = `(hostname) 2>/dev/null`; # bsdish
      }
  
      # method 4 - sysV uname command (may truncate)
--- 94,100 ----
      # method 3 - trusty old hostname command
      || eval {
  	local $SIG{__DIE__};
! 	$host = `hostname 2>/dev/null`; # bsdish
      }
  
      # method 4 - sysV uname command (may truncate)


>Release-Note:
>Audit-Trail:

From: David Muir Sharnoff <muir@idiom.com>
To: freebsd-gnats-submit@freebsd.org
Cc:  
Subject: Re: bin/12311: Hostname.pm hangs forever
Date: Sun, 20 Jun 1999 16:08:21 -0700 (PDT)

 The fix I submitted doesn't work in all cases.  Here is a better
 fix:
 
 Index: contrib/perl5/lib/Sys//Hostname.pm
 ===================================================================
 RCS file: /usr/cvs/src/contrib/perl5/lib/Sys/Hostname.pm,v
 retrieving revision 1.1.1.1
 diff -c -r1.1.1.1 Hostname.pm
 *** Hostname.pm	1998/09/09 06:59:55	1.1.1.1
 --- Hostname.pm	1999/06/20 22:59:51
 ***************
 *** 94,99 ****
 --- 94,100 ----
       # method 3 - trusty old hostname command
       || eval {
   	local $SIG{__DIE__};
 + 	local $SIG{CHLD};
   	$host = `(hostname) 2>/dev/null`; # bsdish
       }
   
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: muir@idiom.com
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/12311: Sys::Hostname.pm hangs forever 
Date: Mon, 21 Jun 1999 18:49:32 +0200

 Hi David,
 
 Your fix definitely makes the problem go away, but what about callers
 that really _don't_ want to receive a SIGCHLD?
 
 Ciao,
 Sheldon.
 

From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To: Sheldon Hearn <sheldonh@uunet.co.za>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/12311: Sys::Hostname.pm hangs forever 
Date: Mon, 21 Jun 1999 13:22:46 -0400 (EDT)

 <<On Mon, 21 Jun 1999 09:50:01 -0700 (PDT), Sheldon Hearn <sheldonh@uunet.co.za> said:
 
 >  Your fix definitely makes the problem go away, but what about callers
 >  that really _don't_ want to receive a SIGCHLD?
  
 The correct fix is to create a FreeBSD-specific mechanism to get the
 hostname.  (This took me all of ten minutes to do, most of which was
 deleting all of the cruft h2xs put in that was not needed.)  Then,
 Sys::Hostname gets the following addition:
 
 	} elsif ($^O eq 'freebsd') {
 		require FreeBSD;
 		$host = "\0" x 1024; # XXX should import MAXHOSTNAMELEN
 		&FreeBSD::gethostname($host, length($host));
 	}
 
 -GAWollman
 
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/12311: Sys::Hostname.pm hangs forever 
Date: Mon, 21 Jun 1999 19:56:41 +0200

 On Mon, 21 Jun 1999 13:22:46 -0400, Garrett Wollman wrote:
 
 > 		require FreeBSD;
 
 What?
 
 Ciao,
 Sheldon.
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/12311: Sys::Hostname.pm hangs forever 
Date: Mon, 21 Jun 1999 20:05:14 +0200

 Hi Garrett,
 
 I'm not sure how that "require FreeBSD" is supposed to work, but I came
 up with the diff below. The only problem is that unistd.ph isn't
 declaring SYS_gethostname as expected.
 
 Any idea what's wrong?
 
 Ciao,
 Sheldon.
 
 
 Index: Hostname.pm
 ===================================================================
 RCS file: /home/ncvs/src/contrib/perl5/lib/Sys/Hostname.pm,v
 retrieving revision 1.1.1.1
 diff -u -d -r1.1.1.1 Hostname.pm
 --- Hostname.pm	1998/09/09 06:59:55	1.1.1.1
 +++ Hostname.pm	1999/06/21 18:02:54
 @@ -60,6 +60,14 @@
      Carp::croak "Cannot get host name of local machine";  
  
    }
 +  elsif ($^O eq 'freebsd') {
 +    require "unistd.ph";
 +    require "sys/param.ph";
 +    require "sys/syscall.ph";
 +    $host = "\0" x MAXHOSTNAMELEN;
 +    syscall(&main::SYS_gethostname, $host, length($host));
 +    $host;
 +  }
    elsif ($^O eq 'MSWin32') {
      ($host) = gethostbyname('localhost');
      chomp($host = `hostname 2> NUL`) unless defined $host;
 
 

From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To: Sheldon Hearn <sheldonh@uunet.co.za>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/12311: Sys::Hostname.pm hangs forever 
Date: Mon, 21 Jun 1999 14:17:34 -0400 (EDT)

 <<On Mon, 21 Jun 1999 20:05:14 +0200, Sheldon Hearn <sheldonh@uunet.co.za> said:
 
 > I'm not sure how that "require FreeBSD" is supposed to work, but I came
 > up with the diff below. The only problem is that unistd.ph isn't
 > declaring SYS_gethostname as expected.
 
 You have to actually WRITE FreeBSD.xs, integrate it with the Perl
 build system, and cause the resulting object files to be installed in
 a `make world'.
 
 There is no gethostname syscall.
 
 -GAWollman
 
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/12311: Sys::Hostname.pm hangs forever 
Date: Mon, 21 Jun 1999 20:21:11 +0200

 On Mon, 21 Jun 1999 14:17:34 -0400, Garrett Wollman wrote:
 
 > There is no gethostname syscall.
 
 Then I'm seriously confused. I have a gethostname(3) manpage on my
 FreeBSD 4.0-CURRENT system.
 
 Ciao,
 Sheldon.
 

From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To: Sheldon Hearn <sheldonh@uunet.co.za>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/12311: Sys::Hostname.pm hangs forever 
Date: Mon, 21 Jun 1999 14:44:02 -0400 (EDT)

 <<On Mon, 21 Jun 1999 20:21:11 +0200, Sheldon Hearn <sheldonh@uunet.co.za> said:
 
 > On Mon, 21 Jun 1999 14:17:34 -0400, Garrett Wollman wrote:
 
 >> There is no gethostname syscall.
 
 > Then I'm seriously confused. I have a gethostname(3) manpage on my
 > FreeBSD 4.0-CURRENT system.
 
 Exactly.  If it were a syscall it would be in section 2.
 
 -GAWollman
 
 

From: "Gary Palmer" <gpalmer@freebsd.org>
To: freebsd-gnats-submit@freebsd.org
Cc:  
Subject: Re: bin/12311: Sys::Hostname.pm hangs forever 
Date: Mon, 21 Jun 1999 18:52:12 -0400

 Sheldon Hearn wrote in message ID
 <199906211830.LAA93737@freefall.freebsd.org>:
 >  Then I'm seriously confused. I have a gethostname(3) manpage on my
 >  FreeBSD 4.0-CURRENT system.
 
 host% man 3 intro
 Formatting page, please wait...Done.
 
 INTRO(3)               FreeBSD Library Functions Manual               INTRO(3)
 
 NAME
      intro - introduction to the C libraries
 
 [ snip ]
 
 host% man 2 intro
 Formatting page, please wait...Done.
 
 INTRO(2)                  FreeBSD System Calls Manual                 INTRO(2)
 
 NAME
      intro - introduction to system calls and error numbers
 
 [ snip ]
 
State-Changed-From-To: open->analyzed 
State-Changed-By: sheldonh 
State-Changed-When: Mon Jul 19 02:56:19 PDT 1999 
State-Changed-Why:  
I've received an explanation of the problem from wosch, who suggests 
that we implement a FreeBSD.xs for a proper fix. 


Responsible-Changed-From-To: freebsd-bugs->sheldonh 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Mon Jul 19 02:56:19 PDT 1999 
Responsible-Changed-Why:  
Now that my perl guru's back from the States, I'll take this one. 
Responsible-Changed-From-To: sheldonh->markm 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Tue Jul 20 08:13:30 PDT 1999 
Responsible-Changed-Why:  
Looks like the guru himself has taken this one on. Fixed in 
rev 1.2 of Hostname.pm, MFC to follow. 
State-Changed-From-To: analyzed->closed 
State-Changed-By: sheldonh 
State-Changed-When: Wed Aug 11 22:19:07 PDT 1999 
State-Changed-Why:  
Merged to RELENG_3 as well. 
>Unformatted:
