void delete_list(LinkedList * list) { if(list == NULL) return; LinkedList * next; do { next = list->next; delete_list_element(list); list = next; } while (list != NULL); }
void remove_list_element(LinkedList * list, void * data) { do { if(list->data == data) { list->prev->next = list->next; if(list->next != NULL) list->next->prev = list->prev; delete_list_element(list); } list = list->next; } while(list != NULL); }
int poll_pids() { //Poll all the alive/exited pids with WNOHANG - returns immediately without waiting for child process to exit. if (pid_list.starting==NULL) { return 0; } else { configure_status_file_and_mmap(); int sleeptime=5,i; struct subprocess* current=pid_list.starting; int poll_status,status; lock_file(); sprintf((char *)mmap_file_pointer,""); while (current->next!=NULL) { poll_status=waitpid(current->pid,&status,WNOHANG); if (poll_status==current->pid) { int exit_code=WEXITSTATUS(status); if (exit_code==0) { subprocess_count-=1; delete_list_element(current); } else if (exit_code==30 || exit_code==255 || exit_code==12) { if (exit_code==12) {sleeptime=1;} current->retries+=1; sleeptime=5; for (i=0;i<current->retries && sleeptime<320;i++) {sleeptime*=2;} strcpy(current->start_time,get_time_string()); current->pid=exec_pipe(current->command,sleeptime); } else { subprocess_count-=1; delete_list_element(current); } } else if (poll_status==0) { put_info_in_status_file(current); } current=current->next; } poll_status=waitpid(current->pid,&status,WNOHANG); if (poll_status==current->pid) { int exit_code=WEXITSTATUS(status); if (exit_code==0) { subprocess_count-=1; delete_list_element(current); } else if (exit_code==30 || exit_code==255 || exit_code==12) { if (exit_code==12) {sleeptime=1;} current->retries+=1; sleeptime=5; for (i=0;i<current->retries && sleeptime<320;i++) {sleeptime*=2;} strcpy(current->start_time,get_time_string()); printf("%s\n",current->command); current->pid=exec_pipe(current->command,sleeptime); } else { subprocess_count-=1; delete_list_element(current); } } else if (poll_status==0) { put_info_in_status_file(current); } unlock_file(); clear_status_file(); return 0; } }
int kill_and_replace_process(struct subprocess* to_be_killed, struct subprocess* replacement, struct inotify_event* event, char*command) { kill(to_be_killed->pid,SIGINT); delete_list_element(to_be_killed); return execute_and_create_process(replacement,event,command); }