Skip to content

Commit c3b717e

Browse files
committed
force termination after 5 interrupt signals
1 parent d0e5e73 commit c3b717e

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

src/Apps/AmplSolver/AmplTNLP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void AmplTNLP::gutsOfConstructor(
170170
}
171171
}
172172

173-
if( checkinterrupt_ && !RegisterInterruptHandler(NULL, &interrupted_) )
173+
if( checkinterrupt_ && !RegisterInterruptHandler(NULL, &interrupted_, 5) )
174174
{
175175
jnlst_->Printf(J_STRONGWARNING, J_MAIN, "Could not register handler for interrupt signals.\n");
176176
}

src/Common/IpUtils.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ Number WallclockTime()
194194
}
195195

196196
static bool registered_handler = false;
197+
static unsigned int abortcountdown_ = std::numeric_limits<unsigned int>::max();
197198
static void (*handle_interrupt_)(void) = NULL;
198199
static bool* interrupt_flag_ = NULL;
199200

@@ -210,26 +211,26 @@ static void sighandler(
210211
{
211212
(*handle_interrupt_)();
212213
}
214+
215+
if( --abortcountdown_ == 0 )
216+
{
217+
fputs("Ipopt sighandler: Too many interrupt signals. Forcing termination.\n", stderr);
218+
exit(1);
219+
}
213220
}
214221

215-
/** register handler for interrupt signals
216-
*
217-
* On POSIX systems, catches SIGHUP and SIGINT signals.
218-
* On Windows, catches SIGTERM, SIGABRT, SIGBREAK, and SIGINT signals.
219-
*
220-
* @return whether registering the handler was successful
221-
* @since 3.14.17
222-
*/
223222
bool RegisterInterruptHandler(
224-
void (*handle_interrupt)(void), /**< function to call when interrupted by signal, if not NULL */
225-
bool* interrupt_flag /**< variable to set to true when interrupted by signal, if not NULL */
223+
void (*handle_interrupt)(void),
224+
bool* interrupt_flag,
225+
unsigned int abortlimit
226226
)
227227
{
228228
if( registered_handler )
229229
{
230230
return false;
231231
}
232232
registered_handler = true;
233+
abortcountdown_ = abortlimit;
233234

234235
handle_interrupt_ = handle_interrupt;
235236
interrupt_flag_ = interrupt_flag;
@@ -260,11 +261,6 @@ bool RegisterInterruptHandler(
260261
return true;
261262
}
262263

263-
/** unregister previously registered handler for interrupt signals
264-
*
265-
* @return whether registering the handler was successful
266-
* @since 3.14.17
267-
*/
268264
bool UnregisterInterruptHandler(void)
269265
{
270266
if( !registered_handler )

src/Common/IpUtils.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ IPOPTLIB_EXPORT Number WallclockTime();
109109
* @since 3.14.17
110110
*/
111111
IPOPTLIB_EXPORT bool RegisterInterruptHandler(
112-
void (*handle_interrupt)(void), /**< function to call when interrupted by signal, if not NULL */
113-
bool* interrupt_flag /**< variable to set to true when interrupted by signal, if not NULL */
112+
void (*handle_interrupt)(void), /**< function to call when interrupted by signal, if not NULL */
113+
bool* interrupt_flag, /**< variable to set to true when interrupted by signal, if not NULL */
114+
unsigned int abortlimit = std::numeric_limits<unsigned int>::max() /**< if interrupt signal has been send this many times, then exit(1) */
114115
);
115116

116117
/** unregister previously registered handler for interrupt signals

0 commit comments

Comments
 (0)