// type is ignored int setitimer(int type, struct itimerval *in, struct itimerval *out) { static const struct timeval zero; static int atexit_done; if (out != NULL) return errno = EINVAL; if (!is_timeval_eq(&in->it_interval, &zero) && !is_timeval_eq(&in->it_interval, &in->it_value)) return errno = EINVAL; if (timer_thread) stop_timer_thread(); if (is_timeval_eq(&in->it_value, &zero) && is_timeval_eq(&in->it_interval, &zero)) return 0; timer_interval = in->it_value.tv_sec * 1000 + in->it_value.tv_usec / 1000; one_shot = is_timeval_eq(&in->it_interval, &zero); if (!atexit_done) { atexit(stop_timer_thread); atexit_done = 1; } return start_timer_thread(); }
void cos_upcall_fn(upcall_type_t t, void *arg1, void *arg2, void *arg3) { static int first = 1; switch (t) { case COS_UPCALL_BOOTSTRAP: if (first) { start_timer_thread(); first = 0; } else { printc("timed_event component received too many bootstrap threads."); } break; default: printc("wf_text: cos_upcall_fn error - type %x, arg1 %d, arg2 %d", (unsigned int)t, (unsigned int)arg1, (unsigned int)arg2); BUG(); return; } BUG(); return; }
c_bool_t init ( const char *dir, const char *nginx_dir, const char *auth, int pool_size, int check_release, int check_db, int gen_log ) { release_interval = check_release / 1000; checkdb_interval = check_db / 1000; gen_log_interval = gen_log / 1000; pthread_mutex_init (&file_queue_mutex, NULL); pthread_mutex_init (&release_lock, NULL); memset (status_buf, '0', FILE_BIT_MAX); tp = new ThreadPool (pool_size); tp->init_threadpool (); std::string status_dir_str (nginx_dir); status_dir_str.append ("status/"); const char *status_dir = status_dir_str.c_str (); int md = mkdir (status_dir, S_IRWXU | S_IRWXG | S_IRWXO); if ( md == - 1 && errno != EEXIST ) { return false; } char total_status_file[256]; sprintf (total_status_file, "%stotal_status.log", status_dir); int fd = open (total_status_file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if ( fd == - 1 ) { std::cerr << "open total_status_file failed" << std::endl; return false; } struct stat sb; fstat (fd, &sb); if ( sb.st_size == 0 ) { write (fd, ( void * ) status_buf, 2 * sizeof (uint64_t )); total_status_addr = ( char * ) mmap (NULL, 2 * sizeof (uint64_t ), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if ( total_status_addr == MAP_FAILED ) { std::cerr << "map total_status_addr failed" << std::endl; return false; } *( uint64_t * ) total_status_addr = 0; *( uint64_t * ) ( total_status_addr + sizeof (uint64_t ) ) = 0; } else { total_status_addr = ( char * ) mmap (NULL, 2 * sizeof (uint64_t ), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); } close (fd); fd = open (auth, O_RDONLY); if ( fd == - 1 ) { std::cerr << "auth failed" << std::endl; return false; } read (fd, passwd, 255); close (fd); construct_file_queues (status_dir, dir); if ( start_monitor_thread () != 0 ) { return false; } if ( start_check_db_thread () != 0 ) { return false; } if ( start_timer_thread () != 0 ) { return false; } if ( start_read_log_thread () != 0 ) { return false; } return true; }