Skip to content
This repository has been archived by the owner on Sep 23, 2021. It is now read-only.

Commit

Permalink
Retry VT_WAITACTIVE ioctl if interrupted
Browse files Browse the repository at this point in the history
My personal use-case that triggers the problem:
physlock is launched by the XFCE Power Manager daemon when the system is
suspended. What happens is that, sometimes, the WAITACTIVE ioctl is
issued just before the system goes to sleep. When the system resumes,
the ioctl returns with errno=EINTR (aka interrupted system call),
therefore physlock exits.

Retrying the ioctl is enough to solve the problem.
  • Loading branch information
elboulangero authored and xyb3rt committed Jul 15, 2015
1 parent 2abc722 commit 14d6190
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions vt.c
Expand Up @@ -63,6 +63,8 @@ void get_current_vt(int *nr) {
}

void acquire_new_vt(vt_t *vt) {
int ret;

vt->nr = -1;
vt->ios = NULL;
vt->fd = -1;
Expand All @@ -78,9 +80,11 @@ void acquire_new_vt(vt_t *vt) {
die("could not open %s: %s", filename, strerror(errno));
vt->fd = fileno(vt->ios);

if (ioctl(fd, VT_ACTIVATE, vt->nr) == -1 ||
ioctl(fd, VT_WAITACTIVE, vt->nr) == -1)
if (ioctl(fd, VT_ACTIVATE, vt->nr) == -1)
die("could not activate console # %d: %s", vt->nr, strerror(errno));
while ((ret = ioctl(fd, VT_WAITACTIVE, vt->nr)) == -1 && errno == EINTR);
if (ret == -1)
die("could not wait for console # %d: %s", vt->nr, strerror(errno));

tcgetattr(vt->fd, &vt->term);
vt->rlflag = vt->term.c_lflag;
Expand All @@ -97,13 +101,18 @@ void reopen_vt(vt_t *vt) {
}

void release_vt(vt_t *vt, int nr) {
int ret;

if (fd < 0)
die("release_vt() called without vt_init()");
if (nr <= 0)
die("release_vt() called with invalid argument");
if (ioctl(fd, VT_ACTIVATE, nr) == -1 ||
ioctl(fd, VT_WAITACTIVE, nr) == -1)

if (ioctl(fd, VT_ACTIVATE, nr) == -1)
die("could not activate console # %d: %s", nr, strerror(errno));
while ((ret = ioctl(fd, VT_WAITACTIVE, nr)) == -1 && errno == EINTR);
if (ret == -1)
die("could not wait for console # %d: %s", nr, strerror(errno));

if (vt->ios != NULL) {
fclose(vt->ios);
Expand Down

0 comments on commit 14d6190

Please sign in to comment.