]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind: get a fresh file descriptor to clean up a VT 990/head
authorOwen W. Taylor <otaylor@fishsoup.net>
Tue, 18 Aug 2015 19:19:05 +0000 (15:19 -0400)
committerOwen W. Taylor <otaylor@fishsoup.net>
Tue, 18 Aug 2015 19:26:11 +0000 (15:26 -0400)
When the controlling process exits, any existing file descriptors
for that FD will be marked as hung-up and ioctls on them will
file with EIO. To work around this, open a new file descriptor
for the VT we want to clean up.

Thanks to Ray Strode for help in sorting out the problem and
coming up with a fix!

https://github.com/systemd/systemd/issues/989

src/login/logind-session.c

index 902abe0e42de43f7822789a656830509d46828dd..92a6027a7ef4a085f21ca90c5a60f13823b2d68a 100644 (file)
@@ -1050,7 +1050,18 @@ void session_restore_vt(Session *s) {
         int vt, kb = K_XLATE;
         struct vt_mode mode = { 0 };
 
+        /* We need to get a fresh handle to the virtual terminal,
+         * since the old file-descriptor is potentially in a hung-up
+         * state after the controlling process exited; we do a
+         * little dance to avoid having the terminal be available
+         * for reuse before we've cleaned it up.
+         */
+        int old_fd = s->vtfd;
+        s->vtfd = -1;
+
         vt = session_open_vt(s);
+        safe_close(old_fd);
+
         if (vt < 0)
                 return;