int main(int argc, char **argv){ static char fname[] = "main()"; char *pMethodName = NULL; char *pMethodDir = NULL; char *pIsOutput = NULL; char *pJobID = NULL; char *presAcctFN = NULL; char resAcctFN[MAXFILENAMELEN]; char echkpntProgPath[MAXPATHLEN]; char *pChkpntDir = NULL; pid_t iChildPid; LS_WAIT_T iStatus; char *cargv[MAX_ARGS]; int argIndex = 0; int cc; int iReValue; char *jf, *jfn; while ((cc = getopt(argc, argv, "cfksd:Vhx")) != EOF ){ switch(cc){ case 'c': case 'f': case 'k': case 'x': case 's': break; case 'V': fputs(_LS_VERSION_, stderr); exit(0); case 'd': pChkpntDir = optarg; break; case 'h': usage(argv[0]); exit(0); default: usage(argv[0]); exit(-1); } } if (pChkpntDir == NULL){ usage(argv[0]); exit(-1); } if (access(pChkpntDir,W_OK | X_OK) < 0){ fprintf(stderr,"%s : the chkpnt dir %s can not be accessed\n", fname,pChkpntDir); exit(-1); } iReValue = fileIsExist(pChkpntDir); if (iReValue == 1){ pMethodName = getEchkpntVar(ECHKPNT_METHOD); if ((pMethodName == NULL)||(strcmp(pMethodName,"") == 0)){ pMethodName = ECHKPNT_DEFAULT_METHOD; } pMethodDir = getEchkpntVar(ECHKPNT_METHOD_DIR); pIsOutput = getEchkpntVar(ECHKPNT_KEEP_OUTPUT); }else if (iReValue == 0) { initenv_(NULL,NULL); pMethodName = getenv(ECHKPNT_METHOD); if ((pMethodName == NULL)||(strcmp(pMethodName,"") == 0)){ pMethodName = ECHKPNT_DEFAULT_METHOD; } pMethodDir = getenv(ECHKPNT_METHOD_DIR); pIsOutput = getenv(ECHKPNT_KEEP_OUTPUT); { jf = getenv("LSB_JOBFILENAME"); if (jf == NULL) { fprintf(stderr, "%s : getenv of LSB_JOBFILENAME failed", fname); } else { jfn = strchr (jf, '/'); if (jfn) { sprintf(resAcctFN, "%s/.%s.acct",LSTMPDIR,jfn+1); presAcctFN = (char *) resAcctFN; } } } writeEchkpntVar(ECHKPNT_METHOD, pMethodName); writeEchkpntVar(ECHKPNT_METHOD_DIR, pMethodDir); writeEchkpntVar(ECHKPNT_KEEP_OUTPUT,pIsOutput); writeEchkpntVar(ECHKPNT_ACCT_FILE,presAcctFN); }else{ fprintf(stderr, "%s : the .echkpnt file content occurs error: %s\n",fname,strerror(errno)); exit(-1); } if ((pIsOutput != NULL)&&((strcmp(pIsOutput,ECHKPNT_OPEN_OUTPUT) == 0) ||(strcmp(pIsOutput,ECHKPNT_OPEN_OUTPUT_L) == 0))) { initLog("Echkpnt"); } #ifdef DEBUG sprintf(logMesgBuf,"%s : the LSB_ECHKPNT_METHOD = %s\n",fname,pMethodName); logMesg(logMesgBuf); sprintf(logMesgBuf,"%s : the LSB_ECHKPNT_METHOD_DIR = %s\n",fname,pMethodDir != NULL?pMethodDir : ""); logMesg(logMesgBuf); #endif if (getEchkpntMethodDir(echkpntProgPath, pMethodDir, ECHKPNT_PROGRAM, pMethodName) == NULL){ sprintf(logMesgBuf, "%s : the echkpnt method(%s) path is not correct\n",fname,pMethodName); goto Error; } #ifdef DEBUG sprintf(logMesgBuf,"%s : the echkpntProgPath is : %s\n",fname,echkpntProgPath); logMesg(logMesgBuf); #endif for(argIndex = 0;argIndex < argc; argIndex++){ cargv[argIndex] = argv[argIndex]; } cargv[argIndex] = NULL; if (strcmp(pMethodName, ECHKPNT_DEFAULT_METHOD) == 0){ cargv[0] = "echkpnt.default"; freeTable_(); #ifdef DEBUG logMesg("the echkpnt.default will be executed\n"); #endif closeLog(); execv(echkpntProgPath, cargv); sprintf(logMesgBuf,"%s : execute the echkpnt.default fail\n%s\n",fname, (errno? strerror(errno):"")); fprintf(stderr,"%s",logMesgBuf); exit(-1); } iChildPid = fork(); if (iChildPid < 0){ sprintf(logMesgBuf, "%s : fork() fork a child process fail...\n",fname); goto Error; }else if (iChildPid == 0){ long lMaxfds; int ii; char progName[MAXFILENAMELEN]; sprintf(logMesgBuf,"erestart.%s",pMethodName); setMesgHeader(logMesgBuf); if ((pIsOutput == NULL) || ((strcmp(pIsOutput,ECHKPNT_OPEN_OUTPUT) != 0) &&(strcmp(pIsOutput,ECHKPNT_OPEN_OUTPUT_L) != 0))){ if (redirectFd(ECHKPNT_DEFAULT_OUTPUT_FILE, 1) == -1){ sprintf(logMesgBuf, "%s : redirect stdout to %s file\n%s\n", fname, ECHKPNT_DEFAULT_OUTPUT_FILE, errno? strerror(errno) : ""); goto Error; } if (redirectFd(ECHKPNT_DEFAULT_OUTPUT_FILE, 2) == -1){ sprintf(logMesgBuf, "%s : redirect stderr to %s file\n%s\n", fname, ECHKPNT_DEFAULT_OUTPUT_FILE, errno? strerror(errno) : ""); goto Error; } }else{ char aFileName[MAXPATHLEN]; if ((getChkpntDirFile(aFileName, ECHKPNT_STDOUT_FILE) == -1) || (redirectFd(aFileName,1) == -1)){ sprintf(logMesgBuf,"%s : redirect the stdout to %s fail\n", fname,ECHKPNT_STDOUT_FILE); logMesg(logMesgBuf); if (redirectFd(ECHKPNT_DEFAULT_OUTPUT_FILE, 1) == -1){ sprintf(logMesgBuf, "%s : redirect stdout to %s file fail\n%s\n", fname, ECHKPNT_DEFAULT_OUTPUT_FILE, errno? strerror(errno) : ""); goto Error; } } if ((getChkpntDirFile(aFileName, ECHKPNT_STDERR_FILE) == -1) || (redirectFd(aFileName,2) == -1)){ sprintf(logMesgBuf,"%s : redirect the stderr to %s fail\n", fname,ERESTART_STDERR_FILE); logMesg(logMesgBuf); if (redirectFd(ECHKPNT_DEFAULT_OUTPUT_FILE, 2) == -1){ sprintf(logMesgBuf, "%s : redirect stderr to %s file fail\n%s\n", fname, ECHKPNT_DEFAULT_OUTPUT_FILE, errno? strerror(errno) : ""); goto Error; } } } lMaxfds = sysconf(_SC_OPEN_MAX); for (ii = 3; ii < lMaxfds; ii++){ close(ii); } sprintf(progName,"%s.%s",ECHKPNT_PROGRAM,pMethodName); cargv[0] = progName; freeTable_(); execv(echkpntProgPath,cargv); sprintf(logMesgBuf, "%s : the child process execute the %s fail\n",fname,progName); fprintf(stderr,"%s",logMesgBuf); logMesg(logMesgBuf); closeLog(); exit(-1); } while ((iChildPid = waitpid(iChildPid, &iStatus, 0)) < 0 && errno == EINTR); if (iChildPid < 0 ){ sprintf(logMesgBuf, "%s : %s fail, \n%s\n", fname, "waitpid", errno? strerror(errno) : ""); goto Error; }else{ if (WEXITSTATUS(iStatus) != 0) { sprintf(logMesgBuf, "%s : the echkpnt.%s fail,the exit value is %d\n", fname, pMethodName,WEXITSTATUS(iStatus)); fprintf(stderr,"%s",logMesgBuf); logMesg(logMesgBuf); freeTable_(); closeLog(); exit(WEXITSTATUS(iStatus)); } } pJobID = getenv(ECHKPNT_JOBID); if (pJobID == NULL){ writeEchkpntVar(ECHKPNT_OLD_JOBID,""); sprintf(logMesgBuf,"%s : getenv() can not get the env variable LSB_JOBID\n",fname); logMesg(logMesgBuf); }else{ writeEchkpntVar(ECHKPNT_OLD_JOBID, pJobID); } freeTable_(); closeLog(); exit(0); Error: fprintf(stderr,"%s",logMesgBuf); logMesg(logMesgBuf); freeTable_(); closeLog(); exit(-1); }
int main(int argc, char **argv) { char AgencyID[B2B_AGENCYID_SIZE+1]; char Mode; B2B_STATINFO_T *Data = NULL; CONFIG_T Config; int FetchedCount = 0; char LogPath[256]; double start_time=0, end_time=0; double real_time = 0; struct timeval tp_start; struct timeval tp_end; int ErrorCode = NO_ERROR; Q_ENTRY *req = qCgiRequestParse(NULL, (Q_CGI_T) 0); gettimeofday(&tp_start, 0); // Set Random Value srand(tp_start.tv_usec); memset(AgencyID, 0, B2B_AGENCYID_SIZE+1); ReadConfig(CONFIGFILE_PATH, &Config); sprintf(LogPath, "%s/%s", Config.LOG_PATH, LOG_NAME_SEARCHPRODUCTSTAT); SvcLog = openLog("SearchProductStatInfo", LogPath, LOG_MODE); sprintf(LogPath, "%s/%s", Config.LOG_PATH, LOG_NAME_SEARCHPRODUCTSTAT_DEB); Log = openLog("SearchProductStatInfo", LogPath, LOG_MODE); sprintf(LogPath, "%s/%s", Config.LOG_PATH, LOG_NAME_STATISTICS); StatLog = openLog("SearchProductStatInfo", LogPath, LOG_MODE); if((ErrorCode = Connect2DB(Config)) == NO_ERROR) { if((ErrorCode = GetParamsReqStatInfo(req, AgencyID, &Mode)) == NO_ERROR) { if((Data = DB_SelectProductStatInfo(AgencyID, &FetchedCount, &ErrorCode)) != NO_ERROR) { printLog(HEAD, "Search Error...ErrorCode(%d)\n", ErrorCode); } } else { printLog(HEAD, "Invalid Paramters Error...(%d)\n", ErrorCode); } } else { printLog(HEAD, "DBConnection Error...(%d)\n", ErrorCode); } if(Mode == 'T') { qCgiResponseSetContentType(req, "text/html"); PrintResultProductStatInfoWithTable(ErrorCode, AgencyID, Data, FetchedCount); } else { qCgiResponseSetContentType(req, "application/json;charset=euc-kr"); PrintResultProductStatInfo(ErrorCode, AgencyID, Data, FetchedCount); } if(Data != NULL) free(Data); DisConnectDB(); gettimeofday(&tp_end, 0); start_time = (double)tp_start.tv_sec + (double)tp_start.tv_usec/1000000; end_time = (double)tp_end.tv_sec + (double)tp_end.tv_usec/1000000; real_time = end_time - start_time; printLog(STAT_HEAD, "SEARCH_PRODUCT_S %d %4.6f\n", ErrorCode, real_time); printLog(HEAD, "---------------------------------------------------------------\n"); closeLog(SvcLog); closeLog(Log); closeLog(StatLog); return 0; }
/// Destructor CallStateEventWriter_DB::~CallStateEventWriter_DB() { closeLog(); }
int main(){ Uavcam *camera; bool camera_ok, frame_ok; int n_saved; std::stringstream filename; std::stringstream directory; std::vector<int> jpg_params; cv::Mat frame, preview; parseConfig(); jpg_params.push_back(CV_IMWRITE_JPEG_QUALITY); jpg_params.push_back(90); //Set Signals std::signal(SIGINT,exit_signal); //Set up Ctrl+C signal //Construct Cameras if (cameratype == 1){ #ifdef USE_ARAVIS camera = new AravisCam(); std::cout<<"Using Aravis camera"<<std::endl; #else camera = new WebCam(); #endif } if(view) cv::namedWindow("Camera Viewer", cv::WINDOW_AUTOSIZE); n_saved = checkLog(); //Check the log and open it openLogtoWrite(n_saved); ublox = new Gps(); //Initialize the GPS std::thread gps_thread(gpsUpdate); //clock_gettime(CLOCK_MONOTONIC, &start); camera_ok = camera->initializeCam(); //Initialize the camera //clock_gettime(CLOCK_MONOTONIC, &end); if (camera_ok) { std::cout << "Start camera acquisition in " << start_delay << " seconds" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(start_delay)); while(!finish){ //--Main Acquisition Loop filename.str(""); directory.str(""); //Update filenames filename<<"im"<<std::setfill('0')<<std::setw(4)<<++n_saved<<".jpg"; directory<<FOLDER<<filename.str(); frame_ok = camera->trigger(frame); //Send camera trigger if (usegps){ if(ublox->data_is_good) std::cout<<"GPS up to date"<<std::endl; else std::cout<<"No GPS available" <<std::endl; } mtx.lock(); writeImageInfo(ublox->current_loc, filename.str()); //Record GPS mtx.unlock(); //frame_ok = camera->getImage(frame); //Acquire the image if(frame_ok){ //Acquired Image cv::resize(frame,preview,cv::Size(),sizefac,sizefac,cv::INTER_NEAREST); if(saveimg) { cv::imwrite(directory.str(), preview, jpg_params); std::cout<<"Saved to " << filename.str() <<std::endl; } if(view) { cv::imshow("Camera Viewer", preview); cv::waitKey(50); } } std::this_thread::sleep_for(std::chrono::milliseconds(250)); } //Finished photographing delete camera; } gps_thread.join(); closeLog(); return 0; }