unsigned int scheduler_launch_task(start_func_t* start_func) { unsigned int tid = launch_task(start_func); run_queue_add_task(tid); return tid; }
int main (int argc,char *argv[]) { int force = 0; pid_t consistency_pid; pid_t listener_pid; slave_get_options(&argc,&argv,&force,&sdb); logtool = DRQ_LOG_TOOL_SLAVE; // Set some standard defaults based on DRQUEUE_ROOT (must be already set!) set_default_env(); // Config files overrides environment // Read the config file after reading the arguments, as those may change // the path to the config file if (sdb.conf[0]) { config_parse(sdb.conf); } else { config_parse_tool("slave"); } if (!common_environment_check()) { log_auto (L_ERROR,"Error checking the environment: %s",drerrno_str()); exit (1); } set_signal_handlers (); //system ("env | grep DRQUEUE"); sdb.shmid = get_shared_memory_slave (force); sdb.comp = attach_shared_memory_slave (sdb.shmid); sdb.semid = get_semaphores_slave (); log_auto (L_INFO,"Starting..."); computer_init (sdb.comp); sdb.comp->used = 1; get_hwinfo (&sdb.comp->hwinfo); computer_limits_cpu_init (sdb.comp); // computer_init_limits depends on the hardware information slave_set_limits (&sdb); // Override defaults logger_computer = sdb.comp; report_hwinfo (&sdb.comp->hwinfo); fprintf (stderr,"Working silently..."); register_slave (sdb.comp); // Before sending the limits we have to set the pools computer_pool_set_from_environment (&sdb.comp->limits); computer_pool_list (&sdb.comp->limits); update_computer_limits(&sdb.comp->limits); /* Does not need to be locked because at this point */ /* because there is only one process running. The rest of the time */ /* either we call it locked or we make a copy of the limits while locked */ /* and then we send that copy */ if (pipe(phantom) != 0) { fprintf (stderr,"Phantom pipe could not be created\n"); exit (1); } if ((listener_pid = fork()) == 0) { /* Create the listening process */ log_auto (L_INFO,"Listener process starting..."); set_signal_handlers_child_listening (); slave_listening_process (&sdb); log_auto (L_INFO,"Listener process exiting..."); exit (0); } else if (listener_pid == -1) { drerrno_system = errno; log_auto (L_ERROR,"Could not create the listener process. (%s)", strerror(drerrno_system)); slave_exit(SIGINT); } if ((consistency_pid = fork()) == 0) { // Create the consistency checks process // Signal are treated the same way as the listening process log_auto (L_INFO,"Consistency process starting..."); set_signal_handlers_child_listening (); slave_consistency_process (&sdb); log_auto (L_INFO,"Consistency process exiting..."); exit (0); } else if (consistency_pid == -1) { drerrno_system = errno; log_auto (L_ERROR,"Could not create the listener process. (%s)", strerror(drerrno_system)); slave_exit(SIGINT); } while (1) { get_computer_status (&sdb.comp->status,sdb.semid); computer_autoenable_check (&sdb); /* Check if it's time for autoenable */ while (computer_available(sdb.comp)) { uint16_t itask; if (request_job_available(&sdb,&itask)) { launch_task(&sdb,itask); update_computer_status (&sdb); } else { // computer not available break; // break the while loop } } /* WARNING could be in this loop forever if no care is taken !! */ update_computer_status (&sdb); /* sends the computer status to the master */ /* Does not need to be locked because we lock inside it */ FD_ZERO(&read_set); FD_SET(phantom[0],&read_set); timeout.tv_sec = SLAVEDELAY; timeout.tv_usec = 0; rs = select (phantom[0]+1,&read_set,NULL,NULL,&timeout); switch (rs) { case -1: /* Error in select */ log_auto(L_ERROR,"Select call failed"); case 0: log_auto(L_DEBUG,"Slave loop (select call timeout)"); break; default: if (FD_ISSET(phantom[0],&read_set)) { log_auto(L_DEBUG,"Select call, notification came. Available for reading."); read(phantom[0],buffer,BUFFERLEN); } else { log_auto(L_WARNING,"Select call, report this message, please. It should never happen."); } } } exit (0); }