.PP
The suspend setup maybe be interrupted by active hardware; for example wireless USB
input devices that continue to send events for some fraction of a second after the
-return key is pressed. In this case is better to use sleep command before invoking
-suspend by rtcwake.
+return key is pressed.
+.BR rtcwake
+tries to avoid this problem and it waits to terminal to settle down before
+entering a system sleep.
+
.SH OPTIONS
.TP
.BR \-A , " \-\-adjfile " \fIfile
#include <fcntl.h>
#include <getopt.h>
#include <linux/rtc.h>
+#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
+#include <termios.h>
#include <time.h>
#include <unistd.h>
return NULL;
}
+static void wait_stdin(struct rtcwake_control *ctl)
+{
+ struct pollfd fd[] = {
+ {.fd = STDIN_FILENO, .events = POLLIN}
+ };
+ int tries = 0;
+
+ while (tries < 8 && poll(fd, 1, 10) == 1) {
+ if (ctl->verbose)
+ warnx(_("discarding stdin"));
+ xusleep(250000);
+ tcflush(STDIN_FILENO, TCIFLUSH);
+ tries++;
+ }
+}
+
static void suspend_system(struct rtcwake_control *ctl)
{
FILE *f = fopen(SYS_POWER_STATE_PATH, "w");
}
if (!ctl->dryrun) {
+ if (isatty(STDIN_FILENO))
+ wait_stdin(ctl);
fprintf(f, "%s\n", ctl->mode_str);
fflush(f);
}