Beispiel #1
0
int main(int argc, char *argv[])
{

	signal(SIGALRM, sig_alarm);

	if ((argc < 2) || (argc > 2 && argc < 5) || (argc > 5)) {
		fprintf(stderr, "Error args!\n");
		print_usage();
		return -1;
	}

	strcpy(root_dir, argv[1]);
	if (root_dir[strlen(root_dir)-1] == '/') {
		root_dir[strlen(root_dir)-1] = '\0';	
	}
	if (argc == 5) {
		file_size = atol(argv[2])*1024*1024;
		thread_n = atoi(argv[3]);
		time_s = atoi(argv[4]);
	}
	if ((n = parse_args()) <= 0) {
		openlog("fs_write", LOG_CONS|LOG_PID, 0);
		syslog(LOG_USER|LOG_ERR, "parse_args error!\n");
		print_usage();
		return -1;
	}
	strcpy(_dirname, root_dir);
	strcat(_dirname, "/");
	strcat(_dirname, dirs_name[now]);
	if (init_time(time_s) < 0) {
		openlog("fs_write", LOG_CONS|LOG_PID, 0);
		syslog(LOG_USER|LOG_ERR, "init_time error!\n");
		return -1;
	}

	if (w_thread() < 0) {
		return -1;
	}
	if (dfile() < 0) {
		return -1;
	}
}
Beispiel #2
0
static void sig_handler(int sig) {
	if (sig == SIGINT || sig == SIGTERM) {
		std::cout << "Caught SIGINT/SIGTERM" << std::endl;
		if (work->shutdown()) {
			exit(0);
		}
	} else if (sig == SIGHUP) {
		std::cout << "Reloading config" << std::endl;
		std::cout.flush();
		conf->reload();
		db->reload_config(conf);
		mother->reload_config(conf);
		sc->reload_config(conf);
		sched->reload_config(conf);
		work->reload_config(conf);
		std::cout << "Done reloading config" << std::endl;
	} else if (sig == SIGUSR1) {
		std::cout << "Reloading from database" << std::endl;
		std::thread w_thread(&worker::reload_lists, work);
		w_thread.detach();
	}
}