+ if (bg_jobs) {
+ /* Do not use xbt_dynar_free or it will lock the dynar, preventing armageddon from working */
+ while (xbt_dynar_length(bg_jobs)) {
+ rctx_t rctx;
+ xbt_dynar_pop(bg_jobs,&rctx);
+ kill_it(&rctx);
+ }
+ xbt_dynar_free(&bg_jobs);
+ }
+ bg_jobs = xbt_dynar_new_sync(sizeof(rctx_t),kill_it);
+}
+
+void rctx_armageddon(rctx_t initiator, int exitcode) {
+ rctx_t rctx;
+
+ DEBUG2("Armageddon request by <%s> (exit=%d)",initiator->filepos,exitcode);
+ xbt_os_mutex_acquire(armageddon_mutex);
+ if (armageddon_initiator != NULL) {
+ VERB0("Armageddon already started. Let it go");
+ xbt_os_mutex_release(initiator->interruption);
+ xbt_os_mutex_release(armageddon_mutex);
+ return;
+ }
+ DEBUG1("Armageddon request by <%s> got the lock. Let's go amok",initiator->filepos);
+ armageddon_initiator = initiator;
+ xbt_os_mutex_release(armageddon_mutex);
+
+ /* Kill any background commands */
+ while (xbt_dynar_length(bg_jobs)) {
+ xbt_dynar_pop(bg_jobs,&rctx);
+ if (rctx != initiator) {
+ INFO2("Kill <%s> because <%s> failed",rctx->filepos,initiator->filepos);
+ xbt_os_mutex_acquire(rctx->interruption);
+ rctx->interrupted = 1;
+ xbt_os_mutex_release(rctx->interruption);
+ if (!rctx->reader_done) {
+ kill(rctx->pid,SIGTERM);
+ usleep(100);
+ kill(rctx->pid,SIGKILL);
+ }
+ }
+ }
+
+ VERB0("Shut everything down!");
+ exit(exitcode);