Merge branch '170427' of github.com:jwpi/util-linux

* '170427' of github.com:jwpi/util-linux:
  hwclock: remove unused stdarg.h
  Docs: update howto-usage-function.txt
  hwclock: add --update-drift check
  hwclock: slice up the usage text
  hwclock: update --help content and grammar
  hwclock: use RTC in help output
  include: update pathnames.h
  hwclock: add usage() functions heading
  hwclock: update usage() FILE name
  hwclock: update usage() to util-linux style
  hwclock: remove dead code in usage()
This commit is contained in:
Karel Zak 2017-06-21 11:16:23 +02:00
commit 8ad750bc3c
6 changed files with 67 additions and 97 deletions

View File

@ -33,6 +33,9 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
{
fputs(USAGE_HEADER, out);
fprintf(out, _(" %s [options] file...\n"), program_invocation_short_name);
fputs(USAGE_FUNCTIONS, out);
fputs(_(" -s, --do-something some specific task\n"), out);
fputs(_(" -o, --do-other some different task\n"), out);
fputs(USAGE_OPTIONS, out);
fputs(_(" -n, --no-argument option does not use argument\n"), out);
fputs(_(" --optional[=<arg>] option argument is optional\n"), out);

View File

@ -10,8 +10,7 @@ other purpose:
The rule of thumb with other options is that once they exist, you may
not change them, nor change how they work, nor remove them.
Notice that '-?' is not expected to be a synonym of '--help', but is an
unknown option resulting in a usage print-out due to a getopt failure.
See Legacy options below.
How a usage text is supposed to look
@ -118,6 +117,7 @@ entail for translators will pay off later, at the time of the next change,
when they will not need to search in the long fuzzy text what was changed,
where, how, and whether it was the only change.
Synopsis
--------
@ -143,13 +143,15 @@ Some commands use peculiar options and arguments. These will continue
to be supported, but anything like them will not be accepted as new
additions. A short list of examples:
- Other characters than '-' to start an option. See '+' in 'more'.
- Using a number as an option argument. See '-<number>' in 'more'.
- Characters other than '-' to start an option. See '+' in 'more'.
- Using a number as an option. See '-<number>' in 'more'.
- Long options that start with a single '-'. See 'setterm'.
- '-?' is not expected to be a synonym of '--help', but is an unknown
option resulting in a suggestion to try --help due to a getopt failure.
Example file
------------
The file disk-utils/delpart.c is a minimal example of how to write
The file ./boilerplate.c is a minimal example of how to write
a usage function, set up option parsing, version printing and so on.

View File

@ -317,9 +317,10 @@ static inline int xusleep(useconds_t usec)
*/
#define USAGE_HEADER _("\nUsage:\n")
#define USAGE_OPTIONS _("\nOptions:\n")
#define USAGE_FUNCTIONS _("\nFunctions:\n")
#define USAGE_SEPARATOR "\n"
#define USAGE_HELP _(" -h, --help display this help and exit\n")
#define USAGE_VERSION _(" -V, --version output version information and exit\n")
#define USAGE_HELP _(" -h, --help display help information and exit\n")
#define USAGE_VERSION _(" -V, --version display version information and exit\n")
#define USAGE_MAN_TAIL(_man) _("\nFor more details see %s.\n"), _man
#define UTIL_LINUX_VERSION _("%s from %s\n"), program_invocation_short_name, PACKAGE_STRING

View File

@ -7,7 +7,7 @@
#define PATHNAMES_H
#ifdef HAVE_PATHS_H
#include <paths.h>
# include <paths.h>
#endif
#ifndef __STDC__
@ -41,45 +41,40 @@
#define _PATH_NOLOGIN_TXT "/etc/nologin.txt"
#ifndef _PATH_MAILDIR
#define _PATH_MAILDIR "/var/spool/mail"
# define _PATH_MAILDIR "/var/spool/mail"
#endif
#define _PATH_MOTDFILE "/etc/motd"
#ifndef _PATH_NOLOGIN
#define _PATH_NOLOGIN "/etc/nologin"
# define _PATH_NOLOGIN "/etc/nologin"
#endif
#define _PATH_VAR_NOLOGIN "/var/run/nologin"
#ifndef _PATH_LOGIN
#define _PATH_LOGIN "/bin/login"
# define _PATH_LOGIN "/bin/login"
#endif
#define _PATH_SHUTDOWN "/sbin/shutdown"
#define _PATH_TERMCOLORS_DIRNAME "terminal-colors.d"
#define _PATH_TERMCOLORS_DIR "/etc/" _PATH_TERMCOLORS_DIRNAME
/* used in login-utils/shutdown.c */
/* used in login-utils/setpwnam.h and login-utils/islocal.c */
/* login paths */
#define _PATH_PASSWD "/etc/passwd"
/* used in login-utils/newgrp and login-utils/setpwnam.h*/
#define _PATH_GSHADOW "/etc/gshadow"
/* used in login-utils/setpwnam.h */
#define _PATH_GROUP "/etc/group"
#define _PATH_SHADOW_PASSWD "/etc/shadow"
#define _PATH_SHELLS "/etc/shells"
/* used in term-utils/agetty.c */
#ifndef _PATH_BTMP
# define _PATH_BTMP "/var/log/btmp"
#endif
#define _PATH_ISSUE "/etc/issue"
#define _PATH_OS_RELEASE_ETC "/etc/os-release"
#define _PATH_OS_RELEASE_USR "/usr/lib/os-release"
#define _PATH_NUMLOCK_ON _PATH_LOCALSTATEDIR "/numlock-on"
#define _PATH_LOGINDEFS "/etc/login.defs"
/* used in misc-utils/look.c */
/* misc paths */
#define _PATH_WORDS "/usr/share/dict/words"
#define _PATH_WORDS_ALT "/usr/share/dict/web2"
@ -154,15 +149,10 @@
# define _PATH_ADJTIME "/etc/adjtime"
#endif
#define _PATH_LASTDATE "/var/lib/lastdate"
#ifdef __ia64__
# define _PATH_RTC_DEV "/dev/efirtc"
#else
# define _PATH_RTC_DEV "/dev/rtc"
#endif
#ifndef _PATH_BTMP
#define _PATH_BTMP "/var/log/btmp"
# define _PATH_RTC_DEV "/dev/rtc0"
#endif
/* raw paths*/
@ -195,9 +185,7 @@
/* ctrlaltdel paths */
#define _PATH_PROC_CTRL_ALT_DEL "/proc/sys/kernel/ctrl-alt-del"
/* hwclock-cmos paths */
#define _PATH_DEV_PORT "/dev/port"
/* lscpu paths */
#define _PATH_PROC_CPUINFO "/proc/cpuinfo"
#endif /* PATHNAMES_H */

View File

@ -376,9 +376,8 @@ in learning about the internal operations of hwclock.
.B \-\-update\-drift
Update the Hardware Clock's drift factor in
.IR @ADJTIME_PATH@ .
It is used with
It can only be used with
.BR \-\-set " or " \%\-\-systohc ,
otherwise it is ignored.
.sp
A minimum four hour period between settings is required. This is to
avoid invalid calculations. The longer the period, the more precise the

View File

@ -61,7 +61,6 @@
#include <getopt.h>
#include <limits.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -1199,78 +1198,51 @@ static void out_version(void)
printf(UTIL_LINUX_VERSION);
}
/*
* usage - Output (error and) usage information
*
* This function is called both directly from main to show usage information
* and as fatal function from shhopt if some argument is not understood. In
* case of normal usage info FMT should be NULL. In that case the info is
* printed to stdout. If FMT is given usage will act like fprintf( stderr,
* fmt, ... ), show a usage information and terminate the program
* afterwards.
*/
static void __attribute__((__noreturn__))
usage(const struct hwclock_control *ctl, const char *fmt, ...)
usage(const struct hwclock_control *ctl, FILE *out)
{
FILE *usageto;
va_list ap;
fputs(USAGE_HEADER, out);
fputs(_(" hwclock [function] [option...]\n"), out);
usageto = fmt ? stderr : stdout;
fputs(USAGE_SEPARATOR, out);
fputs(_(" Query or set the RTC (Real Time Clock / Hardware Clock)\n"), out);
fputs(USAGE_HEADER, usageto);
fputs(_(" hwclock [function] [option...]\n"), usageto);
fputs(USAGE_SEPARATOR, usageto);
fputs(_("Query or set the hardware clock.\n"), usageto);
fputs(_("\nFunctions:\n"), usageto);
fputs(_(" -h, --help show this help text and exit\n"
" -r, --show read hardware clock and print result\n"
" --get read hardware clock and print drift corrected result\n"
" --set set the RTC to the time given with --date\n"), usageto);
fputs(_(" -s, --hctosys set the system time from the hardware clock\n"
" -w, --systohc set the hardware clock from the current system time\n"
" --systz set the system time based on the current timezone\n"
" --adjust adjust the RTC to account for systematic drift since\n"
" the clock was last set or adjusted\n"), usageto);
fputs(USAGE_FUNCTIONS, out);
fputs(_(" -r, --show display the RTC time\n"), out);
fputs(_(" --get display drift corrected RTC time\n"), out);
fputs(_(" --set set the RTC according to --date\n"), out);
fputs(_(" -s, --hctosys set the system time from the RTC\n"), out);
fputs(_(" -w, --systohc set the RTC from the system time\n"), out);
fputs(_(" --systz send timescale configurations to the kernel\n"), out);
fputs(_(" --adjust adjust the RTC to account for systematic drift\n"), out);
#if defined(__linux__) && defined(__alpha__)
fputs(_(" --getepoch print out the kernel's hardware clock epoch value\n"
" --setepoch set the kernel's hardware clock epoch value to the \n"
" value given with --epoch\n"), usageto);
fputs(_(" --getepoch display the RTC epoch\n"), out);
fputs(_(" --setepoch set the RTC epoch according to --epoch\n"), out);
#endif
fputs(_(" --predict predict RTC reading at time given with --date\n"
" -V, --version display version information and exit\n"), usageto);
fputs(USAGE_OPTIONS, usageto);
fputs(_(" -u, --utc the hardware clock is kept in UTC\n"
" -l, --localtime the hardware clock is kept in local time\n"), usageto);
fputs(_(" --predict predict the drifted RTC time according to --date\n"), out);
fputs(USAGE_OPTIONS, out);
fputs(_(" -u, --utc inform hwclock the RTC timescale is UTC\n"), out);
fputs(_(" -l, --localtime inform hwclock the RTC timescale is Local\n"), out);
fprintf(out, _(
#ifdef __linux__
fputs(_(" -f, --rtc <file> special /dev/... file to use instead of default\n"), usageto);
" -f, --rtc <file> use an alternate file to %1$s\n"
#endif
fprintf(usageto, _(
" --directisa access the ISA bus directly instead of %s\n"
" --date <time> specifies the time to which to set the hardware clock\n"), _PATH_RTC_DEV);
" --directisa use the ISA bus instead of %1$s access\n"), _PATH_RTC_DEV);
fputs(_(" --date <time> date/time input for --set and --predict\n"), out);
#if defined(__linux__) && defined(__alpha__)
fputs(_(" --epoch <year> specifies the hardware clock's epoch value\n"), usageto);
fputs(_(" --epoch <year> epoch input for --setepoch\n"), out);
#endif
fprintf(usageto, _(
" --update-drift update drift factor in %1$s (requires\n"
" --set or --systohc)\n"
" --noadjfile do not access %1$s; this requires the use of\n"
" either --utc or --localtime\n"
" --adjfile <file> specifies the path to the adjust file;\n"
" the default is %1$s\n"), _PATH_ADJTIME);
fputs(_(" --test do not update anything, just show what would happen\n"
" -D, --debug debugging mode\n" "\n"), usageto);
if (fmt) {
va_start(ap, fmt);
vfprintf(usageto, fmt, ap);
va_end(ap);
}
fflush(usageto);
hwclock_exit(ctl, fmt ? EX_USAGE : EX_OK);
fputs(_(" --update-drift update the RTC drift factor\n"), out);
fprintf(out, _(
" --noadjfile do not use %1$s\n"
" --adjfile <file> use an alternate file to %1$s\n"), _PATH_ADJTIME);
fputs(_(" --test dry run; use -D to view what would have happened\n"), out);
fputs(_(" -D, --debug use debug mode\n"), out);
fputs(USAGE_SEPARATOR, out);
fputs(USAGE_HELP, out);
fputs(USAGE_VERSION, out);
fprintf(out, USAGE_MAN_TAIL("hwclock(8)"));
hwclock_exit(ctl, EXIT_SUCCESS);
}
/*
@ -1475,7 +1447,7 @@ int main(int argc, char **argv)
out_version();
return 0;
case 'h': /* --help */
usage(&ctl, NULL);
usage(&ctl, stdout);
default:
errtryhelp(EXIT_FAILURE);
}
@ -1492,6 +1464,11 @@ int main(int argc, char **argv)
if (!ctl.adj_file_name)
ctl.adj_file_name = _PATH_ADJTIME;
if (ctl.update && !ctl.set && !ctl.systohc) {
warnx(_("--update-drift requires --set or --systohc"));
hwclock_exit(&ctl, EX_USAGE);
}
if (ctl.noadjfile && !ctl.utc && !ctl.local_opt) {
warnx(_("With --noadjfile, you must specify "
"either --utc or --localtime"));