]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
agetty: add --show-issue to review issue output
authorKarel Zak <kzak@redhat.com>
Tue, 12 Nov 2019 10:15:38 +0000 (11:15 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 12 Nov 2019 10:24:40 +0000 (11:24 +0100)
Let's make life easier for admins and allow to review issue file
output on the current terminal without all full agetty execution. Use
case is pretty simple:

 # $EDITOR /etc/issue
 # agetty --show-issue

Addresses: https://github.com/karelzak/util-linux/issues/828
Signed-off-by: Karel Zak <kzak@redhat.com>
term-utils/agetty.8
term-utils/agetty.c

index eb6cb334106abb717042f39bb629786fe97483f4..c6af995dc1202e9392acb97e042726dec79319fb 100644 (file)
@@ -124,6 +124,12 @@ extension in version-sort order from the directory.  This allows custom
 messages to be displayed on different terminals.  The
 \-\-noissue option will override this option.
 .TP
+\-\-show\-issue
+Display the current issue file (or other) on the current terminal and exit.
+Use this option to review the current setting, it is not designed for any other
+purpose.  Note that output may use some default or incomplete information as 
+proper output depends on terminal and agetty command line.
+.TP
 \-h, \-\-flow\-control
 Enable hardware (RTS/CTS) flow control.  It is left up to the
 application to disable software (XON/XOFF) flow protocol where
@@ -349,7 +355,7 @@ The default issue file is \fI/etc/issue\fP. If the file exists then agetty also
 checks for \fI/etc/issue.d\fP directory. The directory is optional extension to
 the default issue file and content of the directory is printed after
 \fI/etc/issue\fP content. If the \fI/etc/issue\fP does not exist than the
-directory is ignored. All files with .issue extension from the directory are
+directory is ignored. All files \fBwith .issue extension\fP from the directory are
 printed in version-sort order. The directory allow to maintain 3rd-party
 messages independently on the primary system \fI/etc/issue\fP file.
 
@@ -366,6 +372,9 @@ directory locations are ignored.
 
 The issue file feature is possible to completely disable by \fB\-\-noissue\fP option.
 
+It is possible to review the current issue file by \fBagetty \-\-show\-issue\fP
+on the current terminal.
+
 The issue files may contain certain escape codes to display the system name, date, time
 etcetera.  All escape codes consist of a backslash (\\) immediately
 followed by one of the characters listed below.
index f1e5b32929feceddc48b87222e933b1c7c5a5040..a0d0876c3bf4ad320e4a06c115f917ed8b0cbef3 100644 (file)
@@ -342,6 +342,8 @@ static void login_options_to_argv(char *argv[], int *argc, char *str, char *user
 static void reload_agettys(void);
 static void print_issue_file(struct issue *ie, struct options *op, struct termios *tp);
 static void eval_issue_file(struct issue *ie, struct options *op, struct termios *tp);
+static void show_issue(struct options *op);
+
 
 /* Fake hostname for ut_host specified on command line. */
 static char *fakehost;
@@ -709,6 +711,7 @@ static void parse_args(int argc, char **argv, struct options *op)
                KILL_CHARS_OPTION,
                RELOAD_OPTION,
                LIST_SPEEDS_OPTION,
+               ISSUE_SHOW_OPTION,
        };
        const struct option longopts[] = {
                {  "8bits",          no_argument,        NULL,  '8'  },
@@ -718,6 +721,7 @@ static void parse_args(int argc, char **argv, struct options *op)
                {  "delay",          required_argument,  NULL,  'd'  },
                {  "remote",         no_argument,        NULL,  'E'  },
                {  "issue-file",     required_argument,  NULL,  'f'  },
+               {  "show-issue",     no_argument,        NULL,  ISSUE_SHOW_OPTION },
                {  "flow-control",   no_argument,        NULL,  'h'  },
                {  "host",           required_argument,  NULL,  'H'  },
                {  "noissue",        no_argument,        NULL,  'i'  },
@@ -864,6 +868,10 @@ static void parse_args(int argc, char **argv, struct options *op)
                case LIST_SPEEDS_OPTION:
                        list_speeds();
                        exit(EXIT_SUCCESS);
+               case ISSUE_SHOW_OPTION:
+                       show_issue(op);
+                       exit(EXIT_SUCCESS);
+                       break;
                case VERSION_OPTION:
                        output_version();
                        exit(EXIT_SUCCESS);
@@ -1794,6 +1802,11 @@ static void eval_issue_file(struct issue *ie __attribute__((__unused__)),
                            struct termios *tp __attribute__((__unused__)))
 {
 }
+
+static void show_issue(struct options *op __attribute__((__unused__)))
+{
+}
+
 #else /* ISSUE_SUPPORT */
 
 static int issuefile_read_stream(
@@ -1816,7 +1829,6 @@ static int issuefile_read_stream(
                        putc(c, ie->output);
        }
 
-       fclose(f);
        return 0;
 }
 
@@ -1827,9 +1839,10 @@ static int issuefile_read(
        FILE *f = fopen(filename, "r" UL_CLOEXECSTR);
        int rc = 1;
 
-       if (f)
+       if (f) {
                rc = issuefile_read_stream(ie, f, op, tp);
-       fclose(f);
+               fclose(f);
+       }
        return rc;
 }
 
@@ -1954,6 +1967,27 @@ done:
        if (ie->output)
                fclose(ie->output);
 }
+
+/* This is --show-issue backend, executed by normal user on the current
+ * terminal.
+ */
+static void show_issue(struct options *op)
+{
+       struct issue ie = { .output = NULL };
+       struct termios tp;
+
+       memset(&tp, 0, sizeof(struct termios));
+       if (tcgetattr(STDIN_FILENO, &tp) < 0)
+               err(EXIT_FAILURE, _("failed to get terminal attributes: %m"));
+
+       eval_issue_file(&ie, op, &tp);
+
+       if (ie.mem_sz)
+               write_all(STDOUT_FILENO, ie.mem, ie.mem_sz);
+
+       free(ie.mem);
+}
+
 #endif /* ISSUE_SUPPORT */
 
 /* Show login prompt, optionally preceded by /etc/issue contents. */
@@ -2377,6 +2411,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -c, --noreset              do not reset control mode\n"), out);
        fputs(_(" -E, --remote               use -r <hostname> for login(1)\n"), out);
        fputs(_(" -f, --issue-file <file>    display issue file\n"), out);
+       fputs(_("     --show-issue           display issue file and exit\n"), out);
        fputs(_(" -h, --flow-control         enable hardware flow control\n"), out);
        fputs(_(" -H, --host <hostname>      specify login host\n"), out);
        fputs(_(" -i, --noissue              do not display issue file\n"), out);