]> err.no Git - util-linux/commitdiff
agetty: add 'O' escape code to display domain name
authorKarel Zak <kzak@redhat.com>
Thu, 28 Jun 2007 23:50:50 +0000 (01:50 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 29 Jun 2007 00:26:02 +0000 (02:26 +0200)
This patch add a new 'O' escape code to display domain name
by issue-file (/etc/issue) output.

(Based on an Gentoo patch.)

Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/agetty.8
login-utils/agetty.c

index 69be5f2bed3211019d25770f0242ff240a9a3eca..dc18691f40e86a92d62705109e7cea7de759e33a 100644 (file)
@@ -217,7 +217,10 @@ n
 Insert the nodename of the machine, also known as the hostname.
 .TP
 o
-Insert the domainname of the machine.
+Insert the NIS domainname of the machine.
+.TP
+O
+Insert the DNS domainname of the machine.
 .TP
 r
 Insert the release number of the OS, eg. 1.1.9.
index eb9fab560953a887e2cd621a42e838dd206c0eec..c827103947f86458d98b79579ae968b0248ebc2e 100644 (file)
@@ -30,6 +30,9 @@
 #include <getopt.h>
 #include <time.h>
 #include <sys/file.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
 #include "xstrncpy.h"
 #include "nls.h"
 
   */
 #ifndef BUFSIZ
 #define        BUFSIZ          1024
+#endif
+
+/* set a maximum length for the hostname,  */
+#ifdef HOST_NAME_MAX
+# define HOSTNAME_LENGTH HOST_NAME_MAX         /* defined by POSIX.1 */
+#elif defined(MAXHOSTNAMELEN)
+# define HOSTNAME_LENGTH MAXHOSTNAMELEN                /* implemented in current Unix-versions */
+#else
+# define HOSTNAME_LENGTH 255
 #endif
 
  /*
@@ -879,6 +891,31 @@ do_prompt(op, tp)
                   }
                  break;
 
+                 case 'O':
+                  {
+                       char *dom = "unknown_domain";
+                       char host[HOST_NAME_MAX + 1];
+                       struct addrinfo hints, *info = NULL;
+
+                       memset(&hints, 0, sizeof(hints));
+                       hints.ai_flags = AI_CANONNAME;
+
+                       if (gethostname(host, sizeof(host)) ||
+                           getaddrinfo(host, NULL, &hints, &info) ||
+                           info == NULL)
+                               fputs(dom, stdout);
+                       else {
+                               char *canon;
+
+                               if (info->ai_canonname &&
+                                   (canon = strchr(info->ai_canonname, '.')))
+                                       dom = canon + 1;
+                               fputs(dom, stdout);
+                               freeaddrinfo(info);
+                       }
+                  }
+                 break;
+
                  case 'd':
                  case 't':
                    {