r1080 - trunk/glibc-2.3-head/sysdeps/kfreebsd

2006-01-20 Thread Robert Millan
Author: rmh
Date: 2006-01-20 10:16:42 + (Fri, 20 Jan 2006)
New Revision: 1080

Modified:
   trunk/glibc-2.3-head/sysdeps/kfreebsd/uname.c
Log:
Misc cleanup and optimisations in uname:
- Less agressive use of stack.
- Use strcpy instead of strncpy when copying sysname (bounds check is done at 
build time).
- Remove fallback values.  If the kernel doesn't know, we don't either.
(Still using sysctls. uname syscall sets broken version and machine components)

Modified: trunk/glibc-2.3-head/sysdeps/kfreebsd/uname.c
===
--- trunk/glibc-2.3-head/sysdeps/kfreebsd/uname.c   2006-01-19 22:09:38 UTC 
(rev 1079)
+++ trunk/glibc-2.3-head/sysdeps/kfreebsd/uname.c   2006-01-20 10:16:42 UTC 
(rev 1080)
@@ -1,6 +1,6 @@
-/* Copyright (C) 2002 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
-   Contributed by Bruno Haible <[EMAIL PROTECTED]>, 2002.
+   Contributed by Bruno Haible <[EMAIL PROTECTED]>.
 
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -22,105 +22,80 @@
 #include 
 #include 
 
-/* Dummy values used as a fallback.  */
-#define UNAME_SYSNAME  "GNU/kFreeBSD"
-#define UNAME_RELEASE  "4.0"
-#define UNAME_VERSION  "GENERIC"
-#define UNAME_MACHINE  "mmix"
+#define SYSNAME"GNU/kFreeBSD"
+#define SYSNAME_LEN13
 
+/* Check for bounds in pre-processor */
+#if SYSNAME_LEN > _UTSNAME_SYSNAME_LENGTH
+#error
+#endif
+
 /* Put information about the system in NAME.  */
 int
 __uname (struct utsname *name)
 {
-  /* Fill nodename: "uname -n".  Fetch sysctl "kern.hostname".  */
-  {
-int request[2] = { CTL_KERN, KERN_HOSTNAME };
-size_t len = sizeof (name->nodename);
-if (__sysctl (request, 2, name->nodename, &len, NULL, 0) >= 0)
-  {
-   if (len < sizeof (name->nodename))
- name->nodename[len] = '\0';
-  }
-else
-  {
-   if (errno != ENOMEM)
- strncpy (name->nodename, "localhost", sizeof (name->nodename));
-  }
-  }
+  int request[2] = { CTL_KERN };
+  size_t len;
 
-  /* Fill sysname: "uname -s".  Fetch sysctl "kern.ostype".  */
-  {
-strncpy (name->sysname, UNAME_SYSNAME, sizeof (name->sysname));
-  }
+  /* Fill sysname: "uname -s". */
+  strcpy (name->sysname, SYSNAME);
 
+  /* Fill nodename: "uname -n".  Fetch sysctl "kern.hostname".  */
+  request[1] = KERN_HOSTNAME;
+  len = sizeof (name->nodename);
+  if (__sysctl (request, 2, name->nodename, &len, NULL, 0) >= 0)
+{
+  if (len < sizeof (name->nodename))
+   name->nodename[len] = '\0';
+}
+
   /* Fill release: "uname -r".  Fetch sysctl "kern.osrelease".  */
-  {
-int request[2] = { CTL_KERN, KERN_OSRELEASE };
-size_t len = sizeof (name->release);
-if (__sysctl (request, 2, name->release, &len, NULL, 0) >= 0)
-  {
-   if (len < sizeof (name->release))
- name->release[len] = '\0';
-  }
-else
-  {
-   if (errno != ENOMEM)
- strncpy (name->release, UNAME_RELEASE, sizeof (name->release));
-  }
-  }
+  request[1] = KERN_OSRELEASE;
+  len = sizeof (name->release);
+  if (__sysctl (request, 2, name->release, &len, NULL, 0) >= 0)
+{
+  if (len < sizeof (name->release))
+name->release[len] = '\0';
+}
 
   /* Fill version: "uname -v".  Fetch sysctl "kern.version".  */
-  {
-int request[2] = { CTL_KERN, KERN_VERSION };
-size_t len = sizeof (name->version);
-if (__sysctl (request, 2, name->version, &len, NULL, 0) >= 0)
-  {
-   if (len < sizeof (name->version))
- name->version[len] = '\0';
-  }
-else
-  {
-   if (errno != ENOMEM)
- strncpy (name->version, UNAME_VERSION, sizeof (name->version));
-  }
-
-/* Remove trailing whitespace.  Turn non-trailing whitespace to
-   spaces.  */
+  request[1] = KERN_VERSION;
+  len = sizeof (name->version);
+  if (__sysctl (request, 2, name->version, &len, NULL, 0) >= 0)
 {
-  char *p0 = name->version;
-  char *p = p0 + __strnlen (p0, sizeof (name->version));
-
-  while (p > p0 && (p[-1] == '\t' || p[-1] == '\n' || p[-1] == ' '))
-   *--p = '\0';
-
-  while (p > p0)
-   {
- --p;
- if (*p == '\t' || *p == '\n')
-   *p = ' ';
-   }
+  if (len < sizeof (name->version))
+name->version[len] = '\0';
 }
-  }
 
-  /* Fill machine: "uname -m".  Fetch sysctl "hw.machine".  */
+  /* Remove trailing whitespace.  Turn non-trailing whitespace to
+ spaces.  */
   {
-int request[2] = { CTL_HW, HW_MACHINE };
-size_t len = sizeof (name->machine);
-if (__sysctl (request, 2, name->machine, &len, NULL, 0) >= 0)
+char *p0 = name->version;
+char *p = p0 + __strnlen (p0, sizeof (name->version));
+
+while (p > p0 && (p[-1] == '\t' || p[-1] == '\n' || p[-1] == ' '))
+  *--p = '\0';
+
+while (

r1081 - in trunk/glibc-2.3-head/sysdeps/kfreebsd: . bits

2006-01-20 Thread Petr Salinger
Author: ps-guest
Date: 2006-01-20 10:24:16 + (Fri, 20 Jan 2006)
New Revision: 1081

Modified:
   trunk/glibc-2.3-head/sysdeps/kfreebsd/bits/waitflags.h
   trunk/glibc-2.3-head/sysdeps/kfreebsd/wait3.c
Log:
* define WCONTINUED, WSTOPPED
* reuse linux version of wait3.c (which is bsd4.4 version for now)


Modified: trunk/glibc-2.3-head/sysdeps/kfreebsd/bits/waitflags.h
===
--- trunk/glibc-2.3-head/sysdeps/kfreebsd/bits/waitflags.h  2006-01-20 
10:16:42 UTC (rev 1080)
+++ trunk/glibc-2.3-head/sysdeps/kfreebsd/bits/waitflags.h  2006-01-20 
10:24:16 UTC (rev 1081)
@@ -26,6 +26,10 @@
 #defineWNOHANG 1   /* Don't block waiting.  */
 #defineWUNTRACED   2   /* Report status of stopped children.  
*/
 
+/* Bits in the fourth argument to `waitid'.  */
+#defineWSTOPPED2   /* Report stopped child (same as 
WUNTRACED). */
+#defineWCONTINUED  4   /* Report continued child.  */
+
 #define __WCLONE   0x8000  /* Wait for cloned process.  */
 #ifdef __USE_BSD
 # define WLINUXCLONE   __WCLONE/* FreeBSD name for __WCLONE.  */

Modified: trunk/glibc-2.3-head/sysdeps/kfreebsd/wait3.c
===
--- trunk/glibc-2.3-head/sysdeps/kfreebsd/wait3.c   2006-01-20 10:16:42 UTC 
(rev 1080)
+++ trunk/glibc-2.3-head/sysdeps/kfreebsd/wait3.c   2006-01-20 10:24:16 UTC 
(rev 1081)
@@ -1,38 +1 @@
-/* Copyright (C) 1991, 1992, 1993, 1995, 1997 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
-
-#include 
-#include 
-#include 
-#include 
-
-/* Wait for a child to exit.  When one does, put its status in *STAT_LOC and
-   return its process ID.  For errors return (pid_t) -1.  If USAGE is not nil,
-   store information about the child's resource usage (as a `struct rusage')
-   there.  If the WUNTRACED bit is set in OPTIONS, return status for stopped
-   children; otherwise don't.  */
-pid_t
-__wait3 (stat_loc, options, usage)
- __WAIT_STATUS stat_loc;
- int options;
- struct rusage *usage;
-{
-  return __wait4(WAIT_ANY, stat_loc, options, usage);
-}
-
-weak_alias (__wait3, wait3)
+#include 


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



r1082 - trunk/glibc-2.3-head/sysdeps/kfreebsd/x86_64

2006-01-20 Thread Petr Salinger
Author: ps-guest
Date: 2006-01-20 10:49:21 + (Fri, 20 Jan 2006)
New Revision: 1082

Added:
   trunk/glibc-2.3-head/sysdeps/kfreebsd/x86_64/get_clockfreq.c
Log:
amd64 - reuse get_clockfreq


Added: trunk/glibc-2.3-head/sysdeps/kfreebsd/x86_64/get_clockfreq.c
===
--- trunk/glibc-2.3-head/sysdeps/kfreebsd/x86_64/get_clockfreq.c
2006-01-20 10:24:16 UTC (rev 1081)
+++ trunk/glibc-2.3-head/sysdeps/kfreebsd/x86_64/get_clockfreq.c
2006-01-20 10:49:21 UTC (rev 1082)
@@ -0,0 +1 @@
+#include "../i386/get_clockfreq.c"


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



r1083 - trunk/glibc-2.3-head/sysdeps/kfreebsd

2006-01-20 Thread Petr Salinger
Author: ps-guest
Date: 2006-01-20 16:54:08 + (Fri, 20 Jan 2006)
New Revision: 1083

Modified:
   trunk/glibc-2.3-head/sysdeps/kfreebsd/ptsname.c
Log:
* FreeBSD 6.0 has dynamic major number allocation for pseudo terminals 
(kern/tty_pty.c) 


Modified: trunk/glibc-2.3-head/sysdeps/kfreebsd/ptsname.c
===
--- trunk/glibc-2.3-head/sysdeps/kfreebsd/ptsname.c 2006-01-20 10:49:21 UTC 
(rev 1082)
+++ trunk/glibc-2.3-head/sysdeps/kfreebsd/ptsname.c 2006-01-20 16:54:08 UTC 
(rev 1083)
@@ -38,13 +38,6 @@
   return __ptsname_r (fd, buffer, sizeof (buffer)) != 0 ? NULL : buffer;
 }
 
-
-/* Check if DEV corresponds to a master pseudo terminal device.  */
-#define MASTER_P(dev) (major (dev) == 6)
-
-/* Check if DEV corresponds to a master pseudo terminal device.  */
-#define SLAVE_P(dev) (major (dev) == 5)
-
 /* The are declared in getpt.c.  */
 extern const char __libc_ptyname1[] attribute_hidden;
 extern const char __libc_ptyname2[] attribute_hidden;
@@ -73,7 +66,7 @@
 return errno;
 
   /* Check if FD really is a master pseudo terminal.  */
-  if (!(S_ISCHR (st.st_mode) && MASTER_P (st.st_rdev)))
+  if (!(S_ISCHR (st.st_mode)))
 {
   __set_errno (ENOTTY);
   return ENOTTY;
@@ -103,7 +96,7 @@
 
   /* Check if the pathname we're about to return really corresponds to the
  slave pseudo terminal of the given master pseudo terminal.  */
-  if (!(S_ISCHR (st.st_mode) && SLAVE_P (st.st_rdev)
+  if (!(S_ISCHR (st.st_mode)
&& (unsigned int) minor (st.st_rdev) == ptyno))
 {
   /* This really is a configuration problem.  */


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



Re: r1073 - trunk/glibc-2.3-head/sysdeps/kfreebsd

2006-01-20 Thread Aurelien Jarno
On Wed, Jan 18, 2006 at 11:27:24PM +, Robert Millan wrote:
> Author: rmh
> Date: 2006-01-18 23:27:24 + (Wed, 18 Jan 2006)
> New Revision: 1073
> 
> Modified:
>trunk/glibc-2.3-head/sysdeps/kfreebsd/uname.c
> Log:
> Rewrite uname.c to use SYS_uname.  Runs 1.54 faster.
> 

This is the comment in the FreeBSD kernel, file sys/kern/kern_xxx.c

/*
 * This is the FreeBSD-1.1 compatable uname(2) interface.  These
 * days it is done in libc as a wrapper around a bunch of sysctl's.
 * This must maintain the old 1.1 binary ABI.
 */

Then if you look at the code corresponding to the syscall, you will see 
that the syscall correspond to a call to the corresponding sysctl, but
truncated:

...

name[0] = CTL_KERN;
name[1] = KERN_OSTYPE;
len = sizeof (uap->name->sysname);
mtx_lock(&Giant);
error = userland_sysctl(td, name, 2, uap->name->sysname, &len,
1, 0, 0, 0);
if (error)
goto done2;
subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);

...


So, in short the current implementation in our glibc is the correct one.

Bye,
Aurelien

-- 
  .''`.  Aurelien Jarno | GPG: 1024D/F1BCDB73
 : :' :  Debian developer   | Electrical Engineer
 `. `'   [EMAIL PROTECTED] | [EMAIL PROTECTED]
   `-people.debian.org/~aurel32 | www.aurel32.net


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



r1084 - trunk/glibc-2.3-head/sysdeps/kfreebsd

2006-01-20 Thread Aurelien Jarno
Author: aurel32
Date: 2006-01-20 23:13:52 + (Fri, 20 Jan 2006)
New Revision: 1084

Removed:
   trunk/glibc-2.3-head/sysdeps/kfreebsd/getdomain.c
   trunk/glibc-2.3-head/sysdeps/kfreebsd/setdomain.c
Log:
Remve setdomain.c and getdomain.c, as we now have the corresponding syscalls.



Deleted: trunk/glibc-2.3-head/sysdeps/kfreebsd/getdomain.c
===
--- trunk/glibc-2.3-head/sysdeps/kfreebsd/getdomain.c   2006-01-20 16:54:08 UTC 
(rev 1083)
+++ trunk/glibc-2.3-head/sysdeps/kfreebsd/getdomain.c   2006-01-20 23:13:52 UTC 
(rev 1084)
@@ -1,103 +0,0 @@
-/* Copyright (C) 2002 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Bruno Haible <[EMAIL PROTECTED]>, 2002.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-/* Put the name of the current NIS domain in no more than LEN bytes of NAME.
-   The result is null-terminated if LEN is large enough for the full
-   name and the terminator.  */
-
-int
-getdomainname (char *name, size_t len)
-{
-  /* Fetch the "kern.domainname" sysctl value.  */
-  int request[2] = { CTL_KERN, KERN_NISDOMAINNAME };
-#if 1
-  size_t result_len = len;
-
-  if (__sysctl (request, 2, name, &result_len, NULL, 0) < 0)
-{
-  if (errno == ENOMEM)
-   __set_errno (ENAMETOOLONG);
-  return -1;
-}
-
-  if (result_len == len)
-{
-  __set_errno (ENAMETOOLONG);
-  return -1;
-}
-
-  name[result_len] = '\0';
-  return 0;
-#else
-  char buf[MAXHOSTNAMELEN + 1];
-  char *result;
-  size_t result_len;
-  char *bufend;
-  size_t buflen;
-
-  if (len >= MAXHOSTNAMELEN)
-{
-  result = name;
-  result_len = len - 1;
-}
-  else
-{
-  /* Use a temporary buffer, so that we can detect the ENAMETOOLONG
-condition.  (Well, we could also rely on the ENOMEM error code.)  */
-  result = buf;
-  result_len = MAXHOSTNAMELEN;
-}
-
-  if (__sysctl (request, 2, result, &result_len, NULL, 0) < 0)
-return -1;
-
-  /* If we used no temporary buffer, we are done.  */
-  if (result == name)
-{
-  result[resultlen] = '\0';
-  return 0;
-}
-
-  /* See if the result fits in the caller's buffer.  */
-  bufend = memchr (buf, '\0', result_len);
-  if (bufend == NULL)
-{
-  bufend = buf + result_len;
-  *bufend = '\0';
-}
-  buflen = bufend - buf + 1;
-
-  /* Copy into the caller's buffer.  */
-  memcpy (name, buf, len < buflen ? len : buflen);
-
-  if (len < buflen)
-{
-  __set_errno (ENAMETOOLONG);
-  return -1;
-}
-  return 0;
-#endif
-}
-libc_hidden_def (getdomainname)

Deleted: trunk/glibc-2.3-head/sysdeps/kfreebsd/setdomain.c
===
--- trunk/glibc-2.3-head/sysdeps/kfreebsd/setdomain.c   2006-01-20 16:54:08 UTC 
(rev 1083)
+++ trunk/glibc-2.3-head/sysdeps/kfreebsd/setdomain.c   2006-01-20 23:13:52 UTC 
(rev 1084)
@@ -1,37 +0,0 @@
-/* Copyright (C) 2002 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Bruno Haible <[EMAIL PROTECTED]>, 2002.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
-
-#include 
-#include 
-
-/* Set the name of the current NIS domain to NAME, which is LEN bytes long
-   (excluding a possible trailing NUL byte).  This call is restricted to
-   the super-user.  */
-
-int
-setdomainname (const char *name, size_t len)
-{
-  /* Set the "kern.domainname" sysctl value.  */
-  int request[2] = { CTL_KERN