Commit Graph

81 Commits

Author SHA1 Message Date
Karel Zak 01b37affc1 rtcwake: fix time_t=long assumptions
References: ce3355cc54
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-06 11:07:22 +02:00
Sami Kerola f6b6beaf6a
various: fix more lgtm scan warnings
The logger and rtwake time function changes continue the same fixes as
previous commit - use thread safe functions.  The libsmartcols condition
removal is possible because width must be greater than tb->termwidth that is
size_t and cannot be smaller than zero.  And remove couple FIXME's that are
old and unlikely ever to get fixed.

Reference: 3160589d86
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-02-20 20:18:46 +00:00
Sami Kerola 3160589d86
various: use threadsafe versions of time functions [lgtm scan]
Deprecating calls to not-thread safe asctime(), ctime(), and localtime()
calls is pretty close to pointless change.  Lets do it to reduce lgtm scan
warnings with justification it's nicer to use static analysis tools when
they have very few positives.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-02-15 15:23:44 +00:00
Karel Zak d3149a8556 rtcwake: terminate mode and excl[]
* terminate string read from /proc
* terminate array for exclusive options

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-28 12:53:58 +02:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Justin Chen e1686b25ac rtcwake: use poweroff if shutdown is not found
Some systems do not have the shutdown command. Use poweroff as an
alternative.

Signed-off-by: Justin Chen <justinpopo6@gmail.com>
2018-11-06 12:34:02 +01:00
Sami Kerola c8ff2e5562 rtcwake: wait stdin to settle down before entering a system sleep
This can delay entering to system sleep up to 0.28 seconds while discarding
input, when stdin is interactive device.

[kzak@redhat.com: - add note to the man page]

Reference: https://github.com/karelzak/util-linux/issues/527
See-also: a85c390134
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-02 15:14:37 +01:00
Karel Zak e72027dada rtcwake: fix sys vs. rtc time delta usage
srett commented:

 After some head scratching why relative wakeup using -s always works
 while -t didn't seem to work at all I discovered that the adjustment
 for time difference between sys and rtc is actually inverted when
 writing the alarm (code for -m show reading is fine), so if the RTC
 lags 10 minutes behind, the alarm will be shifted into the future by
 10 minutes, resulting in a wakeup that is 20 minutes late.

Addresses: https://github.com/karelzak/util-linux/issues/544
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-27 12:37:53 +01:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier 9325dbfd20 misc: cleanup and fix --unknownopt issues
Fixed checkusage.sh warnings:

  rtcwake: --unknownopt, non-empty stdout

  rtcwake: --unknownopt, stderr too long: 21
  blockdev: --unknownopt, stderr too long: 28
  lsipc: --unknownopt, stderr too long: 77
  pg: --unknownopt, stderr too long: 23
  renice: --unknownopt, stderr too long: 18
  sulogin: --unknownopt, stderr too long: 17
  write: --unknownopt, stderr too long: 12

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Karel Zak a325f3c206 rtcwake: make sure buffer is zero terminated [coverity scan] 2016-10-05 11:11:45 +02:00
Sami Kerola 984a60965a
misc: always check setenv(3) return value
At least glibc setenv(3) can fail when system runs out of memory.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-08-12 21:25:36 +01:00
Sami Kerola eb2306e675
misc: fix declarations shadowing variables in the global scope [oclint]
Fixes multiple occurences of 'optarg' overwrites.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Sami Kerola 74ce680a3e
misc: simplify if clauses [oclint]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Ruediger Meier eaac9f88f9 misc: fix some includes
features.h:  any glibc header includes this already
libgen.h:    was unused there
sys/uio.h:   for writev(3p)
sys/queue.h  seems like it was never used

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-29 13:04:56 +01:00
Karel Zak 6b497c0e19 rtcwake: improve open() usage [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-05 11:33:29 +02:00
Karel Zak f078134257 rtcwake: cosmetic changes
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-29 15:19:47 +02:00
Karel Zak bac778c06a rtcwake: fix ARRAY_SIZE() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-29 13:46:05 +02:00
Karel Zak 2626f123a5 rtcwake: don't use usage() on error
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-29 13:43:41 +02:00
Sami Kerola 76037ac7d8 rtcwake: fix valgrind warning
==3445== Syscall param ioctl(generic) points to uninitialised byte(s)
==3445==    at 0x4F16477: ioctl (in /usr/lib/libc-2.21.so)
==3445==    by 0x402785: setup_alarm (rtcwake.c:231)
==3445==    by 0x403302: main (rtcwake.c:520)

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 13:39:37 +02:00
Sami Kerola f87b73ab44 rtcwake: read accepted mode strings from /sys/power/state
The rtcwake has various mode names that are internal to the command,
listed in rtcwake_mode_string array, while some modes are dynamicaly
listed in /sys/power/state.  Together these form the allowed modes.

[kzak@redhat.com: - cleanup strv usage]

Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-29 13:39:37 +02:00
Sami Kerola 254e9e58b7 rtcwake: make some command line options mutually exclusive
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 13:39:37 +02:00
Sami Kerola 5b4185e17d rtcwake: improve coding style
Reviewed-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 13:39:37 +02:00
Sami Kerola 43a44bfc6d rtcwake: add --list-modes
Commit ece44f19f4 missed freeze mode, which
to a simple patch adding the missing argument but Karel pointed out it
would be better to make the rtcwake to tell what arguments are supported
so that possible changes end up to be automatically correct in bash
completion.

Proposed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 13:39:37 +02:00
Sami Kerola 067fde32c9 rtcwake: do not overwrite device name
This improves error messaging, and removes a memory leak.

Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 13:39:37 +02:00
Sami Kerola 499a0c7956 rtcwake: clean up struct tm initializations
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 13:39:37 +02:00
Sami Kerola 356b2989ae rtcwake: fix preprocessor redefinition
The RTC_AF is expected to be part of linux/rtc.h file.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 13:39:37 +02:00
Sami Kerola a10ce9a3e5 rtcwake: add human readable --date timestamp format
Reviewed-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 13:39:37 +02:00
Sami Kerola 3e5a54554d rtcwake: improve read_clock_mode()
Make skipping two lines more robust, and add message about unexpected
adjfile contents when running with --verbose.

Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 13:39:37 +02:00
Sami Kerola 5fde2f0d34 rtcwake: remove RTC_ALM_READ and RTC_ALM_SET compatibility
The RTC_WKALM_RD and RTC_WKALM_SET have been available since 2.6.17, and
preferred way since 2007.  Keeping the fallbacks to the old interface is
no longer needed.

Reference: e824290e5d
Reference: f8245c2688
Reviewed-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 13:39:37 +02:00
Sami Kerola 64a8067835 rtcwake: replace long if else statement with switch case
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 13:39:37 +02:00
Sami Kerola 6e1ec14faf rtcwake: enumerate constant mode strings
Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 13:39:37 +02:00
Sami Kerola 71d95e92c1 rtcwake: add rtcwake_control and remove global variables
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-06-29 13:39:37 +02:00
Ruediger Meier f205c90a72 build: fix printf warnings for icc (-Wformat-security)
Intel compiler complains about printf style function calls with trivial
format string and no other arguments. Like this one:

../sys-utils/ipcrm.c(117): warning #2279: printf/scanf format not a string literal and no format arguments
                        err(EXIT_FAILURE, iskey ? _("key failed") : _("id failed"));
2015-01-21 11:15:19 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Sami Kerola f627750083 textual: use version printing macro everywhere
Only mount, umount, and blkid remains not using the macro because they
are print also library references.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:23 +02:00
Karel Zak a5bd793996 include/c.h: prefer nanosleep() over usleep()
Let's use nanosleep() although if usleep() exists. The nanosleep
function does no interact with signals and other timers.

The patch introduces xusleep() as replacement to libc (or our fallback)
usleep(). Yes, we don't want to use struct timespec + nanosleep()
everywhere in code as nano-time resolution is useless for us.

The patch also enlarges delays in some busy wait loops. It seems
enough to try read/write 4x per second.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-24 13:04:14 +01:00
Mike Frysinger caf60f22fb rtcwake: pass -h to shutdown
The sysvinit shutdown requires you use -h when using -H or -P.
Other inits just don't seem to care.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2013-04-25 09:23:40 +02:00
Karel Zak ece44f19f4 rtcwake: add support for "freeze" mode
Supported by Linux since 3.9 (upstream commit
7e73c5ae6e7991a6c01f6d096ff8afaef4458c36).

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-23 13:20:15 +02:00
Karel Zak 49ebda9b89 rtcwake: add --auto to usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-05 13:19:13 +02:00
Karel Zak 09e092ad5c rtcwake: clean up usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-26 12:14:31 +01:00
Karel Zak 7528fae9e9 include/pathnames: rename _PATH_ADJPATH to _PATH_ADJTIME
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-26 11:45:45 +01:00
Karel Zak 3a2f3e82bb rtcwake: add --adjfile command line option
... for better compatibility with hwclock.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-26 11:16:12 +01:00
Sami Kerola 07ff972eb6 translation: unify exec error messages
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-02-06 11:51:17 +01:00
Benno Schulenberg 217615e8ed textual: standardize reporting of program name plus package version
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-01-25 11:47:29 +01:00
Karel Zak 2a31396a9c include/c: move usleep() fallback to c.h
To make it available everywhere in code.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-22 11:03:09 +02:00
Giacomo 829eab67e6 rtcwake: doesn't reset wakealarm
Disable an alarm use the same logic used to enable it: first try RTC_WKALM_SET
with the "enabled" flag set to false, if it fails fall back to RTC_AIE_OFF.

Signed-off-by: Giacomo <giacomo.perale@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-13 13:23:11 +02:00