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>
This commit is contained in:
Corinna Vinschen 2019-01-24 12:01:01 +01:00
parent 6ffcc50f19
commit 84230b71c6
8 changed files with 92 additions and 7 deletions

View File

@ -440,6 +440,7 @@ GMON_OFILES:=gmon.o mcount.o profil.o mcountFunc.o
NEW_FUNCTIONS:=$(addprefix --replace=,\ NEW_FUNCTIONS:=$(addprefix --replace=,\
atexit= \ atexit= \
timezone= \ timezone= \
uname=uname_x \
__xdrrec_getrec= \ __xdrrec_getrec= \
__xdrrec_setnonblock= \ __xdrrec_setnonblock= \
xdr_array= \ xdr_array= \

View File

@ -1522,6 +1522,7 @@ ualarm SIGFE
umask NOSIGFE umask NOSIGFE
umount SIGFE umount SIGFE
uname SIGFE uname SIGFE
uname_x SIGFE
ungetc SIGFE ungetc SIGFE
ungetwc SIGFE ungetwc SIGFE
unlink SIGFE unlink SIGFE

View File

@ -505,12 +505,13 @@ details. */
332: Add signalfd. 332: Add signalfd.
333: Add timerfd_create, timerfd_gettime, timerfd_settime. 333: Add timerfd_create, timerfd_gettime, timerfd_settime.
334: Remove matherr. 334: Remove matherr.
335: Change size of utsname, change uname output.
Note that we forgot to bump the api for ualarm, strtoll, strtoull, Note that we forgot to bump the api for ualarm, strtoll, strtoull,
sigaltstack, sethostname. */ sigaltstack, sethostname. */
#define CYGWIN_VERSION_API_MAJOR 0 #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 /* There is also a compatibity version number associated with the shared memory
regions. It is incremented when incompatible changes are made to the shared regions. It is incremented when incompatible changes are made to the shared

View File

@ -13,13 +13,20 @@ details. */
extern "C" { extern "C" {
#endif #endif
#define _UTSNAME_LENGTH 65
struct utsname struct utsname
{ {
char sysname[20]; char sysname[_UTSNAME_LENGTH];
char nodename[20]; char nodename[_UTSNAME_LENGTH];
char release[20]; char release[_UTSNAME_LENGTH];
char version[20]; char version[_UTSNAME_LENGTH];
char machine[20]; char machine[_UTSNAME_LENGTH];
#if __GNU_VISIBLE
char domainname[_UTSNAME_LENGTH];
#else
char __domainname[_UTSNAME_LENGTH];
#endif
}; };
int uname (struct utsname *); int uname (struct utsname *);

View File

@ -56,6 +56,8 @@ What changed:
- Remove matherr, and SVID and X/Open math library configurations. - Remove matherr, and SVID and X/Open math library configurations.
Default math library configuration is now IEEE. Default math library configuration is now IEEE.
- Improve uname(2) for newly built applications.
Bug Fixes Bug Fixes
--------- ---------

View File

@ -10,15 +10,83 @@ details. */
#include "winsup.h" #include "winsup.h"
#include <sys/utsname.h> #include <sys/utsname.h>
#include <netdb.h>
#include "cygwin_version.h" #include "cygwin_version.h"
#include "cygtls.h" #include "cygtls.h"
extern "C" int cygwin_gethostname (char *__name, size_t __len); 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 */ /* uname: POSIX 4.4.1.1 */
/* New entrypoint for applications since API 335 */
extern "C" int extern "C" int
uname (struct utsname *name) 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 *in_name)
{
struct old_utsname *name = (struct old_utsname *) in_name;
__try __try
{ {
char *snp = strstr (cygwin_version.dll_build_date, "SNP"); char *snp = strstr (cygwin_version.dll_build_date, "SNP");

View File

@ -59,6 +59,7 @@ public:
const size_t allocation_granularity () const const size_t allocation_granularity () const
{ return (size_t) system_info.dwAllocationGranularity; } { return (size_t) system_info.dwAllocationGranularity; }
const char *osname () const { return osnam; } const char *osname () const { return osnam; }
const DWORD build_number () const { return version.dwBuildNumber; }
const bool is_wow64 () const { return !!wow64; } const bool is_wow64 () const { return !!wow64; }
#define IMPLEMENT(cap) cap() const { return ((wincaps *) this->caps)->cap; } #define IMPLEMENT(cap) cap() const { return ((wincaps *) this->caps)->cap; }

View File

@ -91,6 +91,10 @@ Remove matherr, and SVID and X/Open math library configurations.
Default math library configuration is now IEEE. Default math library configuration is now IEEE.
<listitem><para> <listitem><para>
</para></listitem>
Improve uname(2) for newly built applications.
</para></listitem>
</itemizedlist> </itemizedlist>
</sect2> </sect2>