Some comments about init_subshell()



Hello!

GCC emits a warning about pty_slave variable possible used uninitialized
in init_subshell(). I was trying to fix it and found what appears to be a
real bug.

Actually, pty_slave is used in two processes. If init_subshell() is called
the first time (yes, it can be called more than once, see below) then
pty_slave is assigned a value in the parent process. Then fork() is
called. Then the child changes the value of pty_slave and does something
with is while the parent calls close(pty_slave).

Since the processes have separate data, the child's pty_slave is a
separate variable. In fact, the child initialization can and should be
made a separate function.

But init_subshell() can be called more than once. If the subshell dies,
then mc is supposed to restart it. In this case, some parts of the
initialization process are skipped and pty_slave is not assigned a certain
value.

After that close(pty_slave) becomes russian roulette. It closes a random
file descriptor. This should be fixed, but there is one problem. I cannot
get subshell recovery to work at all.

Pressing Ctrl-O after killing the subshell with -KILL causes
init_subshell() to be rerun. Dependent on random factors (I think it's a
race between read() in feed_subshell() and sigchld_handler() unsetting
subshell_alive), mc would either decide that the subshell has died
instantly and disable it, or it would exit with the message

subshell.c: read (subshell_pty...): Input/output error

I'm going to fix what I can, but please note that subshell recovery was
broken before me. Any help would be appreciated.

bash-2.04, RedHat 7.0, Linux-2.4.4-ac9, using unix-98 ptys on devfs
(devpts not mounted).

-- 
Regards,
Pavel Roskin





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]