Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What possible reasons could block a virtual terminal on Linux?

Or is it possible at all that some process or something else could block a virtual terminal? Or what could be a reason that an application hangs when trying to access the VT1?

It seems, while that is happening, it is hanging in the function ioctl. Especially, this is the code which fails:

int vtno = 1;
const char* vtname = "/dev/tty1";

int fd = open(vtname, O_RDWR|O_NDELAY, 0);

if (ioctl(fd, VT_ACTIVATE, vtno) < 0)
  printf("VT_ACTIVATE failed: %s\n", strerror(errno));

if (ioctl(fd, VT_WAITACTIVE, vtno) < 0)
  printf("VT_WAITACTIVE failed: %s\n", strerror(errno));

It hangs in the second ioctl. When I interrupt it, I get this message:

VT_WAITACTIVE failed: Interrupted system call

Also, while it is waiting there, if I do a chvt 1 from another terminal, that also hangs.

like image 648
Albert Avatar asked Sep 02 '10 12:09

Albert


1 Answers

I found out the problem. Linus Torvalds has described it firstly in a similar situation. It is actually a race condition.

The problem is as follows: If it happens that right after the first ioctl(fd, VT_ACTIVE, 1) succeeds, i.e. the system switched to the first VT, another separate process switches to another VT, the second ioctl will fail (or just wait forever, i.e. hang) because it waits that we switch to VT1 which we are not going to do any more (unless the user is doing it).


Well, that explains it to one part. It doesn't explain why the chvt 1 is hanging also.

like image 154
Albert Avatar answered Sep 21 '22 03:09

Albert