Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/util-linux/rtcwake.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/util-linux/rtcwake.c
r3232 r3621 33 33 //usage: "\n -u,--utc Clock is set to UTC time" 34 34 //usage: "\n -d,--device=DEV Specify the RTC device" 35 //usage: "\n -m,--mode=MODE Set thesleep state (default: standby)"36 //usage: "\n -s,--seconds=SEC Set t he timeout in SEC seconds from now"37 //usage: "\n -t,--time=TIME Set t he timeout to TIME seconds from epoch"35 //usage: "\n -m,--mode=MODE Set sleep state (default: standby)" 36 //usage: "\n -s,--seconds=SEC Set timeout in SEC seconds from now" 37 //usage: "\n -t,--time=TIME Set timeout to TIME seconds from epoch" 38 38 //usage: ) 39 39 //usage: IF_NOT_LONG_OPTS( … … 42 42 //usage: "\n -u Clock is set to UTC time" 43 43 //usage: "\n -d DEV Specify the RTC device" 44 //usage: "\n -m MODE Set thesleep state (default: standby)"45 //usage: "\n -s SEC Set t he timeout in SEC seconds from now"46 //usage: "\n -t TIME Set t he timeout to TIME seconds from epoch"44 //usage: "\n -m MODE Set sleep state (default: standby)" 45 //usage: "\n -s SEC Set timeout in SEC seconds from now" 46 //usage: "\n -t TIME Set timeout to TIME seconds from epoch" 47 47 //usage: ) 48 48 … … 52 52 #define SYS_RTC_PATH "/sys/class/rtc/%s/device/power/wakeup" 53 53 #define SYS_POWER_PATH "/sys/power/state" 54 #define DEFAULT_MODE "standby"55 54 56 55 static NOINLINE bool may_wakeup(const char *rtcname) … … 68 67 69 68 /* wakeup events could be disabled or not supported */ 70 return strncmp(buf, "enabled\n", 8) == 0;69 return is_prefixed_with(buf, "enabled\n") != NULL; 71 70 } 72 71 … … 123 122 int rtcwake_main(int argc UNUSED_PARAM, char **argv) 124 123 { 125 time_t rtc_time;126 127 124 unsigned opt; 128 125 const char *rtcname = NULL; 129 const char *suspend ;126 const char *suspend = "standby"; 130 127 const char *opt_seconds; 131 128 const char *opt_time; 132 129 130 time_t rtc_time; 133 131 time_t sys_time; 134 time_t alarm_time = 0;135 unsigned seconds = 0;132 time_t alarm_time = alarm_time; 133 unsigned seconds = seconds; /* for compiler */ 136 134 int utc = -1; 137 135 int fd; … … 149 147 applet_long_options = rtcwake_longopts; 150 148 #endif 149 /* Must have -s or -t, exclusive */ 150 opt_complementary = "s:t:s--t:t--s"; 151 151 opt = getopt32(argv, "alud:m:s:t:", &rtcname, &suspend, &opt_seconds, &opt_time); 152 152 … … 157 157 if (opt & (RTCWAKE_OPT_UTC | RTCWAKE_OPT_LOCAL)) 158 158 utc = opt & RTCWAKE_OPT_UTC; 159 if (!(opt & RTCWAKE_OPT_SUSPEND_MODE)) 160 suspend = DEFAULT_MODE; 161 if (opt & RTCWAKE_OPT_SECONDS) 159 if (opt & RTCWAKE_OPT_SECONDS) { 162 160 /* alarm time, seconds-to-sleep (relative) */ 163 seconds = xatoi(opt_seconds); 164 if (opt & RTCWAKE_OPT_TIME) 161 seconds = xatou(opt_seconds); 162 } else { 163 /* RTCWAKE_OPT_TIME */ 165 164 /* alarm time, time_t (absolute, seconds since 1/1 1970 UTC) */ 166 alarm_time = xatol(opt_time); 167 168 if (!alarm_time && !seconds) 169 bb_error_msg_and_die("must provide wake time"); 165 if (sizeof(alarm_time) <= sizeof(long)) 166 alarm_time = xatol(opt_time); 167 else 168 alarm_time = xatoll(opt_time); 169 } 170 170 171 171 if (utc == -1) … … 178 178 fd = rtc_xopen(&rtcname, O_RDONLY); 179 179 180 if (strcmp(suspend, "on") && !may_wakeup(rtcname)) 181 bb_error_msg_and_die("%s not enabled for wakeup events", rtcname); 180 if (strcmp(suspend, "on") != 0) 181 if (!may_wakeup(rtcname)) 182 bb_error_msg_and_die("%s not enabled for wakeup events", rtcname); 182 183 183 184 /* relative or absolute alarm time, normalized to time_t */ … … 189 190 } 190 191 191 192 if (alarm_time) { 193 if (alarm_time < sys_time) 192 if (opt & RTCWAKE_OPT_TIME) { 193 /* Correct for RTC<->system clock difference */ 194 alarm_time += rtc_time - sys_time; 195 if (alarm_time < rtc_time) 196 /* 197 * Compat message text. 198 * I'd say "RTC time is already ahead of ..." instead. 199 */ 194 200 bb_error_msg_and_die("time doesn't go backward to %s", ctime(&alarm_time)); 195 alarm_time += sys_time - rtc_time;196 201 } else 197 202 alarm_time = rtc_time + seconds + 1; 203 198 204 setup_alarm(fd, &alarm_time, rtc_time); 199 200 205 sync(); 206 #if 0 /*debug*/ 207 printf("sys_time: %s", ctime(&sys_time)); 208 printf("rtc_time: %s", ctime(&rtc_time)); 209 #endif 201 210 printf("wakeup from \"%s\" at %s", suspend, ctime(&alarm_time)); 202 211 fflush_all(); 203 212 usleep(10 * 1000); 204 213 205 if (strcmp(suspend, "on") )214 if (strcmp(suspend, "on") != 0) 206 215 xopen_xwrite_close(SYS_POWER_PATH, suspend); 207 216 else {
Note:
See TracChangeset
for help on using the changeset viewer.