Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37504766
en ru br
Репозитории ALT
S:9.4.0.24.75e248-alt1
5.1: 7.6-alt1
4.1: 6.11-alt1
4.0: 5.97-alt6
3.0: 5.3.1-alt0.4
www.altlinux.org/Changes

Другие репозитории
Upstream:8.1pl3

Группа :: Система/Основа
Пакет: coreutils

 Главная   Изменения   Спек   Патчи   Sources   Загрузить   Gear   Bugs and FR  Repocop 

Патч: coreutils-7.6-alt1.patch
Скачать


 .gitignore              |    1 -
 .tarball-version        |    1 +
 AUTHORS                 |    1 +
 README                  |    2 +-
 bootstrap.conf          |    2 -
 configure.ac            |    2 +
 doc/coreutils.texi      |   54 +++----
 m4/hostname.m4          |   26 +++
 man/Makefile.am         |    1 +
 man/mksock.x            |    4 +
 src/Makefile.am         |    8 +-
 src/chroot.c            |    4 +
 src/date.c              |    9 +-
 src/dircolors.hin       |   13 ++-
 src/hostname.c          |  409 ++++++++++++++++++++++++++++++++++++++++++++---
 src/ls.c                |    6 +-
 src/mksock.c            |  162 +++++++++++++++++++
 tests/misc/help-version |    1 +
 18 files changed, 633 insertions(+), 73 deletions(-)
diff --git a/.gitignore b/.gitignore
index 1116620..66a1aac 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,7 +5,6 @@
 *~
 .gdb-history
 .kludge-stamp
-.tarball-version
 .version
 ABOUT-NLS
 ChangeLog
diff --git a/.tarball-version b/.tarball-version
new file mode 100644
index 0000000..f5cce03
--- /dev/null
+++ b/.tarball-version
@@ -0,0 +1 @@
+7.6
\ No newline at end of file
diff --git a/AUTHORS b/AUTHORS
index 7095db0..242c820 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -46,6 +46,7 @@ md5sum: Ulrich Drepper, Scott Miller, David Madore
 mkdir: David MacKenzie
 mkfifo: David MacKenzie
 mknod: David MacKenzie
+mksock: Dmitry V. Levin
 mktemp: Jim Meyering
 mv: Mike Parker, David MacKenzie, Jim Meyering
 nice: David MacKenzie
diff --git a/README b/README
index 7545eab..f46a651 100644
--- a/README
+++ b/README
@@ -10,7 +10,7 @@ The programs that can be built with this package are:
   [ arch base64 basename cat chcon chgrp chmod chown chroot cksum comm cp
   csplit cut date dd df dir dircolors dirname du echo env expand expr
   factor false fmt fold groups head hostid hostname id install join kill
-  link ln logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl nohup
+  link ln logname ls md5sum mkdir mkfifo mknod mksock mktemp mv nice nl nohup
   od paste pathchk pinky pr printenv printf ptx pwd readlink rm rmdir
   runcon seq sha1sum sha224sum sha256sum sha384sum sha512sum shred shuf
   sleep sort split stat stdbuf stty su sum sync tac tail tee test timeout
diff --git a/bootstrap.conf b/bootstrap.conf
index c2bf753..2913625 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -307,12 +307,10 @@ automake   1.11
 autopoint  -
 bison      -
 gettext    -
-git        1.4.4
 gperf      -
 gzip       -
 makeinfo   -
 perl       5.5
-rsync      -
 tar        -
 "
 
diff --git a/configure.ac b/configure.ac
index e718b36..e9f23bb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -317,6 +317,8 @@ AC_CHECK_DECLS([strsignal, sys_siglist, _sys_siglist, __sys_siglist], , ,
   [AC_INCLUDES_DEFAULT
 #include <signal.h>])
 
+gt_PREREQ_HOSTNAME
+
 cu_LIB_CHECK
 cu_GMP
 
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 22d307a..37d750b 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -10979,15 +10979,17 @@ In most modern shells, @command{false} is a built-in command, so when
 you use @samp{false} in a script, you're probably using the built-in
 command, not the one documented here.
 
-@command{false} honors the @option{--help} and @option{--version} options.
+@command{false} ignores all options.
 
-This version of @command{false} is implemented as a C program, and is thus
-more secure and faster than a shell script implementation, and may safely
-be used as a dummy shell for the purpose of disabling accounts.
+@strong{Please note} that this system uses a non-GNU version of
+@command{false}, not the version supplied with GNU coreutils.
+The GNU version of @command{false} is a C program that actually honors
+some options.
 
-Note that @command{false} (unlike all other programs documented herein)
-exits unsuccessfully, even when invoked with
-@option{--help} or @option{--version}.
+This version of @command{false} is implemented as a tiny C program that
+does not use the dynamic linker or any libraries.  It is thus more secure
+and faster than a shell script implementation, and may safely
+be used as a dummy shell for the purpose of disabling accounts.
 
 Portable programs should not assume that the exit status of
 @command{false} is 1, as it is greater than 1 on some
@@ -11011,23 +11013,17 @@ In most modern shells, @command{true} is a built-in command, so when
 you use @samp{true} in a script, you're probably using the built-in
 command, not the one documented here.
 
-@command{true} honors the @option{--help} and @option{--version} options.
-
-Note, however, that it is possible to cause @command{true}
-to exit with nonzero status: with the @option{--help} or @option{--version}
-option, and with standard
-output already closed or redirected to a file that evokes an I/O error.
-For example, using a Bourne-compatible shell:
+@command{true} ignores all options.
 
-@example
-$ ./true --version >&-
-./true: write error: Bad file number
-$ ./true --version > /dev/full
-./true: write error: No space left on device
-@end example
+@strong{Please note} that this system uses a non-GNU version of
+@command{true}, not the version supplied with GNU coreutils.
+The GNU version of @command{true} is a C program that actually honors
+some options (and may even be caused to exit with nonzero status on
+some subtle error conditions).
 
-This version of @command{true} is implemented as a C program, and is thus
-more secure and faster than a shell script implementation, and may safely
+This version of @command{true} is implemented as a tiny C program that
+does not use the dynamic linker or any libraries.  It is thus more secure
+and faster than a shell script implementation, and may safely
 be used as a dummy shell for the purpose of disabling accounts.
 
 @node test invocation
@@ -12902,8 +12898,8 @@ database to be consulted afresh, and so will give a different result.
 
 @flindex utmp
 @command{logname} prints the calling user's name, as found in a
-system-maintained file (often @file{/var/run/utmp} or
-@file{/etc/utmp}), and exits with a status of 0.  If there is no entry
+system-maintained file (often @file{/var/run/utmp}),
+and exits with a status of 0.  If there is no entry
 for the calling process, @command{logname} prints
 an error message and exits with a status of 1.
 
@@ -12978,9 +12974,9 @@ users [@var{file}]
 @flindex utmp
 @flindex wtmp
 With no @var{file} argument, @command{users} extracts its information from
-a system-maintained file (often @file{/var/run/utmp} or
-@file{/etc/utmp}).  If a file argument is given, @command{users} uses
-that file instead.  A common choice is @file{/var/log/wtmp}.
+a system-maintained file (often @file{/var/run/utmp}).
+If a file argument is given, @command{users} uses
+that file instead.  A common choice is @file{/var/run/utmp}.
 
 The only options are @option{--help} and @option{--version}.  @xref{Common
 options}.
@@ -13012,8 +13008,8 @@ line, login time, and remote hostname or X display.
 @flindex utmp
 @flindex wtmp
 If given one non-option argument, @command{who} uses that instead of
-a default system-maintained file (often @file{/var/run/utmp} or
-@file{/etc/utmp}) as the name of the file containing the record of
+a default system-maintained file (often @file{/var/run/utmp})
+as the name of the file containing the record of
 users logged on.  @file{/var/log/wtmp} is commonly given as an argument
 to @command{who} to look at who has previously logged on.
 
diff --git a/m4/hostname.m4 b/m4/hostname.m4
new file mode 100644
index 0000000..a1ef1f9
--- /dev/null
+++ b/m4/hostname.m4
@@ -0,0 +1,26 @@
+# hostname.m4 serial 1 (gettext-0.11)
+dnl Copyright (C) 2001-2002 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# Prerequisites of the hostname.c program.
+AC_DEFUN([gt_PREREQ_HOSTNAME],
+[
+  AC_CHECK_HEADERS(arpa/inet.h)
+  AC_CHECK_FUNCS(gethostname gethostbyname getdomainname setdomainname inet_ntop)
+
+  AC_MSG_CHECKING([for IPv6 sockets])
+  AC_CACHE_VAL(gt_cv_socket_ipv6,[
+    AC_TRY_COMPILE([
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>],
+[int x = AF_INET6; struct in6_addr y; struct sockaddr_in6 z;],
+      gt_cv_socket_ipv6=yes, gt_cv_socket_ipv6=no)
+  ])
+  AC_MSG_RESULT($gt_cv_socket_ipv6)
+  if test $gt_cv_socket_ipv6 = yes; then
+    AC_DEFINE(HAVE_IPV6, 1, [Define if <sys/socket.h> defines AF_INET6.])
+  fi
+])
diff --git a/man/Makefile.am b/man/Makefile.am
index b56db94..8e07de7 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -75,6 +75,7 @@ md5sum.1:	$(common_dep)	$(srcdir)/md5sum.x	../src/md5sum.c
 mkdir.1:	$(common_dep)	$(srcdir)/mkdir.x	../src/mkdir.c
 mkfifo.1:	$(common_dep)	$(srcdir)/mkfifo.x	../src/mkfifo.c
 mknod.1:	$(common_dep)	$(srcdir)/mknod.x	../src/mknod.c
+mksock.1:	$(common_dep)	$(srcdir)/mksock.x	../src/mksock.c
 mktemp.1:	$(common_dep)	$(srcdir)/mktemp.x	../src/mktemp.c
 mv.1:		$(common_dep)	$(srcdir)/mv.x		../src/mv.c
 nice.1:		$(common_dep)	$(srcdir)/nice.x	../src/nice.c
diff --git a/man/mksock.x b/man/mksock.x
new file mode 100644
index 0000000..1857073
--- /dev/null
+++ b/man/mksock.x
@@ -0,0 +1,4 @@
+[NAME]
+mksock \- Create unix domain sockets
+[DESCRIPTION]
+.\" Add any additional description here
diff --git a/src/Makefile.am b/src/Makefile.am
index 90e11c6..1ea2b28 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,7 +33,7 @@ EXTRA_PROGRAMS = \
   $(build_if_possible__progs) \
   [ chcon chgrp chown chmod cp dd dircolors du \
   ginstall link ln dir vdir ls mkdir \
-  mkfifo mknod mktemp \
+  mkfifo mknod mksock mktemp \
   mv nohup readlink rm rmdir shred stat sync touch unlink \
   cat cksum comm csplit cut expand fmt fold head join groups md5sum \
   nl od paste pr ptx sha1sum sha224sum sha256sum sha384sum sha512sum \
@@ -114,15 +114,15 @@ __LDADD = $(LDADD) $(LIB_EACCESS)
 
 # for clock_gettime and fdatasync
 dd_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
-dir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
+dir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP) -ltinfo
 id_LDADD = $(LDADD) $(LIB_SELINUX)
-ls_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
+ls_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP) -ltinfo
 mktemp_LDADD = $(LDADD) $(LIB_GETHRXTIME)
 pr_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
 shred_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
 shuf_LDADD = $(LDADD) $(LIB_GETHRXTIME)
 tac_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
-vdir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
+vdir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP) -ltinfo
 
 ## If necessary, add -lm to resolve use of pow in lib/strtod.c.
 sort_LDADD = $(LDADD) $(POW_LIB) $(LIB_GETHRXTIME)
diff --git a/src/chroot.c b/src/chroot.c
index 3fa26f8..eee11e0 100644
--- a/src/chroot.c
+++ b/src/chroot.c
@@ -256,6 +256,10 @@ main (int argc, char **argv)
   if (fail)
     exit (EXIT_FAILURE);
 
+  /* These variables are useless inside chroot.  ALT#16024 */
+  unsetenv("TMP");
+  unsetenv("TMPDIR");
+
   /* Execute the given command.  */
   execvp (argv[0], argv);
 
diff --git a/src/date.c b/src/date.c
index cbc53e6..fe0d448 100644
--- a/src/date.c
+++ b/src/date.c
@@ -449,14 +449,7 @@ main (int argc, char **argv)
       format = DATE_FMT_LANGINFO ();
       if (! *format)
         {
-          /* Do not wrap the following literal format string with _(...).
-             For example, suppose LC_ALL is unset, LC_TIME="POSIX",
-             and LANG="ko_KR".  In that case, POSIX says that LC_TIME
-             determines the format and contents of date and time strings
-             written by date, which means "date" must generate output
-             using the POSIX locale; but adding _() would cause "date"
-             to use a Korean translation of the format.  */
-          format = "%a %b %e %H:%M:%S %Z %Y";
+          format = dcgettext(NULL, N_("%a %b %e %H:%M:%S %Z %Y"), LC_TIME);
         }
     }
 
diff --git a/src/dircolors.hin b/src/dircolors.hin
index 91ddcb6..6fd8894 100644
--- a/src/dircolors.hin
+++ b/src/dircolors.hin
@@ -7,7 +7,12 @@
 # are permitted provided the copyright notice and this notice are preserved.
 
 # The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the
-# slackware version of dircolors) are recognized but ignored.
+# slackware version of dircolors) are recognized but ignored by GNU dircolors.
+
+# This file goes in the /etc directory, and must be world readable.
+# You can copy this file to .dircolors in your $HOME directory to override
+# the system defaults.  This is also may be handled directly by the
+# /etc/profile.d/color_ls.sh and /etc/profile.d/color_ls.csh scripts.
 
 # Below, there should be one TERM entry for each termtype that is colorizable
 TERM Eterm
@@ -99,14 +104,16 @@ EXEC 01;32
 #.bat 01;32
 # Or if you want to colorize scripts even if they do not have the
 # executable bit actually set.
-#.sh  01;32
-#.csh 01;32
+.sh  01;32
+.csh 01;32
 
  # archives or compressed (bright red)
 .tar 01;31
 .tgz 01;31
+.arc 01;31
 .arj 01;31
 .taz 01;31
+.lha 01;31
 .lzh 01;31
 .lzma 01;31
 .tlz 01;31
diff --git a/src/hostname.c b/src/hostname.c
index 110014b..6ff3b85 100644
--- a/src/hostname.c
+++ b/src/hostname.c
@@ -24,7 +24,9 @@
 #include "system.h"
 #include "long-options.h"
 #include "error.h"
+#include "errno.h"
 #include "quote.h"
+#include "xalloc.h"
 #include "xgethostname.h"
 
 /* The official name of this program (e.g., no `g' prefix).  */
@@ -32,6 +34,148 @@
 
 #define AUTHORS proper_name ("Jim Meyering")
 
+/* Support for using gethostbyname().  */
+#if HAVE_GETHOSTBYNAME
+# include <sys/types.h>
+# include <sys/socket.h>	/* defines AF_INET, AF_INET6 */
+# include <netinet/in.h>	/* declares ntohs(), defines struct sockaddr_in */
+# if HAVE_ARPA_INET_H
+#  include <arpa/inet.h>	/* declares inet_ntoa(), inet_ntop() */
+# endif
+# if HAVE_IPV6
+#  if !defined(__CYGWIN__)	/* Cygwin has only s6_addr, no s6_addr16 */
+#   if defined(__APPLE__) && defined(__MACH__)	/* MacOS X */
+#    define in6_u __u6_addr
+#    define u6_addr16 __u6_addr16
+#   endif
+    /* Use s6_addr16 for portability.  See RFC 2553.  */
+#   ifndef s6_addr16
+#    define s6_addr16 in6_u.u6_addr16
+#   endif
+#   define HAVE_IN6_S6_ADDR16 1
+#  endif
+# endif
+# include <netdb.h>		/* defines struct hostent, declares gethostbyname() */
+#endif
+
+/* Converts an AF_INET address to a printable, presentable format.
+   BUFFER is an array with at least 15+1 bytes.  ADDR is 'struct in_addr'.  */
+#if HAVE_INET_NTOP
+# define ipv4_ntop(buffer,addr) \
+    inet_ntop (AF_INET, &addr, buffer, 15+1)
+#else
+# define ipv4_ntop(buffer,addr) \
+    strcpy (buffer, inet_ntoa (addr))
+#endif
+
+#if HAVE_IPV6
+/* Converts an AF_INET6 address to a printable, presentable format.
+   BUFFER is an array with at least 45+1 bytes.  ADDR is 'struct in6_addr'.  */
+# if HAVE_INET_NTOP
+#  define ipv6_ntop(buffer,addr) \
+     inet_ntop (AF_INET6, &addr, buffer, 45+1)
+# elif HAVE_IN6_S6_ADDR16
+#  define ipv6_ntop(buffer,addr) \
+     sprintf (buffer, "%x:%x:%x:%x:%x:%x:%x:%x", \
+	      ntohs ((addr).s6_addr16[0]), \
+	      ntohs ((addr).s6_addr16[1]), \
+	      ntohs ((addr).s6_addr16[2]), \
+	      ntohs ((addr).s6_addr16[3]), \
+	      ntohs ((addr).s6_addr16[4]), \
+	      ntohs ((addr).s6_addr16[5]), \
+	      ntohs ((addr).s6_addr16[6]), \
+	      ntohs ((addr).s6_addr16[7]))
+# else
+#  define ipv6_ntop(buffer,addr) \
+     sprintf (buffer, "%x:%x:%x:%x:%x:%x:%x:%x", \
+	      ((addr).s6_addr[0] << 8) | (addr).s6_addr[1], \
+	      ((addr).s6_addr[2] << 8) | (addr).s6_addr[3], \
+	      ((addr).s6_addr[4] << 8) | (addr).s6_addr[5], \
+	      ((addr).s6_addr[6] << 8) | (addr).s6_addr[7], \
+	      ((addr).s6_addr[8] << 8) | (addr).s6_addr[9], \
+	      ((addr).s6_addr[10] << 8) | (addr).s6_addr[11], \
+	      ((addr).s6_addr[12] << 8) | (addr).s6_addr[13], \
+	      ((addr).s6_addr[14] << 8) | (addr).s6_addr[15])
+# endif
+#endif
+
+/* Output format types.  */
+typedef enum
+{ default_format, short_format, domain_format, long_format, ip_format }
+output_format_t;
+
+/* Query name types.  */
+typedef enum
+{ host_query, dns_query, nis_query }
+query_name_t;
+
+/* Long options.  */
+static const struct option long_options[] = {
+  {"fqdn", no_argument, NULL, 'f'},
+  {"long", no_argument, NULL, 'f'},
+  {"ip-address", no_argument, NULL, 'i'},
+  {"short", no_argument, NULL, 's'},
+
+  {"dns", no_argument, NULL, 'd'},
+  {"domain", no_argument, NULL, 'd'},
+
+  {"nis", no_argument, NULL, 'y'},
+  {"yp", no_argument, NULL, 'y'},
+
+  {GETOPT_HELP_OPTION_DECL},
+  {GETOPT_VERSION_OPTION_DECL},
+  {NULL, 0, NULL, 0}
+};
+
+#ifndef INITIAL_DOMAINNAME_LENGTH
+# define INITIAL_DOMAINNAME_LENGTH 34
+#endif
+
+/* Return the current domainname in malloc'd storage.
+   If malloc fails, exit.
+   Upon any other failure, return NULL and set errno.  */
+char *
+xgetdomainname (void)
+{
+  char *domainname = NULL;
+  size_t size = INITIAL_DOMAINNAME_LENGTH;
+
+  while (1)
+    {
+      /* Use SIZE_1 here rather than SIZE to work around the bug in
+         SunOS 5.5's getdomainname whereby it NUL-terminates DOMAINNAME
+         even when the name is as long as the supplied buffer.  */
+      size_t size_1;
+
+      domainname = x2realloc (domainname, &size);
+      size_1 = size - 1;
+      domainname[size_1 - 1] = '\0';
+      errno = 0;
+
+#ifdef HAVE_GETDOMAINNAME
+      if (getdomainname (domainname, size_1) == 0)
+	{
+	  if (!domainname[size_1 - 1])
+	    break;
+	}
+      else
+#else
+      errno = ENOSYS;
+#endif
+      if (errno != 0 && errno != ENAMETOOLONG && errno != EINVAL
+	  /* OSX/Darwin does this when the buffer is not large enough */
+	  && errno != ENOMEM)
+	{
+	  int saved_errno = errno;
+	  free (domainname);
+	  errno = saved_errno;
+	  return NULL;
+	}
+    }
+
+  return domainname;
+}
+
 #if !defined HAVE_SETHOSTNAME && defined HAVE_SYSINFO && \
      defined HAVE_SYS_SYSTEMINFO_H
 # include <sys/systeminfo.h>
@@ -43,7 +187,7 @@ sethostname (char *name, size_t namelen)
   return (sysinfo (SI_SET_HOSTNAME, name, namelen) < 0 ? -1 : 0);
 }
 
-# define HAVE_SETHOSTNAME 1  /* Now we have it... */
+# define HAVE_SETHOSTNAME 1	/* Now we have it... */
 #endif
 
 void
@@ -57,10 +201,19 @@ usage (int status)
       printf (_("\
 Usage: %s [NAME]\n\
   or:  %s OPTION\n\
-Print or set the hostname of the current system.\n\
+Print or set the hostname or domainname of the current system.\n\
+\n\
+Output format:\n\
+  -s, --short                 short host name\n\
+  -f, --fqdn, --long          long host name, includes fully qualified\n\
+                                domain name, and aliases\n\
+  -i, --ip-address            addresses for the hostname\n\
+  -d, --dns, --domain         DNS domain name\n\
+  -y, --yp, --nis             NIS/YP domain name\n\
+\n\
+Informative output:\n\
 \n\
-"),
-             program_name, program_name);
+"), program_name, program_name);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
       emit_bug_reporting_address ();
@@ -68,10 +221,15 @@ Print or set the hostname of the current system.\n\
   exit (status);
 }
 
+static void print_name (query_name_t, output_format_t);
+static void set_name (query_name_t, const char *);
+
 int
 main (int argc, char **argv)
 {
-  char *hostname;
+  int optc;
+  output_format_t format = default_format;
+  query_name_t query = host_query;
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
@@ -81,37 +239,240 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
+  if (STREQ (program_name, "dnsdomainname"))
+    query = dns_query;
+
+  if (STREQ (program_name, "domainname")
+      || STREQ (program_name, "nisdomainname")
+      || STREQ (program_name, "ypdomainname"))
+    query = nis_query;
+
   parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
                       usage, AUTHORS, (char const *) NULL);
-  if (getopt_long (argc, argv, "", NULL, NULL) != -1)
-    usage (EXIT_FAILURE);
+
+  /* Parse command line options.  */
+  while ((optc =
+          getopt_long (argc, argv, "dfisyhV", long_options, NULL)) != EOF)
+    switch (optc)
+      {
+      case 'f':
+	if (query != host_query || format != default_format)
+	  {
+	    error (0, 0, _("incompatible options"));
+	    usage (EXIT_FAILURE);
+	  }
+	format = long_format;
+	break;
+      case 's':
+	if (query != host_query || format != default_format)
+	  {
+	    error (0, 0, _("incompatible options"));
+	    usage (EXIT_FAILURE);
+	  }
+	format = short_format;
+	break;
+      case 'i':
+	if (query != host_query || format != default_format)
+	  {
+	    error (0, 0, _("incompatible options"));
+	    usage (EXIT_FAILURE);
+	  }
+	format = ip_format;
+	break;
+
+      case 'd':
+	if (query == nis_query || format != default_format)
+	  {
+	    error (0, 0, _("incompatible options"));
+	    usage (EXIT_FAILURE);
+	  }
+	query = dns_query;
+	break;
+
+      case 'y':
+	if (query == dns_query || format != default_format)
+	  {
+	    error (0, 0, _("incompatible options"));
+	    usage (EXIT_FAILURE);
+	  }
+	query = nis_query;
+	break;
+
+      case 'h':
+	case_GETOPT_HELP_CHAR;
+      case 'V':
+	case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
+      default:
+	usage (EXIT_FAILURE);
+	/* NOTREACHED */
+      }
 
   if (argc == optind + 1)
+    set_name (query, argv[optind]);
+
+  else if (argc <= optind)
+    print_name (query, format);
+
+  else
     {
-#ifdef HAVE_SETHOSTNAME
-      /* Set hostname to operand.  */
-      char const *name = argv[optind];
-      if (sethostname (name, strlen (name)) != 0)
-        error (EXIT_FAILURE, errno, _("cannot set name to %s"), quote (name));
-#else
-      error (EXIT_FAILURE, 0,
-             _("cannot set hostname; this system lacks the functionality"));
-#endif
+      error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
+      usage (EXIT_FAILURE);
     }
 
-  if (argc <= optind)
+  exit (EXIT_SUCCESS);
+}
+
+static void
+print_hostname (output_format_t format)
+{
+  char *hostname;
+  char *dot;
+#if HAVE_GETHOSTBYNAME
+  struct hostent *h;
+  size_t i;
+#endif
+
+  hostname = xgethostname ();
+  if (hostname == NULL)
+    error (EXIT_FAILURE, errno, _("cannot determine hostname"));
+
+  switch (format)
     {
-      hostname = xgethostname ();
-      if (hostname == NULL)
-        error (EXIT_FAILURE, errno, _("cannot determine hostname"));
+    case default_format:
+      /* Print the hostname, as returned by the system call.  */
       printf ("%s\n", hostname);
+      break;
+
+    case short_format:
+      /* Print only the part before the first dot.  */
+      dot = strchr (hostname, '.');
+      if (dot != NULL)
+	*dot = '\0';
+      printf ("%s\n", hostname);
+      break;
+
+    case domain_format:
+      /* Print only the part after the first dot.  */
+      dot = strchr (hostname, '.');
+      if (dot != NULL)
+	hostname = dot + 1;
+      printf ("%s\n", hostname);
+      break;
+
+    case long_format:
+      /* Look for netwide usable hostname using gethostbyname().  */
+#if HAVE_GETHOSTBYNAME
+      h = gethostbyname (hostname);
+      if (h != NULL)
+	printf ("%s\n", h->h_name);
+      else
+#endif
+	printf ("%s\n", hostname);
+      break;
+
+    case ip_format:
+      /* Look for netwide usable IP addresses using gethostbyname().  */
+#if HAVE_GETHOSTBYNAME
+      h = gethostbyname (hostname);
+      if (h != NULL && h->h_addr_list != NULL)
+	{
+	  bool found = false;
+	  for (i = 0; h->h_addr_list[i] != NULL; ++i)
+	    {
+#if HAVE_IPV6
+	      if (h->h_addrtype == AF_INET6)
+		{
+		  char buffer[45 + 1];
+		  ipv6_ntop (buffer,
+			     *(const struct in6_addr *) h->h_addr_list[i]);
+		  printf ("%s%s", (found ? " " : ""), buffer);
+		  found = true;
+		}
+	      else
+#endif
+	      if (h->h_addrtype == AF_INET)
+		{
+		  char buffer[15 + 1];
+		  ipv4_ntop (buffer,
+			     *(const struct in_addr *) h->h_addr_list[i]);
+		  printf ("%s%s", (found ? " " : ""), buffer);
+		  found = true;
+		}
+	    }
+	  if (found)
+	    putchar ('\n');
+	}
+#endif
+      break;
+    }
+}
+
+static void
+print_nisname (void)
+{
+  char *domainname;
+
+  domainname = xgetdomainname ();
+  if (domainname == NULL)
+    error (EXIT_FAILURE, errno, _("cannot determine domainname"));
+
+  printf ("%s\n", domainname);
+}
+
+static void
+print_name (query_name_t query, output_format_t format)
+{
+  switch (query)
+    {
+    case host_query:
+      print_hostname (format);
+      return;
+    case dns_query:
+      print_hostname (domain_format);
+      return;
+    case nis_query:
+      print_nisname ();
+      return;
     }
+}
 
-  if (optind + 1 < argc)
+static const char *
+name_of_query (query_name_t query)
+{
+  switch (query)
     {
-      error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
-      usage (EXIT_FAILURE);
+    case host_query:
+      return "host";
+    case dns_query:
+      return "DNS domain";
+    case nis_query:
+      return "NIS domain";
+    default:
+      return "";
     }
+}
 
-  exit (EXIT_SUCCESS);
+static void
+set_name (query_name_t query, const char *name)
+{
+  switch (query)
+    {
+#ifdef HAVE_SETHOSTNAME
+    case host_query:
+      if (sethostname (name, strlen (name)) != 0)
+	error (EXIT_FAILURE, errno, _("cannot set %s name to %s"),
+	       name_of_query (query), quote (name));
+      break;
+#endif
+#ifdef HAVE_SETDOMAINNAME
+    case nis_query:
+      if (setdomainname (name, strlen (name)) != 0)
+	error (EXIT_FAILURE, errno, _("cannot set %s name to %s"),
+	       name_of_query (query), quote (name));
+      break;
+#endif
+    default:
+      error (EXIT_FAILURE, ENOSYS,
+	     _("cannot set %s name"), name_of_query (query));
+    }
 }
diff --git a/src/ls.c b/src/ls.c
index b62ea12..b7f0ace 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -87,6 +87,7 @@
 
 #include "system.h"
 #include <fnmatch.h>
+#include <termcap.h>
 
 #include "acl.h"
 #include "argmatch.h"
@@ -1874,7 +1875,10 @@ decode_switches (int argc, char **argv)
 
             print_with_color = (i == color_always
                                 || (i == color_if_tty
-                                    && isatty (STDOUT_FILENO)));
+                                    && isatty (STDOUT_FILENO)
+                                    && getenv("TERM")
+                                    && tgetent(NULL, getenv("TERM")) > 0
+                                    && tgetstr("md", NULL) > 0));
 
             if (print_with_color)
               {
diff --git a/src/mksock.c b/src/mksock.c
new file mode 100644
index 0000000..aab468c
--- /dev/null
+++ b/src/mksock.c
@@ -0,0 +1,162 @@
+/* mksock -- create unix domain sockets.
+   Copyright (C) 90, 91, 1995-2007 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Dmitry V. Levin <ldv@altlinux.org>
+   based on mknod.c by David MacKenzie <djm@ai.mit.edu> et al.  */
+
+#include <config.h>
+#include <stdio.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include "system.h"
+#include "error.h"
+#include "modechange.h"
+#include "quote.h"
+
+/* The official name of this program (e.g., no `g' prefix).  */
+#define PROGRAM_NAME "mksock"
+
+#define AUTHORS "Dmitry V. Levin"
+
+static struct option const longopts[] =
+{
+  {"mode", required_argument, NULL, 'm'},
+  {GETOPT_HELP_OPTION_DECL},
+  {GETOPT_VERSION_OPTION_DECL},
+  {NULL, 0, NULL, 0}
+};
+
+void
+usage (int status)
+{
+  if (status != EXIT_SUCCESS)
+    fprintf (stderr, _("Try `%s --help' for more information.\n"),
+	     program_name);
+  else
+    {
+      printf (_("Usage: %s [OPTION] NAME...\n"), program_name);
+      fputs (_("\
+Create unix domain sockets with the given NAMEs.\n\
+\n\
+  -m, --mode=MODE   set permission mode (as in chmod), not a=rw - umask\n\
+"), stdout);
+      fputs (HELP_OPTION_DESCRIPTION, stdout);
+      fputs (VERSION_OPTION_DESCRIPTION, stdout);
+      emit_bug_reporting_address ();
+    }
+  exit (status);
+}
+
+int
+main (int argc, char **argv)
+{
+  mode_t newmode;
+  const char *specified_mode = 0;
+  int errors = EXIT_SUCCESS;
+  int optc;
+
+  initialize_main (&argc, &argv);
+  set_program_name (argv[0]);
+  setlocale (LC_ALL, "");
+  bindtextdomain (PACKAGE, LOCALEDIR);
+  textdomain (PACKAGE);
+
+  atexit (close_stdout);
+
+  while ((optc = getopt_long (argc, argv, "m:", longopts, NULL)) != -1)
+    {
+      switch (optc)
+	{
+	case 0:
+	  break;
+	case 'm':
+	  specified_mode = optarg;
+	  break;
+	case_GETOPT_HELP_CHAR;
+	case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
+	default:
+	  usage (EXIT_FAILURE);
+	}
+    }
+
+  if (optind == argc)
+    {
+      error (EXIT_SUCCESS, 0, _("too few arguments"));
+      usage (EXIT_FAILURE);
+    }
+
+  newmode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+  if (specified_mode)
+    {
+      struct mode_change *change = mode_compile (specified_mode);
+      if (!change)
+	error (EXIT_FAILURE, 0, _("invalid mode"));
+      newmode = mode_adjust (newmode, false, umask (0), change, NULL);
+      free (change);
+      if (newmode & ~S_IRWXUGO)
+	error (EXIT_FAILURE, 0,
+	       _("mode must specify only file permission bits"));
+    }
+
+  for (; optind < argc; ++optind)
+    {
+      struct sockaddr_un sun;
+      int fd;
+
+      if (strlen (argv[optind]) >= sizeof (sun))
+	{
+	  error (EXIT_SUCCESS, EINVAL, _("cannot bind socket `%s'"),
+		 quote (argv[optind]));
+	  errors = EXIT_FAILURE;
+	  continue;
+	}
+
+      memset (&sun, 0, sizeof (sun));
+      sun.sun_family = AF_UNIX;
+      strcpy (sun.sun_path, argv[optind]);
+
+      fd = socket (PF_UNIX, SOCK_STREAM, 0);
+      if (fd < 0)
+	{
+	  error (EXIT_SUCCESS, errno, _("cannot create socket `%s'"),
+		 quote (argv[optind]));
+	  errors = EXIT_FAILURE;
+	  continue;
+	}
+
+      if (specified_mode && fchmod (fd, newmode))
+	{
+	  error (EXIT_SUCCESS, errno, _("cannot set permissions of socket `%s'"),
+		 quote (argv[optind]));
+	  close (fd);
+	  errors = EXIT_FAILURE;
+	  continue;
+	}
+
+      if (bind (fd, (struct sockaddr *) &sun, sizeof (sun)))
+	{
+	  error (EXIT_SUCCESS, errno, _("cannot bind socket `%s'"),
+		 quote (argv[optind]));
+	  errors = EXIT_FAILURE;
+	}
+      close (fd);
+    }
+
+  return errors;
+}
diff --git a/tests/misc/help-version b/tests/misc/help-version
index 9afe8af..3494938 100755
--- a/tests/misc/help-version
+++ b/tests/misc/help-version
@@ -107,6 +107,7 @@ chgrp_args=--version
 chown_args=--version
 mkfifo_args=--version
 mknod_args=--version
+mksock_args=--version
 # Punt on uptime, since it fails (e.g., failing to get boot time)
 # on some systems, and we shouldn't let that stop `make check'.
 uptime_args=--version
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin