agetty: extend --issue-file to support multiple paths

The current default behavior is to print the first issue file/dir and
all alternative locations are used as a backup solution only. If something
is found than the rest is ignored. The --issue-file allow to overwrite
this default behavior, but currently it supports only one file/dir.

This patch extend --issue-file to support ':' separated list of paths
and *all* the files (if exist and no empty) in the list are printed.

 agetty --issue-file=/etc/issue:/etc/issue.d:/run/issue:/run/issue.d:/usr/lib/issue:/usr/lib/issue.d

Addresses: https://github.com/karelzak/util-linux/issues/1041
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2020-05-19 10:55:20 +02:00
parent 1001633991
commit e327a7acd6
3 changed files with 35 additions and 21 deletions

View File

@ -151,7 +151,7 @@ configuration items are relevant for
.B MOTD_FILE
(string)
.RS 4
Sepecifies a ":" delimited list of "message of the day" files and directories
Specifies a ":" delimited list of "message of the day" files and directories
to be displayed upon login. If the specified path is a directory then displays
all files with .motd file extension in version-sort order from the directory.
.PP

View File

@ -32,7 +32,7 @@ Optionally does not hang up when it is given an already opened line
.IP \(bu
Optionally does not display the contents of the \fI/etc/issue\fP file.
.IP \(bu
Optionally displays an alternative issue file or directory instead of \fI/etc/issue\fP or \fI/etc/issue.d\fP.
Optionally displays an alternative issue files or directories instead of \fI/etc/issue\fP or \fI/etc/issue.d\fP.
.IP \(bu
Optionally does not ask for a login name.
.IP \(bu
@ -117,12 +117,13 @@ is added to the \fB/bin/login\fP command line.
.IP
See \fB\-\-login\-options\fR.
.TP
\-f, \-\-issue\-file \fIfile|directory\fP
Display the contents of \fIfile\fP instead of \fI/etc/issue\fP (or other). If the
specified path is a \fIdirectory\fP then displays all files with .issue file
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.
\-f, \-\-issue\-file \fIpath\fP
Specifies a ":" delimited list of files and directories to be displayed instead
of \fI/etc/issue\fP (or other). All specified files and directories are displayed,
missing or empty files are silently ignored. If the specified path is a
directory then display all files with .issue file extension in version-sort
order from the directory. This allows custom messages to be displayed on
different terminals. The \fB\-\-noissue\fP option will override this option.
.TP
\-\-show\-issue
Display the current issue file (or other) on the current terminal and exit.

View File

@ -700,6 +700,7 @@ static void output_version(void)
static void parse_args(int argc, char **argv, struct options *op)
{
int c;
int opt_show_issue = 0;
enum {
VERSION_OPTION = CHAR_MAX + 1,
@ -869,8 +870,7 @@ static void parse_args(int argc, char **argv, struct options *op)
list_speeds();
exit(EXIT_SUCCESS);
case ISSUE_SHOW_OPTION:
show_issue(op);
exit(EXIT_SUCCESS);
opt_show_issue = 1;
break;
case VERSION_OPTION:
output_version();
@ -882,6 +882,11 @@ static void parse_args(int argc, char **argv, struct options *op)
}
}
if (opt_show_issue) {
show_issue(op);
exit(EXIT_SUCCESS);
}
debug("after getopt loop\n");
if (argc < optind + 1) {
@ -1929,24 +1934,32 @@ static void eval_issue_file(struct issue *ie,
#endif
if (!(op->flags & F_ISSUE))
goto done;
/*
* The custom issue file or directory specified by: agetty -f <path>.
* The custom issue file or directory list specified by:
* agetty --isue-file <path[:path]...>
* Note that nothing is printed if the file/dir does not exist.
*/
if (op->issue) {
struct stat st;
char *list = strdup(op->issue);
char *file;
if (stat(op->issue, &st) < 0)
goto done;
if (S_ISDIR(st.st_mode))
issuedir_read(ie, op->issue, op, tp);
else
issuefile_read(ie, op->issue, op, tp);
if (!list)
log_err(_("failed to allocate memory: %m"));
for (file = strtok(list, ":"); file; file = strtok(NULL, ":")) {
struct stat st;
if (stat(file, &st) < 0)
continue;
if (S_ISDIR(st.st_mode))
issuedir_read(ie, file, op, tp);
else
issuefile_read(ie, file, op, tp);
}
free(list);
goto done;
}
/* The default /etc/issue and optional /etc/issue.d directory as
* extension to the file. The /etc/issue.d directory is ignored if
* there is no /etc/issue file. The file may be empty or symlink.
@ -2428,7 +2441,7 @@ static void __attribute__((__noreturn__)) usage(void)
fputs(_(" -a, --autologin <user> login the specified user automatically\n"), out);
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(_(" -f, --issue-file <list> display issue files or directories\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);