[RTEMS Project] #3859: No output from joel scripts in telnet

RTEMS trac trac at rtems.org
Sat Aug 8 07:45:29 UTC 2020


#3859: No output from joel scripts in telnet
-------------------------+--------------------------
 Reporter:  Chris Johns  |       Owner:  Chris Johns
     Type:  defect       |      Status:  reopened
 Priority:  normal       |   Milestone:  5.1
Component:  shell        |     Version:  5
 Severity:  blocker      |  Resolution:
 Keywords:               |  Blocked By:
 Blocking:               |
-------------------------+--------------------------

Comment (by Chris Johns):

 I have looked into the issue and the reuse of the `telnetd` session thread
 is clashing with the way the shell's environment is currently being
 cleaned up. The `telnetd` software creates a number of sessions and it
 reuses these sessions for the incoming connections. This means the `pty`
 file handles assigned to each session are reused. Clearing these file
 handles corrupts the `telnetd` session.

 Setting of `stdin`, `stdout` and also `stderr` to `NULL` when cleaning up
 a shell environment is important because thread termination closes those
 files if present and open and if the file pointers have been inherited
 from the parent thread the parent can be left without a valid `stdin`,
 `stdout` and `stderr`. This happens with a `joel` script. It could also
 happen with a command that is placed in the background (if we supported
 this) or a command that dispatches a worker thread.

 This ticket was originally about a bug where `joel` script output was not
 redirected to the parent thread's stdout. They happened to work for the
 console because the console shell's standard handles are the global ones.
 A new thread inherits the global handles and the clean up also manages the
 closing of those, or the lack of it. However a `joel` script with telnet
 was broken.

 The solution is to move the setting of `stdin`, `stdout` and `stderr` out
 of clearing the environment and to only do this when the
 `rtems_shell_task` exits the `rtems_shell_main_loop`.

 For the record a debug trace from `shell.c` running a `joel` script is:
 {{{
 shell[0a010001]: run: env: 0x62accd0
 shell[0a010001]: run out: 1 (0xbeb028)
 shell[0a010001]: run  in: 0 (0xbeafa8)
 shell[0a01001c]: env: 0x62accd0
 shell[0a01001c]: child out: 1 (0xbeb028)
 shell[0a01001c]: child  in: 0 (0xbeafa8)
 shell[0a010017]: dup: global: copy: 0x2f5d1b8 out: 166 (0x2f02738) in: 165
 (0x2f026b8)
 shell[0a010017]: env: 0x2f5d1b8
 shell[0a010017]: child out: 166 (0x2f02738)
 shell[0a010017]: child  in: 165 (0x2f026b8)
 shell[0a010017]: script: in: /j out: stdout
 shell[0a010017]: run: env: 0x63558a8
 shell[0a010017]: run out: 166 (0x2f02738)
 shell[0a010017]: run  in: 165 (0x2f026b8)
 shell[0a01001d]: env: 0x63558a8
 shell[0a01001d]: child out: 166 (0x2f02738)
 shell[0a01001d]: child  in: 35 (0x629b260)
 shell[0a01001d]: end: 0 0
 shell[0a01001d]: child in-to-close: 0x629b260
 shell[0a01001d]: child out-to-close: 0
 shell[0a010017]: run: end: sc:0 ec:0
 shell[0a010017]: script: end: 0
 shell[0a010017]: end: 0 0
 shell[0a010017]: child in-to-close: 0
 shell[0a010017]: child out-to-close: 0
 }}}

--
Ticket URL: <http://devel.rtems.org/ticket/3859#comment:32>
RTEMS Project <http://www.rtems.org/>
RTEMS Project


More information about the bugs mailing list