]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rtcwake: add human readable --date timestamp format
authorSami Kerola <kerolasa@iki.fi>
Sat, 10 Jan 2015 18:31:29 +0000 (18:31 +0000)
committerKarel Zak <kzak@redhat.com>
Mon, 29 Jun 2015 11:39:37 +0000 (13:39 +0200)
Reviewed-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
bash-completion/rtcwake
sys-utils/rtcwake.8.in
sys-utils/rtcwake.c

index d7d1427011d740faa70627e985af1647e86dc0ad..51566a2a225a6dedfa1b21725b2b490a7d3a77d9 100644 (file)
@@ -23,11 +23,16 @@ _rtcwake_module()
                        COMPREPLY=( $(compgen -W "time_t" -- $cur) )
                        return 0
                        ;;
+               '--date')
+                       COMPREPLY=( $(compgen -W "YYYYMMDDhhmmss" -- $cur) )
+                       return 0
+                       ;;
                '-h'|'--help'|'-V'|'--version')
                        return 0
                        ;;
        esac
-       OPTS="--device
+       OPTS="  --date
+               --device
                --dry-run
                --local
                --mode
index 5ec9c6ccb0afd2ad4af29fab1cd112e02d355bc0..be4a88f4d0a692fc6e180bd9162e8c1370e28fdd 100644 (file)
@@ -53,6 +53,22 @@ from the \fIadjtime\fP file, where
 .BR hwclock (8)
 stores that information.  This is the default.
 .TP
+.BR \-\-date " \fItimestamp"
+Set the wakeup time to the value of the timestamp.  Format of the
+timestmap can be any of the following:
+.TS
+tab(|);
+left l2 l.
+YYYYMMDDhhmmss
+YYYY-MM-DD hh:mm:ss
+YYYY-MM-DD hh:mm|(seconds will be set to 00)
+YYYY-MM-DD|(time will be set to 00:00:00)
+hh:mm:ss|(date will be set to today)
+hh:mm|(date will be set to today, seconds to 00)
+tomorrow|(time is set to 00:00:00)
++5min
+.TE
+.TP
 .BR \-d , " \-\-device " \fIdevice
 Use the specified \fIdevice\fP instead of \fBrtc0\fP as realtime clock.
 This option is only relevant if your system has more than one RTC.
@@ -156,4 +172,4 @@ There is NO WARRANTY, to the extent permitted by law.
 The rtcwake command is part of the util-linux package and is available from the
 .UR ftp://\:ftp.kernel.org\:/pub\:/linux\:/utils\:/util-linux/
 Linux Kernel Archive
-.UE .
\ No newline at end of file
+.UE .
index 6d67fc26a74a56c214e386a2f0e1b437b4e86f90..0caab24da9604956591e2c09e2485d002ab5d1e4 100644 (file)
@@ -41,6 +41,7 @@
 #include "strutils.h"
 #include "c.h"
 #include "closestream.h"
+#include "timeutils.h"
 
 /* constants from legacy PC/AT hardware */
 #define        RTC_PF  0x40
@@ -113,6 +114,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fprintf(out,
              _(" -A, --adjfile <file>     specifies the path to the adjust file\n"
                "                            the default is %s\n"), _PATH_ADJTIME);
+       fputs(_("     --date <timestamp>   date time of timestamp to wake\n"), out);
        fputs(_(" -d, --device <device>    select rtc device (rtc0|rtc1|...)\n"), out);
        fputs(_(" -n, --dry-run            does everything, but suspend\n"), out);
        fputs(_(" -l, --local              RTC uses local timezone\n"), out);
@@ -398,6 +400,10 @@ int main(int argc, char **argv)
        int             fd;
        time_t          alarm = 0;
 
+       enum {
+               OPT_DATE = CHAR_MAX + 1
+       };
+
        static const struct option long_options[] = {
                {"adjfile",     required_argument,      0, 'A'},
                {"auto",        no_argument,            0, 'a'},
@@ -411,6 +417,7 @@ int main(int argc, char **argv)
                {"device",      required_argument,      0, 'd'},
                {"seconds",     required_argument,      0, 's'},
                {"time",        required_argument,      0, 't'},
+               {"date",        required_argument,      0, OPT_DATE},
                {0,             0,                      0, 0  }
        };
 
@@ -448,18 +455,25 @@ int main(int argc, char **argv)
                        ctl.dryrun = 1;
                        break;
 
-                       /* alarm time, seconds-to-sleep (relative) */
                case 's':
+                       /* alarm time, seconds-to-sleep (relative) */
                        seconds = strtou32_or_err(optarg, _("invalid seconds argument"));
                        break;
 
-                       /* alarm time, time_t (absolute, seconds since
-                        * 1/1 1970 UTC)
-                        */
                case 't':
+                       /* alarm time, time_t (absolute, seconds since epoc) */
                        alarm = strtou32_or_err(optarg, _("invalid time argument"));
                        break;
 
+               case OPT_DATE:
+               {
+                       /* alarm time, see timestamp format from manual */
+                       usec_t p;
+                       if (parse_timestamp(optarg, &p) < 0)
+                               errx(EXIT_FAILURE, _("invalid time value \"%s\""), optarg);
+                       alarm = (time_t) (p / 1000000);
+                       break;
+               }
                case 'u':
                        ctl.clock_mode = CM_UTC;
                        break;
@@ -491,7 +505,7 @@ int main(int argc, char **argv)
                                _("Using local time.\n"));
 
        if (!alarm && !seconds && suspend != DISABLE_MODE && suspend != SHOW_MODE) {
-               warnx(_("must provide wake time (see -t and -s options)"));
+               warnx(_("must provide wake time (see --seconds, --time, and --date options)"));
                usage(stderr);
        }