From b3489c3557fdca34cb6693c63be0f92909e49ecc Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 15 Sep 2016 21:38:06 -0700 Subject: [PATCH] session-helper: use proper fd with ioctl() for tty setup This was using the "from" fd from the fd_map, which will have already been closed by time we reach this portion of the child setup. Tracking the movement of FDs while resolving the remappings is rather tedious and error prone, so just locate the final fd before calling the ioctl() in child setup. --- session-helper/flatpak-session-helper.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/session-helper/flatpak-session-helper.c b/session-helper/flatpak-session-helper.c index 37868c177..702b6ba05 100644 --- a/session-helper/flatpak-session-helper.c +++ b/session-helper/flatpak-session-helper.c @@ -142,7 +142,21 @@ child_setup_func (gpointer user_data) setpgid (0, 0); if (data->set_tty) - ioctl (data->tty, TIOCSCTTY, 0); + { + /* data->tty is our from fd which is closed at this point. + * so locate the destnation fd and use it for the ioctl. + */ + for (i = 0; i < data->fd_map_len; i++) + { + if (fd_map[i].from == data->tty) + { + if (ioctl (fd_map[i].final, TIOCSCTTY, 0) == -1) + g_warning ("ioctl(%d, TIOCSCTTY, 0) failed: %s", + fd_map[i].final, strerror (errno)); + break; + } + } + } }