diff options
author | Karel Zak | 2007-06-29 01:50:50 +0200 |
---|---|---|
committer | Karel Zak | 2007-06-29 02:26:02 +0200 |
commit | e61e66bd95e20d1a9a101c5a2efb4c638ca732f1 (patch) | |
tree | 44a3d13d3ddc8bd7fc299862d684c16bfbbe2fd8 /login-utils/agetty.c | |
parent | mount: needs to handle special mountprog even on guessed file systems. (diff) | |
download | kernel-qcow2-util-linux-e61e66bd95e20d1a9a101c5a2efb4c638ca732f1.tar.gz kernel-qcow2-util-linux-e61e66bd95e20d1a9a101c5a2efb4c638ca732f1.tar.xz kernel-qcow2-util-linux-e61e66bd95e20d1a9a101c5a2efb4c638ca732f1.zip |
agetty: add 'O' escape code to display domain name
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>
Diffstat (limited to 'login-utils/agetty.c')
-rw-r--r-- | login-utils/agetty.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/login-utils/agetty.c b/login-utils/agetty.c index eb9fab560..c82710394 100644 --- a/login-utils/agetty.c +++ b/login-utils/agetty.c @@ -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" @@ -122,6 +125,15 @@ #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 + /* * When multiple baud rates are specified on the command line, the first one * we will try is the first one specified. @@ -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': { |