[newlib-cygwin] Cygwin: uname: Raise size of utsname fields and revamp uname(2) output

Corinna Vinschen corinna@sourceware.org
Sat Jan 26 17:40:00 GMT 2019


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=84230b71c64765ad0e34faffdfe6d1c58477a84d

commit 84230b71c64765ad0e34faffdfe6d1c58477a84d
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Thu Jan 24 12:01:01 2019 +0100

    Cygwin: uname: Raise size of utsname fields and revamp uname(2) output
    
    New format:
    
      sysname:      CYGWIN_NT-${osversion}-${os_build_number}[-WOW64]
      nodename:     `gethostname`
      release:      ${cygwin_version}-${API minor}.${arch}[.snap]
      version:      YYYY-MM-DD HH:MM UTC
      machine:      ${arch}
    _GNU_SOURCE:
      domainname:   `getdomainname`
    !_GNU_SOURCE:
      __domainname: `getdomainname`
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/Makefile.in              |  1 +
 winsup/cygwin/common.din               |  1 +
 winsup/cygwin/include/cygwin/version.h |  3 +-
 winsup/cygwin/include/sys/utsname.h    | 17 ++++++---
 winsup/cygwin/release/2.12.0           |  2 +
 winsup/cygwin/uname.cc                 | 70 +++++++++++++++++++++++++++++++++-
 winsup/cygwin/wincap.h                 |  1 +
 winsup/doc/new-features.xml            |  4 ++
 8 files changed, 92 insertions(+), 7 deletions(-)

diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in
index 32c02b8..ecdabb0 100644
--- a/winsup/cygwin/Makefile.in
+++ b/winsup/cygwin/Makefile.in
@@ -440,6 +440,7 @@ GMON_OFILES:=gmon.o mcount.o profil.o mcountFunc.o
 NEW_FUNCTIONS:=$(addprefix --replace=,\
 	atexit= \
 	timezone= \
+	uname=uname_x \
 	__xdrrec_getrec= \
 	__xdrrec_setnonblock= \
 	xdr_array= \
diff --git a/winsup/cygwin/common.din b/winsup/cygwin/common.din
index ca819c6..f620d81 100644
--- a/winsup/cygwin/common.din
+++ b/winsup/cygwin/common.din
@@ -1522,6 +1522,7 @@ ualarm SIGFE
 umask NOSIGFE
 umount SIGFE
 uname SIGFE
+uname_x SIGFE
 ungetc SIGFE
 ungetwc SIGFE
 unlink SIGFE
diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h
index c3e971e..478d080 100644
--- a/winsup/cygwin/include/cygwin/version.h
+++ b/winsup/cygwin/include/cygwin/version.h
@@ -505,12 +505,13 @@ details. */
   332: Add signalfd.
   333: Add timerfd_create, timerfd_gettime, timerfd_settime.
   334: Remove matherr.
+  335: Change size of utsname, change uname output.
 
   Note that we forgot to bump the api for ualarm, strtoll, strtoull,
   sigaltstack, sethostname. */
 
 #define CYGWIN_VERSION_API_MAJOR 0
-#define CYGWIN_VERSION_API_MINOR 334
+#define CYGWIN_VERSION_API_MINOR 335
 
 /* There is also a compatibity version number associated with the shared memory
    regions.  It is incremented when incompatible changes are made to the shared
diff --git a/winsup/cygwin/include/sys/utsname.h b/winsup/cygwin/include/sys/utsname.h
index e9dd019..d6b3be9 100644
--- a/winsup/cygwin/include/sys/utsname.h
+++ b/winsup/cygwin/include/sys/utsname.h
@@ -13,13 +13,20 @@ details. */
 extern "C" {
 #endif
 
+#define _UTSNAME_LENGTH 65
+
 struct utsname
 {
-  char sysname[20];
-  char nodename[20];
-  char release[20];
-  char version[20];
-  char machine[20];
+  char sysname[_UTSNAME_LENGTH];
+  char nodename[_UTSNAME_LENGTH];
+  char release[_UTSNAME_LENGTH];
+  char version[_UTSNAME_LENGTH];
+  char machine[_UTSNAME_LENGTH];
+#if __GNU_VISIBLE
+  char domainname[_UTSNAME_LENGTH];
+#else
+  char __domainname[_UTSNAME_LENGTH];
+#endif
 };
 
 int uname (struct utsname *);
diff --git a/winsup/cygwin/release/2.12.0 b/winsup/cygwin/release/2.12.0
index c2abc93..19e0556 100644
--- a/winsup/cygwin/release/2.12.0
+++ b/winsup/cygwin/release/2.12.0
@@ -56,6 +56,8 @@ What changed:
 - Remove matherr, and SVID and X/Open math library configurations.
   Default math library configuration is now IEEE.
 
+- Improve uname(2) for newly built applications.
+
 
 Bug Fixes
 ---------
diff --git a/winsup/cygwin/uname.cc b/winsup/cygwin/uname.cc
index 778ca57..306cdee 100644
--- a/winsup/cygwin/uname.cc
+++ b/winsup/cygwin/uname.cc
@@ -10,15 +10,83 @@ details. */
 
 #include "winsup.h"
 #include <sys/utsname.h>
+#include <netdb.h>
 #include "cygwin_version.h"
 #include "cygtls.h"
 
 extern "C" int cygwin_gethostname (char *__name, size_t __len);
+extern "C" int getdomainname (char *__name, size_t __len);
 
 /* uname: POSIX 4.4.1.1 */
+
+/* New entrypoint for applications since API 335 */
+extern "C" int
+uname_x (struct utsname *name)
+{
+  __try
+    {
+      char buf[NI_MAXHOST + 1];
+      char *snp = strstr (cygwin_version.dll_build_date, "SNP");
+
+      memset (name, 0, sizeof (*name));
+      /* sysname */
+      __small_sprintf (name->sysname, "CYGWIN_%s-%u%s",
+		       wincap.osname (), wincap.build_number (),
+		       wincap.is_wow64 () ? "-WOW64" : "");
+      /* nodename */
+      memset (buf, 0, sizeof buf);
+      cygwin_gethostname (buf, sizeof buf - 1);
+      strncat (name->nodename, buf, sizeof (name->nodename) - 1);
+      /* release */
+      __small_sprintf (name->release, "%d.%d.%d-%d.",
+		       cygwin_version.dll_major / 1000,
+		       cygwin_version.dll_major % 1000,
+		       cygwin_version.dll_minor,
+		       cygwin_version.api_minor);
+      /* version */
+      stpcpy (name->version, cygwin_version.dll_build_date);
+      if (snp)
+	name->version[snp - cygwin_version.dll_build_date] = '\0';
+      strcat (name->version, " UTC");
+      /* machine */
+      switch (wincap.cpu_arch ())
+	{
+	  case PROCESSOR_ARCHITECTURE_INTEL:
+	    strcat (name->release, strcpy (name->machine, "i686"));
+	    break;
+	  case PROCESSOR_ARCHITECTURE_AMD64:
+	    strcat (name->release, strcpy (name->machine, "x86_64"));
+	    break;
+	  default:
+	    strcpy (name->machine, "unknown");
+	    break;
+	}
+      if (snp)
+	strcat (name->release, ".snap");
+      /* domainame */
+      memset (buf, 0, sizeof buf);
+      getdomainname (buf, sizeof buf - 1);
+      strncat (name->domainname, buf, sizeof (name->domainname) - 1);
+    }
+  __except (EFAULT) { return -1; }
+  __endtry
+  return 0;
+}
+
+/* Old entrypoint for applications up to API 334 */
+struct old_utsname
+{
+  char sysname[20];
+  char nodename[20];
+  char release[20];
+  char version[20];
+  char machine[20];
+};
+
 extern "C" int
-uname (struct utsname *name)
+uname (struct utsname *in_name)
 {
+  struct old_utsname *name = (struct old_utsname *) in_name;
   __try
     {
       char *snp = strstr  (cygwin_version.dll_build_date, "SNP");
diff --git a/winsup/cygwin/wincap.h b/winsup/cygwin/wincap.h
index d89fd71..f8846f9 100644
--- a/winsup/cygwin/wincap.h
+++ b/winsup/cygwin/wincap.h
@@ -59,6 +59,7 @@ public:
   const size_t allocation_granularity () const
 		     { return (size_t) system_info.dwAllocationGranularity; }
   const char *osname () const { return osnam; }
+  const DWORD build_number () const { return version.dwBuildNumber; }
   const bool is_wow64 () const { return !!wow64; }
 
 #define IMPLEMENT(cap) cap() const { return ((wincaps *) this->caps)->cap; }
diff --git a/winsup/doc/new-features.xml b/winsup/doc/new-features.xml
index 59db9c9..ae5088d 100644
--- a/winsup/doc/new-features.xml
+++ b/winsup/doc/new-features.xml
@@ -91,6 +91,10 @@ Remove matherr, and SVID and X/Open math library configurations.
 Default math library configuration is now IEEE.
 <listitem><para>
 
+</para></listitem>
+Improve uname(2) for newly built applications.
+</para></listitem>
+
 </itemizedlist>
 
 </sect2>



More information about the Cygwin-cvs mailing list