Example #1
0
File: main.c Project: jnbek/TekNap
/* nap_exit: cleans up and leaves */
void nap_exit (int really_quit, char *reason, char *format, ...)
{
	if (dead == 1) {
		kill_all_threads();
		exit(1);
	}
	else if (dead == 2) {
		kill_all_threads();
		_exit(1);
	}
	else if (dead == 3) {
		kill_all_threads();
		kill(getpid(), SIGKILL);
	}
	dead++;

	set_lastlog_size(NULL, NULL, 0);
	set_history_size(NULL, NULL, 0);

	if (really_quit)
	{
		kill_all_threads();
		say("Signon time  :    %s", my_ctime(start_time));
		say("Signoff time :    %s", my_ctime(now));
		say("Total uptime :    %s", convert_time(now - start_time));
	}
	do_hook(EXIT_LIST, "%s", reason ? reason : empty_string);
	if (reason)
		say("%s", reason);

	close_all_servers();
	close_all_sockets();
	if (term_initialized)
	{
		cursor_to_input();
		term_cr();
		term_clear_to_eol();
		term_reset();
	}

	remove_bindings();
	clear_variables();
	delete_all_windows();
	destroy_call_stack();		
	write_unfinished_list();
	
	debug_cleanup();
	fprintf(stdout, "\r");
	fflush(stdout);
	if (really_quit)
		exit(0);

	kill_all_threads();
	my_signal(SIGABRT, SIG_DFL, 0);
	kill(getpid(), SIGABRT);
	kill(getpid(), SIGQUIT);
	exit(1);
}
Example #2
0
static void suspend_upcall (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
{
    if (IS_INTERNAL_TID(get_cur_tid()))
        goto ret_exception;

    if (ask_for_checkpoint) {
        int ans =  message_confirm("checkpoint execution "
                                   "(\'k\' to kill the process)",
                                   "yk");

        if (ans == 'K' || ans == 'k')
            goto kill;

        if (ans != 'Y' && ans != 'y')
            goto ret_exception;

        shim_tcb_t * tcb = SHIM_GET_TLS();
        assert(tcb && tcb->tp);
        struct shim_signal signal;
        __store_context(tcb, context, &signal);

        IDTYPE session = 0;
        char cpdir[20];

        if (create_dir("checkpoint-", cpdir, 20, NULL) < 0)
            goto ret_exception;

        sys_printf("creating checkpoint \"%s\"...\n", cpdir);

        if (create_checkpoint(cpdir, &session) < 0)
            goto ret_exception;

        ipc_checkpoint_send(cpdir, session);
        kill_all_threads(tcb->tp, CHECKPOINT_REQUESTED, SIGINT);
        join_checkpoint(tcb->tp, &signal.context);
        goto ret_exception;
    }

kill:
    deliver_signal(ALLOC_SIGINFO(SIGINT, si_pid, 0), NULL);

ret_exception:
    DkExceptionReturn(event);
}
Example #3
0
void main_loop()
{
    char input[STRING_SIZE];
    thread_t threads[MAX_THREADS_COUNT];
    struct thread_args_t all_args[MAX_THREADS_COUNT];
    int last_thread_id = -1;

    while (1) {
        fgets(input, STRING_SIZE, stdin);
        switch (input[0]) {
        case '+':
            add_thread(threads, all_args, ++last_thread_id);
            break;
        case '-':
            delete_thread(threads, all_args, &last_thread_id);
            break;
        case 'q':
            kill_all_threads(threads, all_args, last_thread_id);
            return;
        }
    }
}