Segmentation fault in c3270 when use rest stext Connect call
3270 Terminal Emulator
Brought to you by:
pmattes
version 4.1.12 (but observed also in other versions)
call c3270 as
c3270 -httpd 0.0.0.0:7000
and try to call rest service from browser like
http://<ip-addr>:7000/3270/rest/stext/Connect(dest-ip:3270)
Result:
c3270 v4.1ga12 Mon Mar 14 19:18:30 UTC 2022 nome
Copyright 1989-2022 by Paul Mattes, GTRC and others.
Type 'show copyright' for full copyright information.
Type 'help' for help information.
c3270> Segmentation fault
The same when listening address is set to 127.0.0.1 and call locally.
Running under gdb with debuginfo points to memmove in line 196 of scroll.c
Pointer ea_save is not initialized (has NULL value).
I've set the break point in buf_init and it was not called before fault.
It seems that it is not allocated before connection, which is obviously not that case
It is done inside finsh_screen_init, after connect to the host. Maybe it should have some flag?
Last edit: nutilius 2022-03-14
I've temporary fixed it by add after line 183 in scroll.c
and closing
before end of function definition.
Great find!
It looks like this is caused by opening the connection via HTTP while c3270 is still at the c3270> prompt. There is some deferred screen initialization (including scroll_init()) that happens when the screen is first painted, and the code that processes input from the host assumes that init has been done.
Clearly that's a bug, but I can't reproduce it here easily (though I'll try with Hercules later tonight).
Could you capture a data stream trace for me? (Start c3270 with '-trace', reproduce the crash, and hopefully something useful will be in /tmp/x3trc.<pid>). Hopefully I can use that for easier reproduction here.</pid>
I have it reproduced here. Here is a quick workaround, no code changes required: Run c3270 with the -secure command-line option. This will start c3270 with a blank screen rather than at the c3270> prompt, and it will also keep you from having to hit Return to see the host screen.
Is above response related to this case or my second case about refreshing screen after Connect?
Anyway I attach trace requested by you.
Thank you for the trace, and no, I haven't been notified about a second case.
Anticipating that second issue, though -- I'm not sure how best to fix that. When c3270 is at the c3270> prompt, it's supposed to stay there. To have the screen suddenly switch to the host session without the user hitting Return might be very confusing.
A likelier fix is to add an option to explicitly start c3270 in the host session (a blank screen if no host session was specified on the command line), while still allowing ESC or Ctrl-] to break to the c3270> prompt later. The -secure command-line option has the desired first effect, but it disables the c3270> prompt altogether.
Last edit: Paul Mattes 2022-03-14
Yes, in my opinion this additional flag is good option. Anyway if you have Escape() action whic is going to command mode, maybe opposite Acion in script shoud also exists?
I have yet another problem but in this case it is about execution of macro and and show interaction with user during that (like selection). Should I descibe it as another case? Or maybe request for new feature? I would like to call macro whic givethe user some interaction, but when I call Script, the called process don't see stdin as a terminal. Probably you dont restore full curses env when execute child script process
If you run c3270 without target address, you are in command mode, but after execute Connect(), the emulator switch to 3270 mode. Why this situation cannot be the same when you call Connect from rest interface? The switch to 3270 could be done only if connection is valid, if not - command mode is still active.
Yes, this may be possible. It's just bending the user interface in some unpleasant ways.
I will think about the possible strangeness of automatically jumping into the host session on an Open(). It might not be such a big deal.
For your macro interaction question, please open a separate case.
I have a high-level suggestion here. It sounds like you are trying to automate a single invocation of c3270, including using the TTY for interaction (such as presenting a menu). Why not just run a script that presents a selection menu, then runs c3270 to connect to the selected host, in a loop?
No - I have macro which I run during opened 3270 session. It present menu with different environments (TSO, MVS, TCPIP, VTAM etc), and after selection there is second level menu with commands like
which is put on the 3270 screen and ready to edit or just to press Enter and execute. Currently I run this in tmux and macro just open second tmux pane (another terminal) and presents the selection. But I haven't always possibility to run it in tmux - so displaying in the same terminal another full screen application (curses) will be nice. Currently it cannot be done because (I've checked it) the macro process has file descriptors 1 (stdout) and 2 (stderr) redirected to the unix pipe.
My simple menu selection is done in python with ncurses library and it need standard environment for initiate the curses (calling macro shoud suspend/save curses status in c3270).
Connect() and Disconnect() executed as REST service is needed for switching the system console for sysplex when one system is going down and another must activate console. It is done by system automation request switching from ona NON-SNA session on OSA-ICC card to another NON-SNA session on another OSA-ICC.
Note that Script() was never intended to work the way you are expecting. Of all of the emulators, c3270/wc3270 are only ones running on top of an interactive terminal. In all other cases (and for those two in most cases as well), the current Script() behavior of redirecting the script output so it can be displayed in a pop-up is the right thing to do.
However, I see the utility of running an interactive script on the terminal from within c3270/wc3270, and I am working on that.
Fixed in 4.1 and 4.2.
It is invalid to open a connection remotely in c3270 when at the c3270> prompt.
An example of how to run a script that executes on the c3270 console is on the Escape() page on the Wiki:
https://x3270.miraheze.org/wiki/Escape()_action
Last edit: Paul Mattes 2022-03-20