mailing-list for TeXmacs Users

Text archives Help


Re: [TeXmacs] Is SIGINT sent to plugins ?


Chronological Thread 
  • From: Nicola Mingotti <address@hidden>
  • To: Massimiliano Gubinelli <address@hidden>
  • Cc: texmacs-users <address@hidden>, Nicola Mingotti <address@hidden>
  • Subject: Re: [TeXmacs] Is SIGINT sent to plugins ?
  • Date: Wed, 16 Jan 2019 11:33:19 -0800


Hello Max !

So, the most difficult part was for me to discover how to recompile efficiently the FreeBSD port.
https://forums.freebsd.org/threads/how-to-tweak-the-source-of-an-existing-port.69164/#post-413749

Trying to get the result i was bit messy, sorry about that.

I left there the ::killpg because i had no idea if it had any side effect,
besides throwing a signal (which is wrong: negative).
I added the standard "kill", instead of the "::kill" because I was more
confident it was doing what i wanted, since i don't control Qt.

Anyhow, today i used your code in the patch and it all seems to work :)
The patch I attach contains your lines more a STDOUT message.

I left the message in STDOUT because it is important to know the signal
is sent. It is the plugins that at times do not detect it AFAIK-say.
(eg. Python plugin does not get SIGINT, R plugin does)

Bye
nicola

==== Patching procedure for the FreeBSD port : editors/texmacs ======================
==== tested in FreeBSD-11.2

1] It is supposed you installed the port system

2] Remove TeXmacs package, if you have it installed via package
#> pkg remove texmacsXXX

3] Get the source, clean if necessary
$> cd /usr/ports/editors/texmacs
# if necessary
$> sudo make deinstall
$> sudo make clean
$> sudo make fetch

4] Put the patch file (attached to this mail) into
/usr/ports/editors/texmacs/files/patch-src_Plugins_Qt_qt__pipe__link.cpp

5] patch the source and compile
# in config i keep checked all options
$> sudo make config
$> sudo make patch
$> sudo make build

6] check that it is working
$> cd /usr/ports/editors/texmacs/work/TeXmacs-1.99.4-src/TeXmacs
$> export TEXMACS_PATH=`pwd`
$> cd bin
$> ./texmacs
# now install Max test plugin and and restart TeXmacs
# test that that "interrupt" is resetting the counter !
# not only that there is written "Interrupted"
# You should see a message in STDOUT sayin the singnal has beeen sent.

7] install the software
$> cd /usr/ports/editors/texmacs
$> sudo make install

=========================================================










On 1/16/19 12:32 AM, Massimiliano Gubinelli wrote:
Dear Nicola,
I do not understand the patch. You need to send *two* kill (first
::killpg() and then killI()) to the same pid? or is putting the pid in the
local variable that makes things works?

Is not clear to me what is going on.

Best
Max



On 16. Jan 2019, at 01:21, Nicola Mingotti <address@hidden> wrote:


I was able to fix it !

After patching, my Ruby plugin and Max test plugin both work.

Without the patch my plugin does not get the SIGINT and Max plugin
does not reset the counter.

The working patch for TeXmacs 1.99.4 (tested valid for FreeBSD 11.2) is :

-----------------------
--- src/Plugins/Qt/qt_pipe_link.cpp.orig 2019-01-15 23:10:27 UTC
+++ src/Plugins/Qt/qt_pipe_link.cpp
@@ -9,6 +9,9 @@
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.

******************************************************************************/

+// for my debug
+#include<iostream>
+
#include "basic.hpp"

#if defined (QTTEXMACS) && (defined (__MINGW__) || defined (__MINGW32__) ||
defined (QTPIPES))
@@ -144,8 +147,15 @@ qt_pipe_link_rep::interrupt () {
if (!alive) return;
#if defined(__MINGW__) || defined(__MINGW32__)
// Not implemented
-#else
+#else
::killpg(PipeLink.pid (), SIGINT);
+
+ // for some reason the prevoius "kill" kills
+ // (-1)*myPid.
+ int myPid = PipeLink.pid();
+ cout << "DBG> signal SIGINT on pid: " << myPid << "\n";
+ kill(myPid, SIGINT);
+
#endif
}
-----------------------

bye
Nicola




On 1/15/19 12:35 PM, Nicola Mingotti wrote:
Please don't put much wait on what i wrote,
I may have made a mistake in recompiling the FreeBSD port
which messed all the thing up.

The negative PID is there, but my changes to the code may
have not be taken at all in subsequent tests ... i am checking and
trying to understand.

I will let you know ASAP.

sorry
bye
n.

On 1/14/19 5:39 PM, Nicola Mingotti wrote:
Hello Max,

I have had finally time to do further experiments.

I tried your test plugin, in my system (FreeBSD 11.2, Texmacs v. 1.99.4 from
ports) it works
with and without your patch. Quite misteriously i must say.

My plugin instead keeps on not working and not receiving SIGINT.

I start to doubt i have a bug in my code somewhere, but it is wired,
if I run my plugin on the console it behaves well on Ctrl-C !

I have discovered something that is interesting.

If I run:
$> truss ./texmacs -x '(make-session "ruby" "default")' 2>&1 | grep '^kill'

I get this stuff :
kill(-59846,SIGINT) # ERR3, no such process

... i have never seen a negative pid in life.

I tried to change TeXmacs code you modified many times, but it seems the damn
negative
pid not going to change, whatever i do, eg :
---
Q_PID pid = PipeLink.pid ();
int ret = ::kill(-pid, SIGINT);
---

A different but still negative pid appears to be sent to your plugin,
but, for some reason, your plugin gets the SIGINT.

I am extremely puzzled,
do you have any idea ?

bye
n.


On 12/12/18 8:56 AM, Massimiliano Gubinelli wrote:
Hi again,

On 11. Dec 2018, at 20:11, Nicola Mingotti <address@hidden> wrote:

Hi again,

I am puzzled, I am trying to get the SIGINT from my plugin
but it seems to me TeXmacs is not sending that signal.

Seems there is a bug with the signals. I attach a patch and a test program
(which has to be installed as a plugin).

I will commit a patch in svn.

Best
Max


-----------------------------------------------------------------------
The patch
-8<---------------------------------------------------------------------
Index: src/Plugins/Qt/qt_pipe_link.cpp
===================================================================
--- src/Plugins/Qt/qt_pipe_link.cpp (revision 11316)
+++ src/Plugins/Qt/qt_pipe_link.cpp (working copy)
@@ -148,7 +148,11 @@
qt_error << "SIGINT not implemented on Windows\n";
#else
Q_PID pid = PipeLink.pid ();
- int ret = ::killpg (pid, SIGINT);
+
+ // REMARK: previously there were here below a call to ::killpg which does
not seems to work on MacOS
+ // I (mgubi) replaced it with ::kill which does the job. But I do not
undestand the difference.
+
+ int ret = ::kill (pid, SIGINT);
if (ret == -1) {
qt_error << "Interrupt not successful, pid: " << pid << " return code: " << errno
<< "\n";
}
-8<--------------------------------------------------------------------
The test program
-8<--------------------------------------------------------------------
#include <iostream>
#include <unistd.h>
#include <csignal>

using namespace std;

#define DATA_BEGIN ((char) 2)
#define DATA_END ((char) 5)
#define DATA_ESCAPE ((char) 27)

bool trig = true;
int cc = 0;

void signalHandler( int signum ) {
trig = false;
}

int
main () {
cout << DATA_BEGIN << "verbatim:";
cout << "STARTING\n";
cout << DATA_END;
cout.flush ();

// register signal SIGINT and signal handler
signal(SIGINT, signalHandler);

while (1) {
char buffer[100];
cin.getline (buffer, 100, '\n');
cout << DATA_BEGIN << "verbatim:";
cout << "Input: " << buffer << "\n";
cout.flush ();

while (trig) {
cout << "Going to sleep.... (" << cc ++ << ")\n";
cout.flush ();
sleep (1);
}
cout << DATA_END;
cout.flush ();
trig = true; cc = 0;
}
return 0;
}
-8<--------------------------------------------------------------------


I am using TeXmacs version 1.99.4 in FreeBSD.

Do you know of any plugin who is actually managing SIGINT correctly ?
I tried Python (not working, not implemented IFACSay), Scheme (no button),
Maxima (not working).

I test the SIGINT is not working in this way, for Python i can actually
check there is not signal receiver in the code, so, not a TeXmacs problem,
but the method I use in general is:

1] Run a sleep command, 10 seconds
2] Press the STOP button in TeXmacs
3] Run a simple arithmentic command e.g. 1+1

=== Pyjhon ===
import time
timp.sleep(10)
PRESS QUIT
1+1
HANGS till end of sleep
=============

==== Maxima ====
:lisp (sleep 10)
PRESS QUIT
1
HANGS till end of sleep
================

Maybe also Maxima plugin is not catching the SIGINT...
In my plugin managed to receive the signal but I don't see it coming when i
press the STOP button.

Do you know something about it ?

bye
Nicola




--- src/Plugins/Qt/qt_pipe_link.cpp.orig	2015-03-05 16:34:14 UTC
+++ src/Plugins/Qt/qt_pipe_link.cpp
@@ -9,6 +9,9 @@
 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
 ******************************************************************************/
 
+// for my debug
+#include<iostream>
+
 #include "basic.hpp"
 
 #if defined (QTTEXMACS) && (defined (__MINGW__) || defined (__MINGW32__) || defined (QTPIPES))
@@ -145,7 +148,19 @@ qt_pipe_link_rep::interrupt () {
 #if defined(__MINGW__) || defined(__MINGW32__)
   // Not implemented
 #else
-  ::killpg(PipeLink.pid (), SIGINT);
+  
+  // ::killpg(PipeLink.pid (), SIGINT);
+  
+  // for some reason the prevoius "kill" kills
+  // (-1)*myPid ! 
+  
+  Q_PID pid = PipeLink.pid();
+  cout << "DBG> signal SIGINT on pid: " << pid << "\n";  
+  int ret = ::kill(pid, SIGINT);
+  if (ret == -1) {
+     qt_error << "Interrupt not successful, pid: " << pid << " return code: " << errno << "\n";
+  }
+
 #endif
 }
 



Archive powered by MHonArc 2.6.19.

Top of page