int main(void) { int ret; ret = test_init(); if (ret != 0) { fprintf(stderr, "test_init failed\n"); return 1; } ret = test_fork(); if (ret != 0) { fprintf(stderr, "test_fork failed\n"); return 1; } ret = test_jobs(10, 10000); if (ret != 0) { fprintf(stderr, "test_jobs failed\n"); return 1; } ret = test_busydestroy(); if (ret != 0) { fprintf(stderr, "test_busydestroy failed\n"); return 1; } /* * Test 10 threads adding jobs on a single pool */ ret = test_threaded_addjob(1, 10, 5, 5000); if (ret != 0) { fprintf(stderr, "test_jobs failed\n"); return 1; } /* * Test 10 threads on 3 pools to verify our fork handling * works right. */ ret = test_threaded_addjob(3, 10, 5, 5000); if (ret != 0) { fprintf(stderr, "test_jobs failed\n"); return 1; } printf("success\n"); return 0; }
void main_loop() /* main loop - get the time to sleep until next job execution, * sleep, and then test all jobs and execute if needed. */ { time_t save; /* time remaining until next save */ time_t stime; /* time to sleep until next job * execution */ #ifdef HAVE_GETTIMEOFDAY struct timeval tv; /* we use usec field to get more precision */ #endif #ifdef FCRONDYN int retcode = 0; #endif debug("Entering main loop"); now = time(NULL); synchronize_dir(".", is_system_startup()); /* synchronize save with jobs execution */ save = now + save_time; if (serial_num > 0 || once) stime = first_sleep; else if ((stime = time_to_sleep(save)) < first_sleep) /* force first execution after first_sleep sec : execution of jobs * during system boot time is not what we want */ stime = first_sleep; debug("initial sleep time : %ld", stime); for (;;) { #ifdef HAVE_GETTIMEOFDAY #ifdef FCRONDYN gettimeofday(&tv, NULL); tv.tv_sec = (stime > 1) ? stime - 1 : 0; /* we set tv_usec to slightly more than necessary so as * we don't wake up too early, in which case we would * have to sleep again for some time */ tv.tv_usec = 1001000 - tv.tv_usec; /* On some systems (BSD, etc), tv_usec cannot be greater than 999999 */ if (tv.tv_usec > 999999) tv.tv_usec = 999999; /* note: read_set is set in socket.c */ if ((retcode = select(set_max_fd + 1, &read_set, NULL, NULL, &tv)) < 0 && errno != EINTR) die_e("select returned %d", errno); #else if (stime > 1) sleep(stime - 1); gettimeofday(&tv, NULL); /* we set tv_usec to slightly more than necessary to avoid * infinite loop */ usleep(1001000 - tv.tv_usec); #endif /* FCRONDYN */ #else sleep(stime); #endif /* HAVE_GETTIMEOFDAY */ now = time(NULL); check_signal(); debug("\n"); test_jobs(); while (serial_num > 0 && serial_running < serial_max_running) run_serial_job(); if (once) { explain("Running with option once : exiting ... "); xexit(EXIT_OK); } if (save <= now) { save = now + save_time; /* save all files */ save_file(NULL); } #ifdef FCRONDYN /* check if there's a new connection, a new command to answer, etc ... */ /* we do that *after* other checks, to avoid Denial Of Service attacks */ check_socket(retcode); #endif stime = check_lavg(save); debug("next sleep time : %ld", stime); check_signal(); } }