~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to sys-utils/rtcwake.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <unistd.h>
29
29
#include <errno.h>
30
30
#include <time.h>
31
 
#include <err.h>
32
31
 
33
32
#include <sys/ioctl.h>
34
33
#include <sys/time.h>
41
40
#include "pathnames.h"
42
41
#include "usleep.h"
43
42
#include "strutils.h"
 
43
#include "c.h"
44
44
 
45
45
/* constants from legacy PC/AT hardware */
46
46
#define RTC_PF  0x40
83
83
 
84
84
static void __attribute__((__noreturn__)) usage(FILE *out)
85
85
{
86
 
        fprintf(out, _("Usage: %s [options]\n\nOptions:\n"),
87
 
                                program_invocation_short_name);
88
 
 
89
 
        fprintf(out, _(
90
 
                "    -d | --device <device>    select rtc device (rtc0|rtc1|...)\n"
91
 
                "    -n | --dry-run            does everything, but suspend\n"
92
 
                "    -l | --local              RTC uses local timezone\n"
93
 
                "    -m | --mode <mode>        standby|mem|... sleep mode\n"
94
 
                "    -s | --seconds <seconds>  seconds to sleep\n"
95
 
                "    -t | --time <time_t>      time to wake\n"
96
 
                "    -u | --utc                RTC uses UTC\n"
97
 
                "    -v | --verbose            verbose messages\n"
98
 
                "    -V | --version            show version\n"));
99
 
 
100
 
        fprintf(out, _("\nFor more information see rtcwake(8).\n"));
 
86
        fputs(_("\nUsage:\n"), out);
 
87
        fprintf(out,
 
88
              _(" %s [options]\n"), program_invocation_short_name);
 
89
 
 
90
        fputs(_("\nOptions:\n"), out);
 
91
        fputs(_(" -d, --device <device>    select rtc device (rtc0|rtc1|...)\n"
 
92
                " -n, --dry-run            does everything, but suspend\n"
 
93
                " -l, --local              RTC uses local timezone\n"
 
94
                " -m, --mode <mode>        standby|mem|... sleep mode\n"
 
95
                " -s, --seconds <seconds>  seconds to sleep\n"
 
96
                " -t, --time <time_t>      time to wake\n"
 
97
                " -u, --utc                RTC uses UTC\n"
 
98
                " -v, --verbose            verbose messages\n"
 
99
                " -V, --version            show version\n"), out);
 
100
 
 
101
        fputs(_("\nFor more information see rtcwake(8).\n"), out);
101
102
 
102
103
        exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
103
104
}
247
248
        return 0;
248
249
}
249
250
 
 
251
static int is_suspend_available(const char *suspend)
 
252
{
 
253
        int rc;
 
254
        char buf[32];
 
255
        FILE *f = fopen(SYS_POWER_STATE_PATH, "r");
 
256
 
 
257
        if (!f)
 
258
                return -1;
 
259
 
 
260
        if (fgets(buf, sizeof buf, f) == NULL)
 
261
                rc = -1;
 
262
        else
 
263
                rc = strstr(buf, suspend) != NULL;
 
264
 
 
265
        fclose(f);
 
266
        return rc;
 
267
}
 
268
 
250
269
static void suspend_system(const char *suspend)
251
270
{
252
271
        FILE    *f = fopen(SYS_POWER_STATE_PATH, "w");
380
399
                        break;
381
400
 
382
401
                case 'd':
383
 
                        devname = strdup(optarg);
 
402
                        devname = optarg;
384
403
                        break;
385
404
 
386
405
                case 'l':
405
424
                                        || strcmp(optarg, "disable") == 0
406
425
                                        || strcmp(optarg, "show") == 0
407
426
                           ) {
408
 
                                suspend = strdup(optarg);
 
427
                                suspend = optarg;
409
428
                                break;
410
429
                        }
411
430
 
476
495
 
477
496
                strcpy(new_devname, "/dev/");
478
497
                strcat(new_devname, devname);
479
 
                free(devname);
480
498
                devname = new_devname;
481
499
        }
482
500
 
501
519
                                alarm, sys_time, rtc_time, seconds);
502
520
 
503
521
        if (strcmp(suspend, "show") && strcmp(suspend, "disable")) {
 
522
                if (strcmp(suspend, "no") && strcmp(suspend, "on") &&
 
523
                    strcmp(suspend, "off") && is_suspend_available(suspend) <= 0) {
 
524
                        errx(EXIT_FAILURE, _("suspend to \"%s\" unavailable"), suspend);
 
525
                }
 
526
 
504
527
                /* care about alarm setup only if the show|disable
505
528
                 * modes are not set
506
529
                 */