[PATCH] exit HyperDoc properly

6 views
Skip to first unread message

Qian Yun

unread,
Jun 1, 2024, 3:18:44 AMJun 1
to fricas-devel
This patch is to fix https://github.com/fricas/fricas/issues/170,
aka when quitting FriCAS, the HyperDoc started by ")hd" should
exit properly.

"viewman" started by ")startGraphics" can exit properly,
see src/graph/viewman/viewman.c line 188:

viewType = get_int(spadSock);
if (viewType == -1) goodbye(-1);

The key here is to detect SpadServer shutdown.
HyperDoc didn't do this check.

Another issue recently discovered by Greg is that
HyperDoc can exit only after mouse passes it.

That's because when you enter a line to FRICASsys,
a SIGUSR2 signal is sent to HyperDoc indicating "EndOfOutput".
This signal will cause system call "select" to fail.
The correct thing to do is using "sselect" to restart
this system call, instead of letting it fail silently.
(Just like what sman.c and seesion.c did.)

BTW, "$PageStuff in hypertex.boot" is recently removed,
so C function "get_new_window" can be removed as well?

- Qian

diff --git a/src/hyper/event.c b/src/hyper/event.c
index a0f0c058..2300a07e 100644
--- a/src/hyper/event.c
+++ b/src/hyper/event.c
@@ -114,7 +114,11 @@ mainEventLoop(void)
handle_event(&event);
}
else {
- select(FD_SETSIZE,(void *)&rd,(void *)&dum1,(void
*)&dum2,NULL);
+ int ret_val = sselect(FD_SETSIZE, &rd, &dum1, &dum2, NULL);
+ if (ret_val == -1) {
+ exitHyperDoc();
+ exit(1);
+ }
if (FD_ISSET(Xcon, &rd) ||
XEventsQueued(gXDisplay, QueuedAfterFlush)) {
XNextEvent(gXDisplay, &event);
@@ -127,10 +131,14 @@ mainEventLoop(void)
* $PageStuff in hypertex.boot
*/
{
- if (100 == get_int(spad_socket)) {
+ int cmd = get_int(spad_socket);
+ if (100 == cmd) {
set_window(gParentWindow->fMainWindow);
make_busy_cursors();
get_new_window();
+ } else if (-1 == cmd) {
+ exitHyperDoc();
+ exit(0);
}
}
/*

Waldek Hebisch

unread,
Jun 1, 2024, 1:34:02 PMJun 1
to fricas...@googlegroups.com
On Sat, Jun 01, 2024 at 03:18:37PM +0800, Qian Yun wrote:
> This patch is to fix https://github.com/fricas/fricas/issues/170,
> aka when quitting FriCAS, the HyperDoc started by ")hd" should
> exit properly.
>
> "viewman" started by ")startGraphics" can exit properly,
> see src/graph/viewman/viewman.c line 188:
>
> viewType = get_int(spadSock);
> if (viewType == -1) goodbye(-1);
>
> The key here is to detect SpadServer shutdown.
> HyperDoc didn't do this check.
>
> Another issue recently discovered by Greg is that
> HyperDoc can exit only after mouse passes it.
>
> That's because when you enter a line to FRICASsys,
> a SIGUSR2 signal is sent to HyperDoc indicating "EndOfOutput".
> This signal will cause system call "select" to fail.
> The correct thing to do is using "sselect" to restart
> this system call, instead of letting it fail silently.
> (Just like what sman.c and seesion.c did.)

Seem to work OK.

> BTW, "$PageStuff in hypertex.boot" is recently removed,
> so C function "get_new_window" can be removed as well?

Well, there are several commands in HyperDoc protocol that are
currently unused. Some may be obsolte now, bit most were meant
to be used from Spad code. I started rewrite of Hyperdoc part
in FRICASsys in Spad (currently I have version where about 10%
of code is in Spad and 90% in Boot). In the process I removed
some unused code including '$PageStuff'.

--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages