From mkb@wi4d22.informatik.uni-wuerzburg.de  Thu Mar 28 10:56:16 2002
Return-Path: <mkb@wi4d22.informatik.uni-wuerzburg.de>
Received: from reiher.informatik.uni-wuerzburg.de (wi4d22.informatik.uni-wuerzburg.de [132.187.101.122])
	by hub.freebsd.org (Postfix) with ESMTP id C282E37B416
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 28 Mar 2002 10:56:15 -0800 (PST)
Received: by reiher.informatik.uni-wuerzburg.de (Postfix, from userid 1001)
	id BA3F8AC42; Thu, 28 Mar 2002 19:56:13 +0100 (CET)
Message-Id: <20020328185613.BA3F8AC42@reiher.informatik.uni-wuerzburg.de>
Date: Thu, 28 Mar 2002 19:56:13 +0100 (CET)
From: Matthias Buelow <mkb@reiher.informatik.uni-wuerzburg.de>
Reply-To: Matthias Buelow <mkb@reiher.informatik.uni-wuerzburg.de>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: bump up SYS_NMLN in sys/utsname.h
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         36425
>Category:       kern
>Synopsis:       [patch] bump up SYS_NMLN in sys/utsname.h
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Mar 28 11:00:02 PST 2002
>Closed-Date:    Wed Oct 26 00:13:23 GMT 2005
>Last-Modified:  Wed Oct 26 00:13:23 GMT 2005
>Originator:     Matthias Buelow
>Release:        FreeBSD 4.5-STABLE i386
>Organization:
>Environment:
System: FreeBSD reiher.informatik.uni-wuerzburg.de 4.5-STABLE FreeBSD 4.5-STABLE #0: Fri Mar 22 18:00:52 CET 2002 root@reiher.informatik.uni-wuerzburg.de:/usr/src/sys/compile/REIHER i386


>Description:

	The current definition of the SYS_NMLN constant, which defines
	the length of the entries of the utsname structure for use with
	uname(3) is defined in 4.5-STABLE sys/utsname.h as following:

	#define SYS_NMLN        32

	This is probably a leftover from early days and was forgotten
	to update when Internet hostnames became fashionable (up to
	256 characters.)  As a result, one cannot reliably obtain the
	hostname via uname(3), other entries like the "version" field
	are also truncated.  This has caused a problem for me lately
	because the nmh mailer suite was using uname(3) for obtaining
	the hostname and got a truncated one, resulting in some effort
	for identifying and working around the problem.


>How-To-Repeat:

>Fix:

	Update SYS_NMLN to at least 256.  On Solaris 8, it is 257 and
	defined as following:

	#define _SYS_NMLN       257     /* 4.0 size of utsname elements */
					/* Must be at least 257 to      */
					/* support Internet hostnames.  */

	On NetBSD (1.5.1) it is:

	#define _SYS_NMLN       256

	It might also be beneficial to not make SYS_NMLN visible in
	certain cases but define it like the above mentioned systems
	with a prepended underscore, and only defining the SYS_NMLN
	constant when certain conditions hold, on NetBSD and Solaris,
	this is:

	#if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
	#define SYS_NMLN        _SYS_NMLN
	#endif

	although this is just makeup, imho (don't know what the standard
	has to say here but there seems to be a reason if both do it
	the same way.)

>Release-Note:
>Audit-Trail:

From: Garrett Wollman <wollman@lcs.mit.edu>
To: Matthias Buelow <mkb@wi4d22.informatik.uni-wuerzburg.de>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: kern/36425: bump up SYS_NMLN in sys/utsname.h
Date: Thu, 28 Mar 2002 18:44:01 -0500 (EST)

 <<On Thu, 28 Mar 2002 19:56:13 +0100 (CET), Matthias Buelow <mkb@wi4d22.informatik.uni-wuerzburg.de> said:
 
 > 	256 characters.)  As a result, one cannot reliably obtain the
 > 	hostname via uname(3),
 
 This is true in general, which is why POSIX 2001 adopted the
 gethostname() interface.
 
 -GAWollman
 

From: ryan beasley <ryanb@goddamnbastard.org>
To: freebsd-gnats-submit@FreeBSD.org,
	Matthias Buelow <mkb@reiher.informatik.uni-wuerzburg.de>
Cc:  
Subject: Re: kern/36425: bump up SYS_NMLN in sys/utsname.h
Date: Sun, 15 Sep 2002 20:08:13 -0500

 --FeAIMMcddNRN4P4/
 Content-Type: multipart/mixed; boundary="CGDBiGfvSTbxKZlW"
 Content-Disposition: inline
 
 
 --CGDBiGfvSTbxKZlW
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
     (Following up as I've seen this PR is still open.)
 
     Not sure if you already caught this, but this was 'fixed' in -CURRENT
     quite some time ago.  Please refer to PR 4688 and revision 1.8 of
     lib/libc/gen/uname.c.
 
     I've generated the following patch that essentially merges the new
     behavior into -STABLE; buildworld works flawlessly, and I no longer have
     problems w/ truncated hostnames.  (-CURRENT __xuname.c:1.9, uname.c:1.9
     merge into 4.6.2-p2)
 
     Committers:  any chance of a MFC?  (I'm assuming it was 'fixed' in
     -CURRENT for a reason.  <g>)
 
 --=20
 ryan beasley				<ryanb@goddamnbastard.org>
 professional fat bastard		http://www.goddamnbastard.org
 					GPG ID 0x16EFBD48
 
 --CGDBiGfvSTbxKZlW
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="uname.patch"
 Content-Transfer-Encoding: quoted-printable
 
 Index: lib/libc/gen/Makefile.inc
 diff -ruN lib/libc/gen/Makefile.inc.orig lib/libc/gen/Makefile.inc
 --- lib/libc/gen/Makefile.inc.orig	Sun Sep 15 14:24:21 2002
 +++ lib/libc/gen/Makefile.inc	Sun Sep 15 14:25:44 2002
 @@ -4,7 +4,7 @@
  # machine-independent gen sources
  .PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/gen ${.CURDIR}/../libc/gen
 =20
 -SRCS+=3D  _rand48.c _spinlock_stub.c alarm.c arc4random.c assert.c \
 +SRCS+=3D  __xuname.c _rand48.c _spinlock_stub.c alarm.c arc4random.c asser=
 t.c \
  	basename.c \
  	clock.c closedir.c confstr.c \
  	crypt.c ctermid.c daemon.c devname.c dirname.c disklabel.c \
 Index: lib/libc/gen/__xuname.c
 diff -ruN lib/libc/gen/__xuname.c.orig lib/libc/gen/__xuname.c
 --- lib/libc/gen/__xuname.c.orig	Wed Dec 31 18:00:00 1969
 +++ lib/libc/gen/__xuname.c	Sun Sep 15 14:23:53 2002
 @@ -0,0 +1,132 @@
 +/*-
 + * Copyright (c) 1994
 + *	The Regents of the University of California.  All rights reserved.
 + *
 + * Redistribution and use in source and binary forms, with or without
 + * modification, are permitted provided that the following conditions
 + * are met:
 + * 1. Redistributions of source code must retain the above copyright
 + *    notice, this list of conditions and the following disclaimer.
 + * 2. Redistributions in binary form must reproduce the above copyright
 + *    notice, this list of conditions and the following disclaimer in the
 + *    documentation and/or other materials provided with the distribution.
 + * 3. All advertising materials mentioning features or use of this software
 + *    must display the following acknowledgement:
 + *	This product includes software developed by the University of
 + *	California, Berkeley and its contributors.
 + * 4. Neither the name of the University nor the names of its contributors
 + *    may be used to endorse or promote products derived from this software
 + *    without specific prior written permission.
 + *
 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
 OSE
 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT=
 IAL
 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR=
 ICT
 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W=
 AY
 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 + * SUCH DAMAGE.
 + */
 +
 +#if defined(LIBC_SCCS) && !defined(lint)
 +/*static char sccsid[] =3D "From: @(#)uname.c	8.1 (Berkeley) 1/4/94";*/
 +#endif /* LIBC_SCCS and not lint */
 +#include <sys/cdefs.h>
 +__FBSDID("$FreeBSD: src/lib/libc/gen/__xuname.c,v 1.9 2002/02/01 00:57:29 =
 obrien Exp $");
 +
 +#include <sys/param.h>
 +#include <sys/sysctl.h>
 +#include <sys/utsname.h>
 +#include <errno.h>
 +
 +int
 +__xuname(int namesize, void *namebuf)
 +{
 +	int mib[2], rval;
 +	size_t len;
 +	char *p;
 +	int oerrno;
 +	struct xutsname {
 +		char	sysname[namesize];	/* Name of this OS. */
 +		char	nodename[namesize];	/* Name of this network node. */
 +		char	release[namesize];	/* Release level. */
 +		char	version[namesize];	/* Version level. */
 +		char	machine[namesize];	/* Hardware type. */
 +	} *name;
 +
 +	name =3D (struct xutsname *)namebuf;
 +	rval =3D 0;
 +
 +	mib[0] =3D CTL_KERN;
 +	mib[1] =3D KERN_OSTYPE;
 +	len =3D sizeof(name->sysname);
 +	oerrno =3D errno;
 +	if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) =3D=3D -1) {
 +		if(errno =3D=3D ENOMEM)
 +			errno =3D oerrno;
 +		else
 +			rval =3D -1;
 +	}
 +	name->sysname[sizeof(name->sysname) - 1] =3D '\0';
 +
 +	mib[0] =3D CTL_KERN;
 +	mib[1] =3D KERN_HOSTNAME;
 +	len =3D sizeof(name->nodename);
 +	oerrno =3D errno;
 +	if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) =3D=3D -1) {
 +		if(errno =3D=3D ENOMEM)
 +			errno =3D oerrno;
 +		else
 +			rval =3D -1;
 +	}
 +	name->nodename[sizeof(name->nodename) - 1] =3D '\0';
 +
 +	mib[0] =3D CTL_KERN;
 +	mib[1] =3D KERN_OSRELEASE;
 +	len =3D sizeof(name->release);
 +	oerrno =3D errno;
 +	if (sysctl(mib, 2, &name->release, &len, NULL, 0) =3D=3D -1) {
 +		if(errno =3D=3D ENOMEM)
 +			errno =3D oerrno;
 +		else
 +			rval =3D -1;
 +	}
 +	name->release[sizeof(name->release) - 1] =3D '\0';
 +
 +	/* The version may have newlines in it, turn them into spaces. */
 +	mib[0] =3D CTL_KERN;
 +	mib[1] =3D KERN_VERSION;
 +	len =3D sizeof(name->version);
 +	oerrno =3D errno;
 +	if (sysctl(mib, 2, &name->version, &len, NULL, 0) =3D=3D -1) {
 +		if (errno =3D=3D ENOMEM)
 +			errno =3D oerrno;
 +		else
 +			rval =3D -1;
 +	}
 +	name->version[sizeof(name->version) - 1] =3D '\0';
 +	for (p =3D name->version; len--; ++p) {
 +		if (*p =3D=3D '\n' || *p =3D=3D '\t') {
 +			if (len > 1)
 +				*p =3D ' ';
 +			else
 +				*p =3D '\0';
 +		}
 +	}
 +
 +	mib[0] =3D CTL_HW;
 +	mib[1] =3D HW_MACHINE;
 +	len =3D sizeof(name->machine);
 +	oerrno =3D errno;
 +	if (sysctl(mib, 2, &name->machine, &len, NULL, 0) =3D=3D -1) {
 +		if (errno =3D=3D ENOMEM)
 +			errno =3D oerrno;
 +		else
 +			rval =3D -1;
 +	}
 +	name->machine[sizeof(name->machine) - 1] =3D '\0';
 +	return (rval);
 +}
 Index: lib/libc/gen/uname.c
 diff -ruN lib/libc/gen/uname.c.orig lib/libc/gen/uname.c
 --- lib/libc/gen/uname.c.orig	Sun Sep 15 14:23:12 2002
 +++ lib/libc/gen/uname.c	Sun Sep 15 14:23:26 2002
 @@ -32,94 +32,20 @@
   */
 =20
  #if defined(LIBC_SCCS) && !defined(lint)
 -/*static char sccsid[] =3D "From: @(#)uname.c	8.1 (Berkeley) 1/4/94";*/
 -static const char rcsid[] =3D
 -  "$FreeBSD: src/lib/libc/gen/uname.c,v 1.7 1999/08/27 23:59:06 peter Exp =
 $";
 +static char sccsid[] =3D "From: @(#)uname.c	8.1 (Berkeley) 1/4/94";
  #endif /* LIBC_SCCS and not lint */
 +#include <sys/cdefs.h>
 +__FBSDID("$FreeBSD: src/lib/libc/gen/uname.c,v 1.9 2002/02/01 00:57:29 obr=
 ien Exp $");
 =20
 +#define uname wrapped_uname
  #include <sys/param.h>
  #include <sys/sysctl.h>
  #include <sys/utsname.h>
  #include <errno.h>
 +#undef uname
 =20
  int
 -uname(name)
 -	struct utsname *name;
 +uname(struct utsname *name)
  {
 -	int mib[2], rval;
 -	size_t len;
 -	char *p;
 -	int oerrno;
 -
 -	rval =3D 0;
 -
 -	mib[0] =3D CTL_KERN;
 -	mib[1] =3D KERN_OSTYPE;
 -	len =3D sizeof(name->sysname);
 -	oerrno =3D errno;
 -	if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) =3D=3D -1) {
 -		if(errno =3D=3D ENOMEM)
 -			errno =3D oerrno;
 -		else
 -			rval =3D -1;
 -	}
 -	name->sysname[sizeof(name->sysname) - 1] =3D '\0';
 -
 -	mib[0] =3D CTL_KERN;
 -	mib[1] =3D KERN_HOSTNAME;
 -	len =3D sizeof(name->nodename);
 -	oerrno =3D errno;
 -	if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) =3D=3D -1) {
 -		if(errno =3D=3D ENOMEM)
 -			errno =3D oerrno;
 -		else
 -			rval =3D -1;
 -	}
 -	name->nodename[sizeof(name->nodename) - 1] =3D '\0';
 -
 -	mib[0] =3D CTL_KERN;
 -	mib[1] =3D KERN_OSRELEASE;
 -	len =3D sizeof(name->release);
 -	oerrno =3D errno;
 -	if (sysctl(mib, 2, &name->release, &len, NULL, 0) =3D=3D -1) {
 -		if(errno =3D=3D ENOMEM)
 -			errno =3D oerrno;
 -		else
 -			rval =3D -1;
 -	}
 -	name->release[sizeof(name->release) - 1] =3D '\0';
 -
 -	/* The version may have newlines in it, turn them into spaces. */
 -	mib[0] =3D CTL_KERN;
 -	mib[1] =3D KERN_VERSION;
 -	len =3D sizeof(name->version);
 -	oerrno =3D errno;
 -	if (sysctl(mib, 2, &name->version, &len, NULL, 0) =3D=3D -1) {
 -		if (errno =3D=3D ENOMEM)
 -			errno =3D oerrno;
 -		else
 -			rval =3D -1;
 -	}
 -	name->version[sizeof(name->version) - 1] =3D '\0';
 -	for (p =3D name->version; len--; ++p) {
 -		if (*p =3D=3D '\n' || *p =3D=3D '\t') {
 -			if (len > 1)
 -				*p =3D ' ';
 -			else
 -				*p =3D '\0';
 -		}
 -	}
 -
 -	mib[0] =3D CTL_HW;
 -	mib[1] =3D HW_MACHINE;
 -	len =3D sizeof(name->machine);
 -	oerrno =3D errno;
 -	if (sysctl(mib, 2, &name->machine, &len, NULL, 0) =3D=3D -1) {
 -		if (errno =3D=3D ENOMEM)
 -			errno =3D oerrno;
 -		else
 -			rval =3D -1;
 -	}
 -	name->machine[sizeof(name->machine) - 1] =3D '\0';
 -	return (rval);
 +	return __xuname(32, name);
  }
 Index: sys/sys/utsname.h
 diff -ruN sys/sys/utsname.h.orig sys/sys/utsname.h
 --- sys/sys/utsname.h.orig	Sun Sep 15 14:22:32 2002
 +++ sys/sys/utsname.h	Sun Sep 15 14:22:53 2002
 @@ -37,10 +37,17 @@
   * $FreeBSD: src/sys/sys/utsname.h,v 1.7 1999/12/29 04:24:49 peter Exp $
   */
 =20
 +
  #ifndef	_SYS_UTSNAME_H
  #define	_SYS_UTSNAME_H
 =20
 -#define SYS_NMLN	32
 +#ifdef _KERNEL
 +#define	SYS_NMLN	32		/* uname(2) for the FreeBSD 1.1 ABI. */
 +#endif
 +
 +#ifndef SYS_NMLN
 +#define	SYS_NMLN	256		/* User can override. */
 +#endif
 =20
  struct utsname {
  	char	sysname[SYS_NMLN];	/* Name of this OS. */
 @@ -50,20 +57,18 @@
  	char	machine[SYS_NMLN];	/* Hardware type. */
  };
 =20
 -
  #include <sys/cdefs.h>
 =20
 -
  #ifndef _KERNEL
 -#ifdef __STDC__
  __BEGIN_DECLS
 -int	uname __P((struct utsname *));
 +int	__xuname(int, void *);		/* Variable record size. */
  __END_DECLS
 -#else
 -extern int uname();
 -#endif
 -#else
 -extern struct utsname utsname;
 +
 +static __inline int
 +uname(struct utsname *name)
 +{
 +	return __xuname(SYS_NMLN, (void *)name);
 +}
  #endif	/* _KERNEL */
 =20
  #endif	/* !_SYS_UTSNAME_H */
 
 --CGDBiGfvSTbxKZlW--
 
 --FeAIMMcddNRN4P4/
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.7 (FreeBSD)
 
 iD8DBQE9hS79skfdOxbvvUgRAsxfAJ9cfKOyktlGK0DCc26wYOfCeg6iwQCffEGg
 V/HfpV4vWyHEd8BHkXJiEbQ=
 =sB04
 -----END PGP SIGNATURE-----
 
 --FeAIMMcddNRN4P4/--
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Wed Oct 26 00:12:54 GMT 2005 
State-Changed-Why:  
This is unlikely to be merged back into 4.X at this point.  It's been in 
5.X for a couple of years. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=36425 
>Unformatted:
