void CInstancedMeshSceneNode::OnAnimate(u32 timeMs) { ISceneNode::OnAnimate(timeMs); if (!isStatic()) updateInstances(); }
void OpenGLVegetationLayer::threadedUpdate() { if (camera_changed) { camera_changed = false; updateInstances(); updateImpostor(); } }
bool instPoint::generateInst() { updateInstances(); bool success = false; for (unsigned i = 0; i < instances.size(); i++) { // I was using |=, but it looked like it was getting short-cutted? bool ret = instances[i]->generateInst(); if (ret) success = true; } return success; }
/** * Daemon main loop. Sets up named pipe and captures commands * given through named pipe. * * Can be stopped with "stop" command or with SIGTERM. * * @return int Returns negative integer on error. */ int daemon_main(){ char buf[128] = {0}; FILE *fp; struct sigaction act; sigset_t mask; int res = 0; sigemptyset(&mask); sigaddset(&mask,SIGTERM); sigaddset(&mask,SIGCHLD); sigaddset(&mask,SIGHUP); setlinebuf(stdout); bzero(&act, sizeof(act)); act.sa_sigaction = sig_handler; act.sa_mask = mask; act.sa_flags = SA_NOCLDSTOP|SA_SIGINFO; sigaction(SIGTERM, &act, NULL); sigaction(SIGCHLD, &act, NULL); sigaction(SIGHUP, &act, NULL); if((res = loadConfig()) != 0){ if (res == 1) return res; fprintf(stderr, "Failed to load conf, continuing with defaults.\n"); } updateInstances(); unlink(OPAFMD_PIPE); // cleanup any bad states if (mkfifo(OPAFMD_PIPE, 0660) == -1){ fprintf(stderr, "Failed to create pipe: %s\n", strerror(errno)); return(2); } if((fd = open(OPAFMD_PIPE, O_RDWR)) == -1){ fprintf(stderr, "Failed to open pipe for reading: %s\n", strerror(errno)); unlink(OPAFMD_PIPE); // cleanup any bad states return(2); } if((fp = fdopen(fd, "r")) == NULL){ fprintf(stderr, "Failed to open pipe for reading: %s\n", strerror(errno)); unlink(OPAFMD_PIPE); // cleanup any bad states return(2); } sigprocmask(SIG_BLOCK, &mask, NULL); while(!doStop){ char *s; sigprocmask(SIG_UNBLOCK, &mask, NULL); s = fgets(buf, 127, fp); sigprocmask(SIG_BLOCK, &mask, NULL); if (s != NULL) { parseInput(buf); } } sigprocmask(SIG_UNBLOCK, &mask, NULL); fclose(fp); doStop = -(doStop - 1); // Use doStop value as return value. Allows systemd to show daemon status on failure. unlink(OPAFMD_PIPE); // Destroy pipe pthread_exit(&doStop); // Allows any running background threads to terminate properly. }
/** * Function to parse values passed through named pipe to the * daemon. * * @param buf Pointer to the string extracted from the named * pipe * * @return int Returns 1 if the daemon recieved a command to * stop. */ int parseInput(char *buf){ char *token; int i, c; struct thread_data *thread = NULL; pthread_t thread_id[FM_MAX_INSTANCES*FM_NUM_COMPONENTS]; token = strtok(buf, " "); if(token == NULL){ fprintf(stderr, "Received invalid input. Ignoring.\n"); return 0; } if(strncmp(token, "sig_chld", 8) == 0){ int i = 0, pid = 0, stat = 0; unsigned int instance = 0, component = 0; while ((pid = waitpid(-1, &stat, WNOHANG)) > 0) { for(i = 0; i < FM_MAX_INSTANCES; ++i){ if(smPID[i] == pid){ component = SM_COMPONENT; instance = i; break; } else if (fePID[i] == pid){ component = FE_COMPONENT; instance = i; break; } } if(component == 0){ continue; } fprintf(stderr, "%s component of instance %d has terminated with exit code %d\n", componentToString(component), instance, stat); if(stat == 0 || stat == 1){ //Skip restarting these components if expected (return 0) or user error (return 1) if(stat == 1) fprintf(stderr, "Check opafm.xml config for invalid settings.\n"); return 0; } if(checkRestarts(instance, component)){ //Component has failed too many times doStop = 3; return 0; } if (pkill(instance, component) == 0){ spawn(instance, component); } else { //Failed to kill child. Might be a zombie. doStop = 3; return 0; } } } else if(!strncmp(token, "stop", 4) || !strncmp(token, "sig_term", 8)){ token = strtok(NULL, " "); if(token == NULL) token = "a"; switch(token[0]){ case '0': // Kill both SM and FE for this instance number. doStop = 1; token = strtok(NULL, " "); if(token == NULL){ fprintf(stderr, "Received invalid input. Ignoring.\n"); return 0; } i = atoi((const char*)token); if(i >= FM_MAX_INSTANCES || i < 0){ fprintf(stderr, "Received invalid input. Ignoring.\n"); return 0; } for(c = FM_NUM_COMPONENTS - 1; c >= 1; --c){ thread = calloc(1, sizeof(struct thread_data)); if(thread == NULL){ fprintf(stderr, "Failed to allocate thread struct.\n"); return 0; } thread->instance = i; thread->component = c; pthread_create(&thread_id[c], NULL, &kill_thread, thread); } for(c = 1; c < FM_NUM_COMPONENTS; ++c){ pthread_join(thread_id[c], NULL); } break; case '1': // SM and FE are treated the same so this prevents code redundancy case '2': c = atoi((const char*)token); token = strtok(NULL, " "); if(token == NULL){ fprintf(stderr, "Received invalid input. Ignoring.\n"); return 0; } i = atoi((const char*)token); pkill(i, c); break; case 'a': // Kill all running instances. doStop = 1; for(i = 0; i < FM_MAX_INSTANCES; ++i){ for(c = 1; c < FM_NUM_COMPONENTS; ++c){ thread = calloc(1, sizeof(struct thread_data)); if(thread == NULL){ fprintf(stderr, "Failed to allocate thread struct.\n"); return 0; } thread->instance = i; thread->component = c; pthread_create(&thread_id[i*FM_NUM_COMPONENTS+c], NULL, &kill_thread, thread); } } for(i = 0; i < FM_MAX_INSTANCES; ++i){ for(c = 1; c < FM_NUM_COMPONENTS; ++c){ pthread_join(thread_id[i*FM_NUM_COMPONENTS+c], NULL); } } return 1; default: fprintf(stderr, "Unknown component value. (%d)\n", token[0]); } return 0; } if(strncmp(token, "start", 5) == 0){ token = strtok(NULL, " "); if(token == NULL){ fprintf(stderr, "Received invalid input. Ignoring.\n"); return 0; } switch(token[0]){ case '0': token = strtok(NULL, " "); if(token == NULL){ fprintf(stderr, "Received invalid input. Ignoring.\n"); return 0; } i = atoi((const char*)token); if(i > FM_MAX_INSTANCES){ //Adding additional instance check here to avoid duplicate error messages fprintf(stderr, "Received invalid instance number %d. Ignoring.\n", i); return 0; } spawn(i, SM_COMPONENT); spawn(i, FE_COMPONENT); break; case '1': case '2': c = atoi((const char*)token); token = strtok(NULL, " "); if(token == NULL){ fprintf(stderr, "Received invalid input. Ignoring.\n"); return 0; } i = atoi((const char*)token); spawn(i, c); break; default: fprintf(stderr, "Unknown component value.\n"); } } else if(strncmp(token, "sig_hup", 7) == 0){ loadConfig(); updateInstances(); reloadSMs(); } else if(strncmp(token, "restart", 7) == 0){ token = strtok(NULL, " "); if(token == NULL){ fprintf(stderr, "Received invalid input. Ignoring.\n"); return 0; } switch(token[0]){ case '0': token = strtok(NULL, " "); if(token == NULL){ fprintf(stderr, "Received invalid input. Ignoring.\n"); return 0; } i = atoi((const char*)token); if(i > FM_MAX_INSTANCES){ //Adding additional instance check here to avoid duplicate error messages fprintf(stderr, "Received invalid instance number %d. Ignoring.\n", i); return 0; } if(pkill(i, SM_COMPONENT) == 0) spawn(i, SM_COMPONENT); if(pkill(i, FE_COMPONENT) == 0) spawn(i, FE_COMPONENT); break; case '1': case '2': c = atoi((const char*)token); token = strtok(NULL, " "); if(token == NULL){ fprintf(stderr, "Received invalid input. Ignoring.\n"); return 0; } i = atoi((const char*)token); if(pkill(i, c) == 0) spawn(i, c); break; default: fprintf(stderr, "Unknown component value.\n"); } } return 0; }