summaryrefslogtreecommitdiffstats
path: root/login-utils/login.c
diff options
context:
space:
mode:
authorRuediger Meier2017-06-21 04:14:58 +0200
committerRuediger Meier2017-06-22 21:34:54 +0200
commit7491906df6869e5251ab96ee1de078d0ffc7d3a8 (patch)
tree2b2d5fa0e70c382461ba369f6ae0503e70770efd /login-utils/login.c
parentfsck: add --help and --version (diff)
downloadkernel-qcow2-util-linux-7491906df6869e5251ab96ee1de078d0ffc7d3a8.tar.gz
kernel-qcow2-util-linux-7491906df6869e5251ab96ee1de078d0ffc7d3a8.tar.xz
kernel-qcow2-util-linux-7491906df6869e5251ab96ee1de078d0ffc7d3a8.zip
login: add --help and --version
Also we don't print the usage text on stderr anymore. Note, the usage text could be improved, currently it does not describe any options. I have only added a pointer to the man page. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'login-utils/login.c')
-rw-r--r--login-utils/login.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/login-utils/login.c b/login-utils/login.c
index 37553ef0a..ee06d03e8 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -1095,6 +1095,16 @@ static void init_remote_info(struct login_context *cxt, char *remotehost)
}
}
+static void __attribute__((__noreturn__)) usage(void)
+{
+ fputs(USAGE_HEADER, stdout);
+ printf(_(" %s [-p] [-h <host>] [-H] [[-f] <username>]\n"), program_invocation_short_name);
+ fputs(USAGE_SEPARATOR, stdout);
+ fputs(_("Begin a session on the system.\n"), stdout);
+ printf(USAGE_MAN_TAIL("login(1)"));
+ exit(EXIT_SUCCESS);
+}
+
int main(int argc, char **argv)
{
int c;
@@ -1119,6 +1129,14 @@ int main(int argc, char **argv)
};
+ /* the only two longopts to satisfy UL standards */
+ enum { HELP_OPTION = CHAR_MAX + 1 };
+ static const struct option longopts[] = {
+ {"help", no_argument, NULL, HELP_OPTION},
+ {"version", no_argument, NULL, 'V'},
+ {NULL, 0, NULL, 0}
+ };
+
timeout = (unsigned int)getlogindefs_num("LOGIN_TIMEOUT", LOGIN_TIMEOUT);
signal(SIGALRM, timedout);
@@ -1142,7 +1160,7 @@ int main(int argc, char **argv)
* -h is used by other servers to pass the name of the remote
* host to login so that it may be placed in utmp and wtmp
*/
- while ((c = getopt(argc, argv, "fHh:pV")) != -1)
+ while ((c = getopt_long(argc, argv, "fHh:pV", longopts, NULL)) != -1)
switch (c) {
case 'f':
cxt.noauth = 1;
@@ -1168,12 +1186,10 @@ int main(int argc, char **argv)
case 'V':
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;
- case '?':
+ case HELP_OPTION:
+ usage();
default:
- fprintf(stderr, _("Usage: login [-p] [-h <host>] [-H] [[-f] <username>]\n"));
- fputs(USAGE_SEPARATOR, stderr);
- fputs(_("Begin a session on the system.\n"), stderr);
- exit(EXIT_FAILURE);
+ errtryhelp(EXIT_FAILURE);
}
argc -= optind;
argv += optind;