]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rtcwake: add --adjfile command line option
authorKarel Zak <kzak@redhat.com>
Tue, 26 Mar 2013 10:16:12 +0000 (11:16 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 26 Mar 2013 10:16:12 +0000 (11:16 +0100)
 ... for better compatibility with hwclock.

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/rtcwake.8
sys-utils/rtcwake.c

index a536f322c51b2d620b20e91d1336f232bf20b5de..dea5c940c5485ebf244dddd5bfd646b00defdb26 100644 (file)
@@ -21,7 +21,7 @@
 rtcwake - enter a system sleep state until specified wakeup time
 .SH SYNOPSIS
 .B rtcwake
-.RB [ \-hvVluan ]
+.RB [ options ]
 .RB [ \-d
 .IR device ]
 .RB [ \-m
@@ -56,6 +56,9 @@ Displays version information and exists.
 This option does everything but actually setup alarm, suspend system or wait 
 for the alarm.
 .TP
+\fB-A\fP | \fB--adjfile\fP \fIfile\fP
+Specifies an alternative path to the adjust file.
+.TP
 \fB-a\fP | \fB--auto\fP
 Reads the clock mode (whether the hardware clock is set to UTC or local time)
 from \fI/etc/adjtime\fP. That's the location where the
index f0dada2e05954cab66e17ae032a00ccae6726240..f233f506e6c03d2396a24f910e490aedc14a7dab 100644 (file)
@@ -51,7 +51,6 @@
 
 #define RTC_PATH               "/sys/class/rtc/%s/device/power/wakeup"
 #define SYS_POWER_STATE_PATH   "/sys/power/state"
-#define ADJTIME_PATH           "/etc/adjtime"
 #define DEFAULT_DEVICE         "/dev/rtc0"
 #define DEFAULT_MODE           "standby"
 
@@ -61,25 +60,11 @@ enum ClockMode {
        CM_LOCAL
 };
 
+static char            *adjfile = _PATH_ADJPATH;
 static unsigned                verbose;
 static unsigned                dryrun;
 enum ClockMode         clock_mode = CM_AUTO;
 
-static struct option long_options[] = {
-       {"auto",        no_argument,            0, 'a'},
-       {"dry-run",     no_argument,            0, 'n'},
-       {"local",       no_argument,            0, 'l'},
-       {"utc",         no_argument,            0, 'u'},
-       {"verbose",     no_argument,            0, 'v'},
-       {"version",     no_argument,            0, 'V'},
-       {"help",        no_argument,            0, 'h'},
-       {"mode",        required_argument,      0, 'm'},
-       {"device",      required_argument,      0, 'd'},
-       {"seconds",     required_argument,      0, 's'},
-       {"time",        required_argument,      0, 't'},
-       {0,             0,                      0, 0  }
-};
-
 static void __attribute__((__noreturn__)) usage(FILE *out)
 {
        fputs(USAGE_HEADER, out);
@@ -87,6 +72,9 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
              _(" %s [options]\n"), program_invocation_short_name);
 
        fputs(USAGE_OPTIONS, out);
+       fprintf(out,
+             _(" -A, --adjfile <file>     specifies the path to the adjust file\n"
+               "                            the default is %s\n"), _PATH_ADJPATH);
        fputs(_(" -d, --device <device>    select rtc device (rtc0|rtc1|...)\n"
                " -n, --dry-run            does everything, but suspend\n"
                " -l, --local              RTC uses local timezone\n"
@@ -293,7 +281,7 @@ static int read_clock_mode(void)
        FILE *fp;
        char linebuf[MAX_LINE];
 
-       fp = fopen(ADJTIME_PATH, "r");
+       fp = fopen(adjfile, "r");
        if (!fp)
                return -1;
 
@@ -390,14 +378,34 @@ int main(int argc, char **argv)
        int             fd;
        time_t          alarm = 0;
 
+       static const struct option long_options[] = {
+               {"adjfile",     required_argument,      0, 'A'},
+               {"auto",        no_argument,            0, 'a'},
+               {"dry-run",     no_argument,            0, 'n'},
+               {"local",       no_argument,            0, 'l'},
+               {"utc",         no_argument,            0, 'u'},
+               {"verbose",     no_argument,            0, 'v'},
+               {"version",     no_argument,            0, 'V'},
+               {"help",        no_argument,            0, 'h'},
+               {"mode",        required_argument,      0, 'm'},
+               {"device",      required_argument,      0, 'd'},
+               {"seconds",     required_argument,      0, 's'},
+               {"time",        required_argument,      0, 't'},
+               {0,             0,                      0, 0  }
+       };
+
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
        atexit(close_stdout);
 
-       while ((t = getopt_long(argc, argv, "ahd:lm:ns:t:uVv",
+       while ((t = getopt_long(argc, argv, "A:ahd:lm:ns:t:uVv",
                                        long_options, NULL)) != EOF) {
                switch (t) {
+               case 'A':
+                       /* for better compatibility with hwclock */
+                       adjfile = optarg;
+                       break;
                case 'a':
                        /* CM_AUTO is default */
                        break;