The tty associated with a VT should be owned by the owner of the session
running on the VT. This is important for supporting a socket activated X
server, since the X server will open the tty itself.
This commit makes sure to chown the tty any time a session is
created and and chown it back to root any time the session
is removed. This behavior is copied from /bin/login.
if (vt < 0)
return;
+ r = fchown(vt, s->user->uid, -1);
+ if (r < 0)
+ goto error;
+
r = ioctl(vt, KDSKBMODE, K_OFF);
if (r < 0)
goto error;
mode.mode = VT_AUTO;
ioctl(vt, VT_SETMODE, &mode);
+ fchown(vt, 0, -1);
+
s->vtfd = safe_close(s->vtfd);
}