Skip to content

Commit 91b47d0

Browse files
authored
Merge pull request #4724 from mirabilos/master
subshell: reorder pty/pipe file descriptor acquisition
2 parents 6c4e687 + 421f652 commit 91b47d0

File tree

1 file changed

+35
-31
lines changed

1 file changed

+35
-31
lines changed

src/subshell/common.c

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,37 +1556,6 @@ init_subshell (void)
15561556
if (mc_global.shell->type == SHELL_NONE)
15571557
return;
15581558

1559-
// Open a pty for talking to the subshell
1560-
1561-
// FIXME: We may need to open a fresh pty each time on SVR4
1562-
1563-
#ifdef HAVE_OPENPTY
1564-
if (openpty (&mc_global.tty.subshell_pty, &subshell_pty_slave, NULL, NULL, NULL))
1565-
{
1566-
fprintf (stderr, "Cannot open master and slave sides of pty: %s\n",
1567-
unix_error_string (errno));
1568-
mc_global.tty.use_subshell = FALSE;
1569-
return;
1570-
}
1571-
#else
1572-
mc_global.tty.subshell_pty = pty_open_master (pty_name);
1573-
if (mc_global.tty.subshell_pty == -1)
1574-
{
1575-
fprintf (stderr, "Cannot open master side of pty: %s\r\n", unix_error_string (errno));
1576-
mc_global.tty.use_subshell = FALSE;
1577-
return;
1578-
}
1579-
1580-
subshell_pty_slave = pty_open_slave (pty_name);
1581-
if (subshell_pty_slave == -1)
1582-
{
1583-
fprintf (stderr, "Cannot open slave side of pty %s: %s\r\n", pty_name,
1584-
unix_error_string (errno));
1585-
mc_global.tty.use_subshell = FALSE;
1586-
return;
1587-
}
1588-
#endif
1589-
15901559
// Create a pipe for receiving the subshell's CWD
15911560

15921561
if (mc_global.shell->type == SHELL_TCSH)
@@ -1629,6 +1598,41 @@ init_subshell (void)
16291598
mc_global.tty.use_subshell = FALSE;
16301599
return;
16311600
}
1601+
1602+
// Open a pty for talking to the subshell; do this after
1603+
// acquiring the pipes, so the latter have a higher chance
1604+
// of getting a number lower than 10 so the "pwd >&%d" in
1605+
// the mc-injected precmd does not cause a syntax error, a
1606+
// ten-second sleep at startup, and other problems.
1607+
1608+
// FIXME: We may need to open a fresh pty each time on SVR4
1609+
1610+
#ifdef HAVE_OPENPTY
1611+
if (openpty (&mc_global.tty.subshell_pty, &subshell_pty_slave, NULL, NULL, NULL))
1612+
{
1613+
fprintf (stderr, "Cannot open master and slave sides of pty: %s\n",
1614+
unix_error_string (errno));
1615+
mc_global.tty.use_subshell = FALSE;
1616+
return;
1617+
}
1618+
#else
1619+
mc_global.tty.subshell_pty = pty_open_master (pty_name);
1620+
if (mc_global.tty.subshell_pty == -1)
1621+
{
1622+
fprintf (stderr, "Cannot open master side of pty: %s\r\n", unix_error_string (errno));
1623+
mc_global.tty.use_subshell = FALSE;
1624+
return;
1625+
}
1626+
1627+
subshell_pty_slave = pty_open_slave (pty_name);
1628+
if (subshell_pty_slave == -1)
1629+
{
1630+
fprintf (stderr, "Cannot open slave side of pty %s: %s\r\n", pty_name,
1631+
unix_error_string (errno));
1632+
mc_global.tty.use_subshell = FALSE;
1633+
return;
1634+
}
1635+
#endif
16321636
}
16331637

16341638
// Fork the subshell

0 commit comments

Comments
 (0)