Example #1
0
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();
		}
	}
}
Example #2
0
static void tuple_changed_callback(const uint32_t key, const Tuple* tuple_new, const Tuple* tuple_old, void* context) {
  int value = tuple_new->value->uint8;
  switch (key) {
    case setting_seconds:
      seconds = value;
      persist_write_int(setting_seconds, seconds);
      
      if (seconds == seconds_on)
        enable_seconds();
      else
        disable_seconds();
      break;
    case setting_background:
      background = value;
      persist_write_int(setting_background, background);
      
      bitmap_layer_set_bitmap(background_layer, (background == background_simple) ? background_simple_bitmap : background_bitmap);
      layer_mark_dirty((Layer*) background_layer);
      break;
    case setting_info:
      info = value;
      persist_write_int(setting_info, info);
      
      if (info == info_on)
        enable_info();
      else
        disable_info();
      break;
    case setting_digital:
      digital = value;
      persist_write_int(setting_digital, digital);
      
      if (digital == digital_off)
        disable_digital();
      else
        enable_digital();
      break;
  }
    
  update_now();
}
Example #3
0
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();
	}
}