|
14 | 14 | * reserved. |
15 | 15 | * Copyright (c) 2015 Research Organization for Information Science |
16 | 16 | * and Technology (RIST). All rights reserved. |
| 17 | + * Copyright (c) 2017 FUJITSU LIMITED. All rights reserved. |
17 | 18 | * $COPYRIGHT$ |
18 | 19 | * |
19 | 20 | * Additional copyrights may follow |
|
27 | 28 | #include <errno.h> |
28 | 29 | #include <stdio.h> |
29 | 30 | #include <stdlib.h> |
| 31 | +#include <unistd.h> |
30 | 32 |
|
31 | 33 | #include "opal/util/error.h" |
32 | 34 | #include "opal/constants.h" |
| 35 | +#include "opal/util/proc.h" |
| 36 | +#include "opal/runtime/opal_params.h" |
33 | 37 |
|
34 | 38 | #define MAX_CONVERTERS 5 |
35 | 39 | #define MAX_CONVERTER_PROJECT_LEN 10 |
@@ -208,3 +212,36 @@ opal_error_register(const char *project, int err_base, int err_max, |
208 | 212 |
|
209 | 213 | return OPAL_ERR_OUT_OF_RESOURCE; |
210 | 214 | } |
| 215 | + |
| 216 | + |
| 217 | +void |
| 218 | +opal_delay_abort(void) |
| 219 | +{ |
| 220 | + // Though snprintf and strlen are not guaranteed to be async-signal-safe |
| 221 | + // in POSIX, it is async-signal-safe on many implementations probably. |
| 222 | + |
| 223 | + if (0 != opal_abort_delay) { |
| 224 | + int delay = opal_abort_delay; |
| 225 | + pid_t pid = getpid(); |
| 226 | + char msg[100 + OPAL_MAXHOSTNAMELEN]; |
| 227 | + |
| 228 | + if (delay < 0) { |
| 229 | + snprintf(msg, sizeof(msg), |
| 230 | + "[%s:%05d] Looping forever " |
| 231 | + "(MCA parameter opal_abort_delay is < 0)\n", |
| 232 | + opal_process_info.nodename, (int) pid); |
| 233 | + write(STDERR_FILENO, msg, strlen(msg) + 1); |
| 234 | + while (1) { |
| 235 | + sleep(5); |
| 236 | + } |
| 237 | + } else { |
| 238 | + snprintf(msg, sizeof(msg), |
| 239 | + "[%s:%05d] Delaying for %d seconds before aborting\n", |
| 240 | + opal_process_info.nodename, (int) pid, delay); |
| 241 | + write(STDERR_FILENO, msg, strlen(msg) + 1); |
| 242 | + do { |
| 243 | + sleep(1); |
| 244 | + } while (--delay > 0); |
| 245 | + } |
| 246 | + } |
| 247 | +} |
0 commit comments