Ejemplo n.º 1
0
static void sig_handle_timer(int signum)
{
	int saved_errno = errno;

	if (!--timer_save_value) {
		timer_save_value = timer_save_interval;

		event_save = event_pending = 1;
	}

	if (!--timer_ticksafety_value) {
		timer_ticksafety_value = timer_ticksafety_interval;

		event_ticksafety = event_pending = 1;
	}

	if (john_main_process) {
		int c;
#if OS_FORK
		int new_abort = 0, new_status = 0;
#endif
		while ((c = tty_getchar()) >= 0) {
			if (c == 3 || c == 'q') {
#if OS_FORK
				new_abort = 1;
#endif
				sig_handle_abort(0);
			} else {
#if OS_FORK
				new_status = 1;
#endif
				event_status = event_pending = 1;
			}
		}

#if OS_FORK
		if (new_abort || new_status)
			signal_children(new_abort ? SIGTERM : SIGUSR2);
#endif
	}

#if !OS_TIMER
	signal(SIGALRM, sig_handle_timer);
#elif !defined(SA_RESTART) && !defined(__DJGPP__)
	sig_install_timer();
#endif

	errno = saved_errno;
}
Ejemplo n.º 2
0
static void sig_handle_reload(int signum)
{
#if OS_FORK && !defined(BENCH_BUILD)
	if (!event_reload && options.fork) {
		if (john_main_process)
			signal_children(signum);
		else
			kill(getppid(), signum);
	}
#endif
	if (!event_abort)
		event_reload = 1;
	/* Avoid loops from signalling ppid. We re-enable this signal
	   in sig_handle_timer() */
	signal(signum, SIG_IGN);
}
Ejemplo n.º 3
0
static void sig_handle_abort(int signum)
{
	int saved_errno = errno;

#if OS_FORK
	if (john_main_process) {
/*
 * We assume that our children are running on the same tty with us, so if we
 * receive a SIGINT they probably do as well without us needing to forward the
 * signal to them.  If we forwarded the signal anyway, this could result in
 * them receiving the signal twice for a single Ctrl-C keypress and proceeding
 * with immediate abort without updating the files, which is behavior that we
 * reserve for (presumably intentional) repeated Ctrl-C keypress.
 *
 * We forward the signal as SIGINT even though ours was different (typically a
 * SIGTERM) in order not to trigger a repeated same signal for children if the
 * user does e.g. "killall john", which would send SIGTERM directly to children
 * and also have us forward a signal.
 */
		if (signum != SIGINT)
			signal_children(SIGINT);
	} else {
		static int prev_signum;
/*
 * If it's not the same signal twice in a row, don't proceed with immediate
 * abort since these two signals could have been triggered by the same killall
 * (perhaps a SIGTERM from killall directly and a SIGINT as forwarded by our
 * parent).  event_abort would be set back to 1 just below the check_abort()
 * call.  We only reset it to 0 temporarily to skip the immediate abort here.
 */
		if (prev_signum && signum != prev_signum)
			event_abort = 0;
		prev_signum = signum;
	}
#endif

	check_abort(1);

	event_abort = event_pending = 1;

	write_loop(2, "Wait...\r", 8);

	sig_install_abort();

	errno = saved_errno;
}
Ejemplo n.º 4
0
static void sig_handle_timer(int signum)
{
	int saved_errno = errno;
#if !OS_TIMER
	unsigned int time;
#endif
#ifndef BENCH_BUILD
#if OS_TIMER
	/* Some stuff only done every few seconds */
	if (timer_save_interval < 4 ||
	    ((timer_save_interval - timer_save_value) & 3) == 3) {
#ifdef HAVE_MPI
		if (!event_reload && mpi_p > 1) {
			event_pending = event_mpiprobe = 1;
		}
#endif
		event_poll_files = event_pending = 1;
#ifdef SIGUSR2
		sig_install(sig_handle_reload, SIGUSR2);
#endif
	}
	if (!--timer_save_value) {
		timer_save_value = timer_save_interval;
		event_save = event_pending = 1;
		event_reload = options.reload_at_save;
	}
	if (timer_abort && !--timer_abort) {
		aborted_by_timer = 1;
		if (abort_grace_time > 0)
			timer_abort = abort_grace_time;
		else if (abort_grace_time < 0)
			timer_abort = 0;
		else /* no grace time, kill immediately */
			event_abort = 1;
		sig_handle_abort(0);
	}
	if (timer_status && !--timer_status) {
		timer_status = options.status_interval;
		event_status = event_pending = 1;
	}
#else /* no OS_TIMER */
	time = status_get_time();

	/* Some stuff only done every few seconds */
	if ((time & 3) == 3) {
#ifdef HAVE_MPI
		if (!event_reload && mpi_p > 1) {
			event_pending = event_mpiprobe = 1;
		}
#endif
		event_poll_files = event_pending = 1;
#ifdef SIGUSR2
		sig_install(sig_handle_reload, SIGUSR2);
#endif
	}
	if (time >= timer_save_value) {
		timer_save_value += timer_save_interval;
		event_save = event_pending = 1;
		event_reload = options.reload_at_save;
	}
	if (timer_abort && time >= timer_abort) {
		aborted_by_timer = 1;
		if (abort_grace_time > 0)
			timer_abort += abort_grace_time;
		else if (abort_grace_time < 0)
			timer_abort = 0;
		else /* no grace time, kill immediately */
			event_abort = 1;
		sig_handle_abort(0);
	}
	if (timer_status && time >= timer_status) {
		timer_status += options.status_interval;
		event_status = event_pending = 1;
	}
#endif /* OS_TIMER */
#endif /* !BENCH_BUILD */

	if (!--timer_ticksafety_value) {
		timer_ticksafety_value = timer_ticksafety_interval;

		event_ticksafety = event_pending = 1;
	}

#ifndef HAVE_MPI
	if (john_main_process)
#endif
	{
		int c;
#if OS_FORK
		int new_abort = 0, new_status = 0;
#endif
		while ((c = tty_getchar()) >= 0) {
			if (c == 3 || c == 'q') {
#if OS_FORK
				new_abort = 1;
#endif
				sig_handle_abort(0);
			} else {
#if OS_FORK
				new_status = 1;
#endif
				event_status = event_pending = 1;
			}
		}

#if OS_FORK
		if (new_abort || new_status)
			signal_children(new_abort ? SIGTERM : SIGUSR1);
#endif
	}

#if !OS_TIMER
	signal(SIGALRM, sig_handle_timer);
#elif !defined(SA_RESTART) && !defined(__DJGPP__)
	sig_install_timer();
#endif

	errno = saved_errno;
}