int qdbRun(int argc, char **argv) { eprintf("\n"); eprintf(" ___ _ ____ ____\n"); eprintf(" / _ \\ _ _ ___ ___| |_| _ \\| __ )\n"); eprintf("| | | | | | |/ _ \\/ __| __| | | | _ \\\n"); eprintf("| |_| | |_| | __/\\__ \\ |_| |_| | |_) |\n"); eprintf(" \\__\\_\\\\__,_|\\___||___/\\__|____/|____/\n"); eprintf(" www.questdb.org\n\n"); CONFIG config; initAndParseConfig(argc, argv, &config); int rtn = 55; if (config.errorCode == ECONFIG_OK) { switch (config.command) { case CMD_START: rtn = svcStart(&config); break; case CMD_STOP: rtn = svcStop(&config); break; case CMD_STATUS: rtn = svcStatus(&config); break; case CMD_INSTALL: rtn = svcInstall(&config); break; case CMD_REMOVE: rtn = svcRemove(&config); break; case CMD_SERVICE: qdbDispatchService(&config); rtn = 0; break; default: rtn = qdbConsole(&config); break; } } else { logConfigError(&config); eprintf("Usage: %s [start|stop|status|install|remove] [-d dir] [-f] [-j JAVA_HOME] [-t tag]", argv[0]); } freeConfig(&config); if (rtn == E_ACCESS_DENIED) { eprintf("ACCESS DENIED\n\nPlease try again as Administrator."); } return rtn; }
int ez_shutdown(int exitval) { shout_shutdown(); playlist_shutdown(); freeConfig(pezConfig); xalloc_shutdown(); return (exitval); }
int main(int argc, char *argv[]) { initConfig(); if (!parseCmdLine(argc, argv)) goto exit; if (estgbconf.isSingleton) { switch (checkSingleton()) { case 0: break; // No another instance found, continue to work case 1: goto exit; // Found another instance of bot, exiting case 2: printf("Error open PID file for singleton check\n"); goto exit; // Something goes wrong, exiting } } if (!globalInit()) goto exit; if (estgbconf.isDaemonize) daemon(0, 0); if (estgbconf.needUnescape) { estgbconf.text = zc_unescape(estgbconf.text); estgbconf.comment = zc_unescape(estgbconf.comment); } if (estgbconf.isScan >= 0) { scan(); goto exit; } if (estgbconf.isWildcard) sendMultiple(); else sendSingle(); exit: freeConfig(); return 0; }
int main( int argc, char **argv ) { mpconfig *control; char *path; FILE *pidlog=NULL; struct timeval tv; control=readConfig( ); if( control == NULL ) { printf( "music directory needs to be set.\n" ); printf( "It will be set up now\n" ); path=(char *)falloc( MAXPATHLEN+1, 1 ); while( 1 ) { printf( "Default music directory:" ); fflush( stdout ); memset( path, 0, MAXPATHLEN ); fgets(path, MAXPATHLEN, stdin ); path[strlen( path )-1]=0; /* cut off CR */ abspath( path, getenv( "HOME" ), MAXPATHLEN ); if( isDir( path ) ) { break; } else { printf( "%s is not a directory!\n", path ); } } writeConfig( path ); free( path ); control=readConfig(); if( control == NULL ) { printf( "Could not create config file!\n" ); return 1; } } muteVerbosity(); /* improve 'randomization' */ gettimeofday( &tv,NULL ); srand( (getpid()*tv.tv_usec)%RAND_MAX ); switch( getArgs( argc, argv ) ) { case 0: /* no arguments given */ break; case 1: /* stream - does this even make sense? */ break; case 2: /* single file */ break; case 3: /* directory */ /* if no default directory is set, use the one given */ if( control->musicdir == NULL ) { incDebug(); addMessage( 0, "Setting default configuration values and initializing..." ); setProfile( control ); if( control->root == NULL ) { addMessage( 0, "No music found at %s!", control->musicdir ); return -1; } addMessage( 0, "Initialization successful!" ); writeConfig( argv[optind] ); freeConfig( ); return 0; } break; case 4: /* playlist */ break; default: addMessage( 0, "Unknown argument!\n", argv[optind] ); return -1; } snprintf( control->pidpath, MAXPATHLEN, "%s/.mixplay/mixplayd.pid", getenv("HOME") ); if( access( control->pidpath, F_OK ) == 0 ) { addMessage( 0, "Mixplayd is already running!" ); freeConfig(); return -1; } signal(SIGINT, sigint ); signal(SIGTERM, sigint ); /* daemonization must happen before childs are created otherwise the pipes are cut */ if( getDebug() == 0 ) { daemon( 0, 1 ); openlog ("mixplayd", LOG_PID, LOG_DAEMON); control->isDaemon=1; pidlog=fopen( control->pidpath, "w"); if( pidlog == NULL ) { addMessage( 0, "Cannot open %s!", control->pidpath ); return -1; } fprintf( pidlog, "%i", getpid() ); fclose(pidlog); } addUpdateHook( &s_updateHook ); control->inUI=1; initAll( ); #ifdef EPAPER sleep(1); if( control->status != mpc_quit ) { epSetup(); addUpdateHook( &ep_updateHook ); } #endif pthread_join( control->stid, NULL ); pthread_join( control->rtid, NULL ); control->inUI=0; #ifdef EPAPER epExit(); #endif if( control->changed ) { writeConfig( NULL ); } unlink(control->pidpath); addMessage( 0, "Daemon terminated" ); freeConfig( ); return 0; }
int main(int argc, char **argv) { model M; int k,i,j; double dX,dY,dZ; /* distance */ double oldAccX,oldAccY,oldAccZ; /* old acceleration */ double dist,dist3; /* force, integrated value */ double ticks; /* used for time-measurement */ cfg *conf; if(argc!=2) { usage(argv[0]); return 0; } /* Read config */ if((conf=initCfg(argv[1]))==NULL) { fprintf(stderr,"Could not parse config\n"); return 0; } getCfgKeyInt(conf,"bodies",&M.bodies); getCfgKeyInt(conf,"steps",&M.steps); getCfgKeyInt(conf,"scale",&M.scale); getCfgKeyInt(conf,"width",&M.width); getCfgKeyInt(conf,"height",&M.height); getCfgKeyDouble(conf,"gravity",&M.G); getCfgKeyDouble(conf,"timestep",&M.timestep); freeConfig(conf); printModelInfo(M); ticks=omp_get_wtime(); /* start time-measurement */ if((M.b=init(M.bodies,M.scale))==NULL) { fprintf(stderr, "Error: Could not allocate memory for bodies.\n"); return 0; } if(initX11Out()==-1) { fprintf(stderr,"Could not initalize X11 output.\n"); return 0; } for(k=0;k<M.steps;++k) { /* printf("* Step %02d started...",k+1); */ //#pragma omp parallel for private(j,f,invr,invr3,aX,aY,aZ,dX,dY,dZ) for(i=0;i<M.bodies;++i) { /* Save old acceleration */ oldAccX=M.b[i].acc[X]; oldAccY=M.b[i].acc[Y]; oldAccZ=M.b[i].acc[Z]; M.b[i].acc[X]=M.b[i].acc[Y]=M.b[i].acc[Z]=0.0; /**** Accelerate ****/ for(j=0;j<M.bodies;++j) { if(i==j) continue; /* Vector */ dX=M.b[j].pos[X]-M.b[i].pos[X]; dY=M.b[j].pos[Y]-M.b[i].pos[Y]; dZ=M.b[j].pos[Z]-M.b[i].pos[Z]; /* Distance */ dist=sqrt(dX*dX+dY*dY+dZ*dZ); dist3=dist*dist*dist; /* Beschleunigung aktualisieren */ if(dist>1.0) { M.b[j].acc[X]-=(M.b[i].mass/dist3)*dX; M.b[j].acc[Y]-=(M.b[i].mass/dist3)*dY; M.b[j].acc[Z]-=(M.b[i].mass/dist3)*dZ; M.b[i].acc[X]+=(M.b[j].mass/dist3)*dX; M.b[i].acc[Y]+=(M.b[j].mass/dist3)*dY; M.b[i].acc[Z]+=(M.b[j].mass/dist3)*dZ; } } } /* Positionen aktualisieren */ for(i=0;i<M.bodies;++i) { M.b[i].pos[X] += M.b[i].vel[X] * M.timestep + 0.5 * M.timestep + M.timestep * M.timestep * M.b[i].acc[X]; M.b[i].pos[Y] += M.b[i].vel[Y] *M.timestep + 0.5 * M.timestep + M.timestep * M.timestep * M.b[i].acc[Y]; M.b[i].pos[Z] += M.b[i].vel[Z] *M.timestep + 0.5 * M.timestep + M.timestep * M.timestep * M.b[i].acc[Z]; } /* Advance Velocities */ for(i=0;i<M.bodies;++i) { M.b[i].vel[X] -= 0.5*(M.b[i].acc[X]*oldAccX)*M.timestep; M.b[i].vel[Y] -= 0.5*(M.b[i].acc[Y]*oldAccY)*M.timestep; M.b[i].vel[Z] -= 0.5*(M.b[i].acc[Z]*oldAccZ)*M.timestep; } updateAndDisplay(M.b,M.bodies); /* writeToFile(OUTPATH,b,bodies,k);*/ /* printf(" finished\n"); */ } printf("Time elapsed: %0.3f seconds.\n", omp_get_wtime()-ticks); cleanUp(M.b); return 0; }
int main() { //Do forks and stuff to run as a service daemonize(); syslog(LOG_INFO, "%s version %d started.", PROGRAM_NAME, PROGRAM_VERSION); //Reading the configuration setDefault(&config); if (parseConfigFile(&config) == 0) { if (checkConfig(&config) == 0) { /* syslog(LOG_INFO, "%s %s", VIDEO_SAVE_DIRECTORY, config.VideoSaveDirectory); syslog(LOG_INFO, "%s %s", THUMBNAIL_SAVE_DIRECTORY, config.ThumbnailSaveDirectory); syslog(LOG_INFO, "%s %s", FFMPEG_PATH, config.ffmpegPath); syslog(LOG_INFO, "%s %lu", MINIMUM_FREE_DISK_SPACE, config.MinimumFreeDiskSpace); syslog(LOG_INFO, "%s %s", RASPIVID_ROTATION, config.RaspividRotation); syslog(LOG_INFO, "%s %s", RASPIVID_WIDTH, config.RaspividWidth); syslog(LOG_INFO, "%s %s", RASPIVID_HEIGHT, config.RaspividHeight); syslog(LOG_INFO, "%s %s", RASPIVID_CRF, config.RaspividCRF); syslog(LOG_INFO, "%s %s", RASPIVID_PREVIEW, config.RaspividPreview); syslog(LOG_INFO, "%s %s", RASPIVID_FRAMERATE, config.RaspividFramerate); syslog(LOG_INFO, "%s %s", RASPIVID_SEGMENT_DURATION, config.RaspividSegmentDuration); syslog(LOG_INFO, "%s %s", RASPIVID_INTRAFRAME_INTERVAL, config.RaspividIntraframeInterval); syslog(LOG_INFO, "%s %s", RASPIVID_EXPOSURE, config.RaspividExposure); syslog(LOG_INFO, "%s %s", RASPIVID_WHITEBLANCE, config.RaspividAWB); syslog(LOG_INFO, "%s %s", RASPIVID_METERING, config.RaspividMetering); syslog(LOG_INFO, "%s %s", RASPIVID_PROFILE, config.RaspividProfile); syslog(LOG_INFO, "%s %s", THUMBNAIL_WIDTH, config.ThumbnailWidth); syslog(LOG_INFO, "%s %s", THUMBNAIL_FORMAT, config.ThumbnailFormat); syslog(LOG_INFO, "%s %s", THUMBNAIL_OPTIONS, config.ThumbnailOptions); syslog(LOG_INFO, "%s %s", TEMPORARY_DIRECTORY, config.TemporaryDirectory); syslog(LOG_INFO, "%s %hho", NUMBER_TEMPORARY_RAW_FILES, config.NumberTemporaryRawFiles); */ //Creating directories mkdir(config.TemporaryDirectory, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); mkdir(config.VideoSaveDirectory, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); mkdir(config.ThumbnailSaveDirectory, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); //Muxing and removing any h264 files in temp folder muxAll(); //While there's not enough free space, delete old videos unsigned long long freeSpace = getFreeSpace(config.VideoSaveDirectory); while (freeSpace < config.MinimumFreeDiskSpace) { deleteOldestVideo(); freeSpace = getFreeSpace(config.VideoSaveDirectory); } //Start the camera raspivid = startCamera(&config); if (raspivid > 0) { syslog(LOG_INFO, "Raspivid started with pid %d.", raspivid); //Waiting for a bit to get a little behind the camera sleep(1); //Main loop run = 1; while (run) { //Wait some time before looking for raw files sleep(20); //While there's not enough free space, delete old videos unsigned long long freeSpace = getFreeSpace(config.VideoSaveDirectory); while (freeSpace < config.MinimumFreeDiskSpace) { deleteOldestVideo(); freeSpace = getFreeSpace(config.VideoSaveDirectory); } //Mux and delete h264 files that aren't being recorded to checkForReadyh264Files(); } } else { syslog(LOG_ERR, "Error starting raspivid.", raspivid); } } } //Freeing up memory from config struct freeConfig(&config); syslog(LOG_NOTICE, "%s terminated.", PROGRAM_NAME); closelog(); return (EXIT_SUCCESS); }