bug-prolog
[Top][All Lists]
Advanced

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

previous termination handler not reinstalled when exiting break/0 ?


From: Erick Alphonse
Subject: previous termination handler not reinstalled when exiting break/0 ?
Date: Sat, 27 Mar 2004 11:07:32 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040115

Hello,

I redefined the ctrl-c handler in the C code to be able to call break/0 from C. When I exit break/0, I cannot reenter the handler. Apparently break/0 does not reinstall the previous ctrl-c handler when exiting. I used gprolog-20040317.tgz.

Please, let me know if I have done something wrong.

Regards,
Erick.

Here are handler.pl and handler_c.c. the trace is given below.

handler.pl

:- foreign(c_loop,[return(none)]).

:- initialization(c_loop).

handler_c.c

#include <signal.h>
#include "gprolog.h"

void termination_handler(int signum) {
  printf("handler\n");

  Pl_Query_Begin(FALSE);
  Pl_Query_Call(Find_Atom("break"),0,NULL);
  Pl_Query_End(PL_KEEP_FOR_PROLOG);
}

void c_loop() {
  struct sigaction new_action;
  struct sigaction old_action;

  new_action.sa_handler = termination_handler;
  sigemptyset(&new_action.sa_mask);
  new_action.sa_flags = SA_RESTART;

  sigaction(SIGINT,NULL,&old_action);
  sigaction(SIGINT,&new_action,NULL);

  for(;;);
}

########

trace

614# uname -a
Linux rantanplan 2.4.22-26mdk #1 Wed Jan 7 10:47:21 MST 2004 i686 unknown unknown GNU/Linux
615# gprolog --version
Prolog top-Level (GNU Prolog) 1.2.18
By Daniel Diaz
Copyright (C) 1999-2004 Daniel Diaz
GNU Prolog comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Prolog
under the terms of the GNU General Public License.
For more information about these matters, see the files named COPYING.
616# gplc handler.pl handler_c.c
617# ./handler
% in C code, CTRL-C pressed
handler
| ?- % CTRL-D pressed

% in C code, CTRL-C pressed
Prolog interruption (h for help) ? e
618#



And a maybe strange behaviour

618# ./handler
% in C code, CTRL-C pressed
handler
| ?- | ?- % CTRL-C pressed again, then CTRL-D


Prolog interruption (h for help) ? e




reply via email to

[Prev in Thread] Current Thread [Next in Thread]