void *restore_thrd(void *arg) { sigset_t sigmask, old_mask; int sig; sigemptyset(&sigmask); sigaddset(&sigmask, SIGINT); sigaddset(&sigmask, SIGTERM); sigaddset(&sigmask, SIGUSR1); pthread_sigmask(SIG_BLOCK, &sigmask, &old_mask); while(1) { sigwait(&sigmask, &sig); if(sig == SIGINT || sig == SIGTERM) { interrupted ++; if(interrupted == 1) { ERROR("Interrupting will restore original " "filesystem!\n"); ERROR("Interrupt again to quit\n"); } } if(interrupted == 2 || sig == SIGUSR1) { disable_progress_bar(); disable_info(); pthread_cancel(main_thread); pthread_join(main_thread, NULL); restorefs(); } } }
void *restore_thrd(void *arg) { sigset_t sigmask, old_mask; int i, sig; sigemptyset(&sigmask); sigaddset(&sigmask, SIGINT); sigaddset(&sigmask, SIGTERM); sigaddset(&sigmask, SIGUSR1); pthread_sigmask(SIG_BLOCK, &sigmask, &old_mask); while (1) { sigwait(&sigmask, &sig); if ((sig == SIGINT || sig == SIGTERM) && !interrupted) { ERROR("Interrupting will restore original " "filesystem!\n"); ERROR("Interrupt again to quit\n"); interrupted = TRUE; continue; } /* kill main thread/worker threads and restore */ set_progressbar_state(FALSE); disable_info(); /* first kill the reader thread */ pthread_cancel(reader_thread); pthread_join(reader_thread, NULL); /* * then flush the reader to deflator thread(s) output queue. * The deflator thread(s) will idle */ queue_flush(to_deflate); /* now kill the deflator thread(s) */ for (i = 0; i < processors; i++) pthread_cancel(deflator_thread[i]); for (i = 0; i < processors; i++) pthread_join(deflator_thread[i], NULL); /* * then flush the reader to process fragment thread(s) output * queue. The process fragment thread(s) will idle */ queue_flush(to_process_frag); /* now kill the process fragment thread(s) */ for (i = 0; i < processors; i++) pthread_cancel(frag_thread[i]); for (i = 0; i < processors; i++) pthread_join(frag_thread[i], NULL); /* * then flush the reader/deflator/process fragment to main * thread output queue. The main thread will idle */ seq_queue_flush(to_main); /* now kill the main thread */ pthread_cancel(main_thread); pthread_join(main_thread, NULL); /* then flush the main thread to fragment deflator thread(s) * queue. The fragment deflator thread(s) will idle */ queue_flush(to_frag); /* now kill the fragment deflator thread(s) */ for (i = 0; i < processors; i++) pthread_cancel(frag_deflator_thread[i]); for (i = 0; i < processors; i++) pthread_join(frag_deflator_thread[i], NULL); /* * then flush the main thread/fragment deflator thread(s) * to writer thread queue. The writer thread will idle */ queue_flush(to_writer); /* now kill the writer thread */ pthread_cancel(writer_thread); pthread_join(writer_thread, NULL); TRACE("All threads cancelled\n"); restorefs(); } }