chiark / gitweb /
login: give session ownership of VT
authorRay Strode <rstrode@redhat.com>
Tue, 22 Apr 2014 17:27:58 +0000 (13:27 -0400)
committerDavid Herrmann <dh.herrmann@gmail.com>
Wed, 23 Apr 2014 15:36:43 +0000 (17:36 +0200)
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.

src/login/logind-session.c

index b4fd349f00cb7e4468d44227c18197adfee641d3..83c0ffa65c2abad777b9493435aeca07e78c2b1f 100644 (file)
@@ -972,6 +972,10 @@ void session_mute_vt(Session *s) {
         if (vt < 0)
                 return;
 
         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;
         r = ioctl(vt, KDSKBMODE, K_OFF);
         if (r < 0)
                 goto error;
@@ -1026,6 +1030,8 @@ void session_restore_vt(Session *s) {
         mode.mode = VT_AUTO;
         ioctl(vt, VT_SETMODE, &mode);
 
         mode.mode = VT_AUTO;
         ioctl(vt, VT_SETMODE, &mode);
 
+        fchown(vt, 0, -1);
+
         s->vtfd = safe_close(s->vtfd);
 }
 
         s->vtfd = safe_close(s->vtfd);
 }