int main(int argc, char *argv[]) { security_context_t scon = NULL; cmd_line(argc, argv); scon = get_scon(); disp_con(scon); freecon(scon); exit(EXIT_SUCCESS); }
static void delete_function() { char *str = XmTextGetString(function_name); int warn = !!ison(glob_flags, WARNINGS); ask_item = function_name; turnon(glob_flags, WARNINGS); (void) cmd_line(zmVaStr("\\function -d %s", str), NULL_GRP); if (!warn) turnoff(glob_flags, WARNINGS); XtFree(str); XmTextSetString(function_name, NULL); XmTextSetString(script_input, NULL); }
/*Lida com sinais*/ void handle_signal(int signum){ puts(""); if (childfgpid && !empty){ /*ctrl-c*/ if (signum == SIGINT){ killpg(childfgpid, SIGINT); signal(SIGINT, handle_signal); } /*ctrl-z*/ else if (signum == SIGTSTP){ killpg(childfgpid, SIGTSTP); adicionajob(childfgpid, childname, 2); signal(SIGTSTP, handle_signal); } else printf("Sinal %d desconhecido\n", signum); } /*Lida com stdout*/ if (empty) cmd_line(); else empty=1; fflush(stdout); }
/* * Attempt to simulate fork/execve on Windows */ int openvpn_execve (const struct argv *a, const struct env_set *es, const unsigned int flags) { int ret = -1; if (a && a->argv[0]) { if (openvpn_execve_allowed (flags)) { if (script_method == SM_EXECVE) { STARTUPINFO start_info; PROCESS_INFORMATION proc_info; char *env = env_block (es); char *cl = cmd_line (a); char *cmd = a->argv[0]; CLEAR (start_info); CLEAR (proc_info); /* fill in STARTUPINFO struct */ GetStartupInfo(&start_info); start_info.cb = sizeof(start_info); start_info.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; start_info.wShowWindow = SW_HIDE; start_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE); start_info.hStdOutput = start_info.hStdError = GetStdHandle(STD_OUTPUT_HANDLE); if (CreateProcess (cmd, cl, NULL, NULL, FALSE, 0, env, NULL, &start_info, &proc_info)) { DWORD exit_status = 0; CloseHandle (proc_info.hThread); WaitForSingleObject (proc_info.hProcess, INFINITE); if (GetExitCodeProcess (proc_info.hProcess, &exit_status)) ret = (int)exit_status; else msg (M_WARN|M_ERRNO, "openvpn_execve: GetExitCodeProcess %s failed", cmd); CloseHandle (proc_info.hProcess); } else { msg (M_WARN|M_ERRNO, "openvpn_execve: CreateProcess %s failed", cmd); } free (cl); free (env); } else if (script_method == SM_SYSTEM) { configure_win_path (); ret = openvpn_system (argv_system_str (a), es, flags); } else { ASSERT (0); } } else { msg (M_WARN, SCRIPT_SECURITY_WARNING); } } else { msg (M_WARN, "openvpn_execve: called with empty argv"); } return ret; }
int main(int argc, char *argv[]) { char **childargv = NULL; int child_return = 99; int lockfd; struct flock flock_struct; int lockfd_flags; int pip[2] = {0, 0}; /* used for error checking in async mode */ cmdname = argv[0]; if (argc < 2) { usage(); } /* * * Command line parsing * */ childargv = cmd_line(argc, argv); /* * * Open the file * */ lockfd = open(lockfile, openmode, 0600); if (lockfd == -1) { error("Can't open lockfile \"%s\": %s\n", lockfile, strerror(errno)); } /* * * Set the Close on Exec flag * */ if (fork_mode) { lockfd_flags = fcntl(lockfd, F_GETFD); lockfd_flags |= FD_CLOEXEC; fcntl(lockfd, F_SETFD, lockfd_flags); } /* * * fork() for async mode * */ if (async) { async_fork(pip); } /* * * get the exclusive lock * */ flock_struct.l_type = F_WRLCK; flock_struct.l_whence = SEEK_SET; flock_struct.l_start = 0; flock_struct.l_len = 0; if (fcntl(lockfd, lockmode, &flock_struct) == -1) { /* POSIX allows eigther EAGAIN or EACCES to say it's locked if the file is really not accessible, the open call above has already failed with EACCES */ if ((lockmode == F_SETLK) && (errno == EAGAIN || errno == EACCES)) { /* nonblocking failed */ notifyAsyncParent(pip[1], FAIL_EXITCODE_NB); exit(FAIL_EXITCODE_NB); } if (lockmode == F_GETLK) { /* test mode */ error("Can't get lock information on \"%s\": %s\n", lockfile, strerror(errno)); } error("Can't get exclusive lock on \"%s\": %s\n", lockfile, strerror(errno)); } /* * * do the work (execute the command) * */ if (! test_mode && ! noop_mode) { child_return = mk_child(fork_mode, pip[1], childargv); } else if (test_mode) { /* test mode */ if (flock_struct.l_type == F_UNLCK) { child_return = 0; } else { printf("%ld\n", (long)flock_struct.l_pid); child_return = FAIL_EXITCODE_NB; } } else { /* noop_mode, just return ok */ child_return = 0; } if (! test_mode) { /* * * unlock * */ flock_struct.l_type = F_WRLCK; flock_struct.l_whence = SEEK_SET; flock_struct.l_start = 0; flock_struct.l_len = 0; fcntl(lockfd, F_SETLKW, &flock_struct); /* errors?? -> bad luck */ } /* * * close the lockfile * */ close(lockfd); exit(child_return); }
int main(int argc, char **argv) { /**************************************************************/ /************************** FROM previous version CVBoardTypes VMEBoard; short Device=0; short Link=0; int32_t BHandle; VMEBoard=cvV1718; Device=0; if (CAENVME_Init( VMEBoard, Link, Device, &BHandle) != cvSuccess){ printf("error opening the device\n%s",""); //exit(1); } **************************************************/ // if (argc<=1){printf("%s\n"," ... consider \" ./gregory -r /tmp/lockfile\" for gregory.net");} ///////////////////////////////////// lockfile from argument (.net) char lockfile[180]=""; Targs args; parse_arguments(argc,argv, &args);//in main=normal var, outsourced with if (args.rvalue!=NULL){strncpy( lockfile , args.rvalue, 180 );} printf( "lockfile is ... %s\n", lockfile ); // ENVIRONMENT------------- // char* BinPath, *DataPath; BinPath = getenv ("GREGORY"); if (BinPath==NULL){ BinPath=new char[2]; strcpy(BinPath, "./"); } DataPath = getenv ("GREGORY_DATA"); if (DataPath==NULL){ DataPath=new char[2]; strcpy(DataPath, "./"); } // printf("%s\n"," export GREGORY="); // printf("%s\n"," export GREGORY_DATA="); // printf("%s\n",""); printf("%s\n",""); printf( "binary path: %s (not used yet...)\n",BinPath ); printf( "data path: %s\n",DataPath ); for (int ch=0;ch<8;ch++){ WaveBinfh[ch]=NULL; } // FILL THE TABLE OF FUNCTIONS ===========================TABLE int ic=0; sprintf( compile_table[ic].name, "%s", "get_status" ); compile_table[ic].addr=(functiontype_i)&vme_get_stat_reg; ic++; sprintf( compile_table[ic].name, "%s", "get_version" ); compile_table[ic].addr=(functiontype_i)&vme_get_version; ic++; /* sprintf( compile_table[ic].name, "%s", "v1718_control" ); compile_table[ic].addr=(functiontype_i)&v1718_control; ic++; */ //----------------------------------------------------- // printf("\nlist of known functions\n%s" , ""); // for (icc=0;icc<ic;icc++){ // printf( " %s\n", compile_table[icc].name ); // } printf("%50c\n",'-'); // END OF TABLE ==========================================TABLE mmap_file=create_shared_memory( 1, "vme" ); mmap_file2=create_shared_memory( 1, "vmeOUT" ); mmap_fileS=create_shared_memory( 2, "socket" ); mmap_fileO=create_shared_memory( 3, "oscilo" ); mmap_fileC=create_shared_memory( 4, "counter" ); /* //====================================== MMAP ====== communication system("dd if=/dev/zero of=mmap.in bs=4096 count=1 2> /dev/null"); if ((mmapfd = open("mmap.in", O_RDWR, 0)) == -1) err(1, "open"); mmap_file=(char*)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, mmapfd, 0); if (mmap_file == MAP_FAILED) errx(1, "either mmap"); strcpy(mmap_file, "... this is an initial input.\0\0\0" ); // "acq_setup.xml\nrun=1\n"; //====================================== MMAP ====== communication //====================================== MMAP ====== communication system("dd if=/dev/zero of=mmap.out bs=4096 count=1 2> /dev/null"); if ((mmapfd2 = open("mmap.out", O_RDWR, 0)) == -1) err(1, "open"); mmap_file2=(char*)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, mmapfd2, 0); if (mmap_file2 == MAP_FAILED) errx(1, "either mmap2"); strcpy(mmap_file2, "... no output at the moment...\0\0\0" ); // "acq_setup.xml\nrun=1\n"; //====================================== MMAP ====== communication //====================================== MMAP ====== communication server sock system("dd if=/dev/zero of=mmap.socket bs=4096 count=1 2> /dev/null"); if ((mmapfdS = open("mmap.socket", O_RDWR, 0)) == -1) err(1, "open"); mmap_fileS=(char*)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, mmapfdS, 0); if (mmap_fileS == MAP_FAILED) errx(1, "either mmapS"); strcpy(mmap_fileS, "...................o=ok;X=error...\0\0\0" ); // "acq_setup.xml\nrun=1\n"; //====================================== MMAP ====== communication //====================================== MMAP ====== communication server OSCILO system("dd if=/dev/zero of=mmap.oscilo bs=4096 count=1 2> /dev/null"); if ((mmapfdO = open("mmap.oscilo", O_RDWR, 0)) == -1) err(1, "open"); mmap_fileO=(char*)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, mmapfdO, 0); if (mmap_fileO == MAP_FAILED) errx(1, "either mmapS"); strcpy(mmap_fileO, ".......no command to Oscilo...\0\0\0" ); // "acq_setup.xml\nrun=1\n"; //====================================== MMAP ====== communication */ /* //====================================== MMAP ====== communication 4MB char cmd3[100]; char fname3[100]; sprintf( cmd3,"dd if=/dev/zero of=%s/mmap.histo bs=4096 count=1024 2> /dev/null", DataPath ); sprintf( fname3, "%s/mmap.histo", DataPath ); system( cmd3); if ((mmapfd3 = open( fname3, O_RDWR, 0)) == -1) err(1, "open"); mmap_file3=(char*)mmap(NULL, 4194304 , PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, mmapfd3, 0); if (mmap_file3 == MAP_FAILED) errx(1, "either mmap3"); */ // strcpy(mmap_file3, "... no output at the moment...\0\0\0" ); // "acq_setup.xml\nrun=1\n"; //====================================== MMAP ====== communication //===========histogram array //http://root.cern.ch/root/roottalk/roottalk01/3614.html //hclus[9] = new TH1F("name","descr",100,0,1000); hclus[9]->Fill(1); //- BIG TRICK with allocation. We pray 4MB isok // OBJECTS have to do TMapFile ... virtual classes etc. //TH1F **harray; // harray=new(mmap_file3) TH1F*[8]; //http://root.cern.ch/root/html/TMapFile.html#TMapFile:Add //http://root.cern.ch/root/roottalk/roottalk98/2340.html //http://root.cern.ch/root/roottalk/roottalk04/0352.html //http://root.cern.ch/root/roottalk/roottalk04/0341.html // initialize threads................................ALLOCATE tinfo = (thread_info *)calloc(NTHREADS , sizeof(thread_info) ); if (tinfo == NULL) {printf("calloc failed%s\n", "");return 1;} for (int tnum = 0; tnum < NTHREADS; tnum++) {tinfo[tnum].thread_num=-1;} //==========================================CORE int cmd_param[100]; //set of parameters// minimum 10! int i=0; // CMD counter int res; printf("\n.h for help\n\n%s", ""); //---------------------infinite loop ---------------------------- char prefix[20]=" "; char posfix[20]="..."; while(1==1){ i++; usleep(100*1000); // 50ms is enough to finish thread.. cmd_line( i ); // shows PROMPT; reads INPUT to cmd_buffer; res=get_cmd_name( cmd_param );// 1=quit; 2=list if (res != 0 ){ // .n newrun? .r runnumber! .ls ! // .s status .l LOAD! .s save .c comment .f file .n numberrun ?? // filename send with 'start (maybe run and file commands before)' if ( strcmp(cmd_buffer,".q")==0 ){ //.q printf("%s quitting %s\n", prefix, posfix ); global_flag_quit=-1; // only LOOP itself strcpy(mmap_file,"quit\0"); // send it to gregory.mmap strcpy(mmap_fileO,"quit\0"); // send it oscilo // strcpy(mmap_fileS,"quit\0"); // send it oscilo strcpy(mmap_fileC,"quit\0"); // send it oscilo // i will need to shutdown the socket int socket_fd=atoi(mmap_fileS); // get (slowly) handle shutdown( socket_fd, 2 ); break; // BREAK FROM WHILE 1==1 .... quit } // .q if ( strcmp(cmd_buffer,".s")==0 ){ //.s if ( mmap_fileS[16] == 'o' ){ int socket_fd=atoi(mmap_fileS); // bad trick -get handle printf("%s socket %d port %s %s\n", prefix,socket_fd,PORT,posfix); // sprintf(outline,"%d %d %d\n%c", 1, 2 ,3 , '\0'); int socker[3]; // 32 bit ZH data for socket e0000001 e0010123 0xf0000000 socker[0]=0xe0010000; socker[1]=0x000100ff; // socker[2]=0x0001; //channel // socker[3]=0x00ff; //value socker[2]=0xf0000000; // socker[5]=0x0000; // int tmp=send(socket_fd, outline, strlen(outline), 0 ); int tmp=send(socket_fd, socker, sizeof(socker), 0 ); if (tmp < 0){ printf(" !...socket error ... i block mmap.socket from now\n"); mmap_fileS[16] = 'X'; //shutdown( socket_fd, 2 ); } }else{ // socked_fd blocked [16]==X not "o" printf(" !...socket blocked due to ealier error%s\n",""); } } // .s //--- exact match strcmp //--- strstr means line start match if ( strstr(cmd_buffer,".r")==cmd_buffer ){ // .r RUN number char oldr[70]; int newri=1; char cmdls[200]; sprintf( cmdls,"ls -1tr %s | grep run | grep \\.dat |tail -1 | awk -F _ '{sub(\"run\",\"\");print $1}' > RUNNUM ", DataPath ); system(cmdls); sprintf( cmdls,"ls -ltrh %s/run*.dat 2>/dev/null | tail -1 | awk '{print $9,\" \",$5}' > RUNNAMELAST ", DataPath ); system(cmdls); sprintf( cmdls,"ls -tr1 %s| grep -ie '^run[0-9]' | sed 's/run0*//' | cut -d. -f 1 | cut -d _ -f 1 | sort -n | tail -1 > RUNNEXT ", DataPath ); system(cmdls); //============= read ll -h output with size ========== FILE *frn=fopen("RUNNAMELAST","r"); if (frn!=NULL){ memset(&oldr[0], 0, sizeof(oldr)); fread( oldr, 1, sizeof(oldr), frn ); oldr[ strlen(oldr)-1 ]='\0'; fclose(frn); printf("%s ... LAST SAVED ON DISK\n", oldr ); } //---------------------------------- frn=fopen("RUNNUM","r"); if (frn!=NULL){ fread( oldr, 1, sizeof(oldr), frn ); fclose(frn); if ( strlen(oldr)>0){ sscanf(oldr,"%d", &newri ); //from oldr => newri printf("CURR /on disk/ RUN =%5d\n", newri ); //printf("NEXT proposed RUN =%5d\n", newri+1 ); } }//no RUNNUM file //----------------------------- frn=fopen("RUNNEXT","r"); if (frn!=NULL){ fread( oldr, 1, sizeof(oldr), frn ); fclose(frn); if ( strlen(oldr)>0){ sscanf(oldr,"%d", &newri ); //from oldr => newri // printf("CURR /on disk/ RUN =%5d\n", newri ); printf("NEXT proposed RUN =%5d\n", newri+1 ); }else{ newri=1;} }//no RUNNUM file //----------------------------- printf("%s to change the run number use run x %s\n",prefix,posfix); printf("%s run 0 ... means no data file %s\n",prefix,posfix); sprintf(cmdls,"run %d", newri+1 ); // strcpy( mmap_file, "run " ); strcpy( mmap_file, cmdls ); printf("%s run %d ... command was sent%s\n",prefix,newri+1, posfix); } // .r RUN NUMBER //means - '.ls' on the line start if ( strstr(cmd_buffer,".ls")==cmd_buffer ){ // .ls // printf("%s listing %s\n", prefix, posfix ); for (int tnum = 0; tnum < NTHREADS; tnum++) { if ( (tnum==0) && (tinfo[tnum].thread_num==1) ){ printf("[--M--] process %d (of %d): measurement thread ACTIVE\n", tnum+1, NTHREADS);} else if(tnum==0) { printf("[--M--] process %d (of %d): measurement thread NOT LOADED\n", tnum+1, NTHREADS);} if ( (tnum==1) && (tinfo[tnum].thread_num==2 )){ printf("[--M--] process %d (of %d): socket thread ACTIVE\n", tnum+1, NTHREADS);} else if(tnum==1) { printf("[--M--] process %d (of %d): socket thread NOT LOADED\n", tnum+1, NTHREADS);} if ( (tnum==2) && (tinfo[tnum].thread_num==3 )){ printf("[--M--] process %d (of %d): oscilo thread ACTIVE\n", tnum+1, NTHREADS);} else if(tnum==2) { printf("[--M--] process %d (of %d): oscilo thread NOT LOADED\n", tnum+1, NTHREADS);} if ( (tnum==3) && (tinfo[tnum].thread_num==4 )){ printf("[--M--] process %d (of %d): Countr thread ACTIVE\n", tnum+1, NTHREADS);} else if(tnum==3) { printf("[--M--] process %d (of %d): Countr thread NOT LOADED\n", tnum+1, NTHREADS);} /* if (tinfo[tnum].thread_num>0){ printf(" process %d (of %d): ACTIVE\n", tnum+1, NTHREADS); // printf(" file size %d MB\n", 0 ); }else{ if (tinfo[tnum].thread_num==1){ printf(" process %d (of %d): measurement thread NOT LOADED\n", tnum+1, NTHREADS);} else if (tinfo[tnum].thread_num==2){ printf(" process %d (of %d): socket thread NOT LOADED\n", tnum+1, NTHREADS);} else {printf(" process %d (of %d): socket thread NOT LOADED\n", tnum+1, NTHREADS);} } */ }// NTHREADS printf("[--M--] last message:\n %s\n", mmap_file2 ); char text[100]; time_t now = time(NULL); struct tm *t = localtime(&now); strftime(text, sizeof(text)-1, "%Y/%m/%d_%H:%M:%S ", t); printf("%s ...\n", text); fflush(stdin); global_flag_list=1; /* //======= THIS IS A WAY TO PRINT ON PORT 7777 ======= int socket_fd=atoi(mmap_fileS); if (socket_fd != -1) { if (send(socket_fd, "\nAHOJ\n" , 6, 0) == -1) perror("ls"); } */ } // .ls list............. if ( strcmp(cmd_buffer,".l")==0 ){ // .l LOAD // printf("%s LOADing %s\n", prefix, posfix ); int tnum, pth_res; for (tnum = 0; tnum < NTHREADS; tnum++) { if (tinfo[tnum].thread_num<0){ tinfo[tnum].thread_num = tnum + 1; // if (tnum==0){ pth_res = pthread_create(&tinfo[tnum].thread_id, NULL, &loop_thread, &tinfo[tnum] ); // } // if (tnum==1){ // pth_res = pthread_create(&tinfo[tnum].thread_id, NULL, // &loop_thread2, &tinfo[tnum] ); // } if ( pth_res != 0){printf("pthread_create failed%s\n","");return 1;} }// _num<0 == not active thread=> you can reload else{ printf("%s thread %d is already active== %d %s no action\n", prefix,tnum, tinfo[tnum].thread_num, posfix ); // printf(" thread %d is already active== %d (no action)\n", tnum, tinfo[tnum].thread_num); }// else already active }//for all threads } // .. LOAD /* if ( strcmp(cmd_buffer,".s")==0 ){ // .s LOAD SERVER */ /* printf("%s loading network Server %s\n", prefix, posfix ); */ /* int tnum, pth_res; */ /* for (tnum = 0; tnum < NTHREADS; tnum++) { */ /* if (tinfo[tnum].thread_num<0){ */ /* tinfo[tnum].thread_num = tnum + 1; */ /* pth_res = pthread_create(&tinfo[tnum].thread_id, NULL, */ /* &loop_thread, &tinfo[tnum] ); */ /* if ( pth_res != 0){printf("pthread_create failed%s\n","");return 1;} */ /* }// _num<0 == not active thread=> you can reload */ /* else{ */ /* printf("%s thread %d is already active== %d %s no action\n", prefix,tnum, tinfo[tnum].thread_num, posfix ); */ /* // printf(" thread %d is already active== %d (no action)\n", tnum, tinfo[tnum].thread_num); */ /* }// else already active */ /* }//for all threads */ /* } // .. LOAD SERVER */ if ( strcmp(cmd_buffer,".h")==0 ){ // .h // printf("%s help %s\n", prefix, posfix ); printf("%s .h %s help\n", prefix, posfix ); printf("%s .l %s LOAD ALL THREADS\n", prefix, posfix ); printf("%s .s %s TEST network server on port %s\n", prefix, posfix , PORT ); printf("%s .r %s look at run number\n", prefix, posfix ); printf("%s .ls %s list\n", prefix, posfix ); printf("%s .q %s QUIT\n", prefix, posfix ); printf("%s ------ %s measurement thread commands ------:\n" , prefix, posfix ); printf("%s qu %s quit \n" , prefix, posfix); printf("%s sta %s start \n" , prefix, posfix ); printf("%s te %s test = start +no save\n" , prefix, posfix ); printf("%s sto %s STOP \n" , prefix, posfix ); printf("%s sts %s status \n" , prefix, posfix ); printf("%s cl %s clear histo \n" , prefix, posfix ); printf("%s hi %s histogram (save histogram to txt) \n" , prefix, posfix ); printf("%s wa %s waveform (save waveform to txt,mmap) \n" , prefix, posfix ); //not used anymore printf("%s tr %s trigger \n" , prefix, posfix ); printf("%s in %s init \n" , prefix, posfix ); // printf("%s aon %s autosaveON \n" , prefix, posfix ); // printf("%s aof %s autosaveOFF\n" , prefix, posfix ); printf("%s won %s wavesaveON\n" , prefix, posfix ); printf("%s wof %s wavesaveOFF\n" , prefix, posfix ); printf("%s pd %s probe_down \n" , prefix, posfix ); printf("%s pu %s probe_up \n" , prefix, posfix ); printf("%s re %s restart \n" , prefix, posfix ); printf("%s don %s displayON \n" , prefix, posfix ); printf("%s dof %s displayOFF \n" , prefix, posfix ); } // .h ==============================================================HELP } // was an internal command============================== else{ if (DEBUGGREG>0) printf(" cmd_name=%s\n", cmd_name); // strcpy( mmap_file, cmd_buffer ); //command directly to mmap_file........ //translate to better phrases ..................... if (strstr(cmd_buffer,"qu")!=NULL) strcpy( mmap_file, "quit" ); if (strstr(cmd_buffer,"qu")!=NULL) strcpy( mmap_fileO, "quit" ); // if (strstr(cmd_buffer,"qu")!=NULL) strcpy( mmap_fileS, "quit" ); if (strstr(cmd_buffer,"qu")!=NULL) strcpy( mmap_fileC, "quit" ); if (strstr(cmd_buffer,"run")!=NULL) strcpy( mmap_file, cmd_buffer ); // send the number if (strstr(cmd_buffer,"sta")!=NULL) strcpy( mmap_file, "start" ); if (strstr(cmd_buffer,"sta")!=NULL) strcpy( mmap_fileO, "start" ); //Oscilo if (strstr(cmd_buffer,"sta")!=NULL) strcpy( mmap_fileC, "start" ); //Oscilo if (strstr(cmd_buffer,"te")!=NULL) strcpy( mmap_file, "test" ); //must do wa if (strstr(cmd_buffer,"te")!=NULL) strcpy( mmap_fileO, "test" ); //Oscilo if (strstr(cmd_buffer,"te")!=NULL) strcpy( mmap_fileC, "test" ); //Oscilo if (strstr(cmd_buffer,"go")!=NULL) printf(".. not programmed yet\n%s",""); if (strstr(cmd_buffer,"go")!=NULL) strcpy( mmap_fileO, "go" ); //Oscilo if (strstr(cmd_buffer,"go")!=NULL) strcpy( mmap_fileC, "go" ); //Oscilo if (strstr(cmd_buffer,"sto")!=NULL) strcpy( mmap_file, "STOP" ); if (strstr(cmd_buffer,"sto")!=NULL) strcpy( mmap_fileO, "stop" ); //Oscilo if (strstr(cmd_buffer,"sto")!=NULL) strcpy( mmap_fileC, "stop" ); //Oscilo if (strstr(cmd_buffer,"stat")!=NULL)strcpy( mmap_file, "status" ); if (strstr(cmd_buffer,"sts")!=NULL) strcpy( mmap_file, "status" ); if (strstr(cmd_buffer,"cl")!=NULL) strcpy( mmap_file, "clear" ); if (strstr(cmd_buffer,"hi")!=NULL) strcpy( mmap_file, "histogram" ); // not used anymore if (strstr(cmd_buffer,"wa")!=NULL) strcpy( mmap_file, "waveform" ); // ? is it? if (strstr(cmd_buffer,"tr")!=NULL) strcpy( mmap_file, "trigger" ); if (strstr(cmd_buffer,"in")!=NULL) strcpy( mmap_file, "init" ); //notused anymore ... autosave==1 if (strstr(cmd_buffer,"aon")!=NULL) strcpy( mmap_file, "autosaveON" ); if (strstr(cmd_buffer,"aof")!=NULL) strcpy( mmap_file, "autosaveOFF" ); //NOW autosave==111 ! wav file if (strstr(cmd_buffer,"won")!=NULL) strcpy( mmap_file, "wavesaveON" ); if (strstr(cmd_buffer,"wof")!=NULL) strcpy( mmap_file, "wavesaveOFF" ); if (strstr(cmd_buffer,"pd")!=NULL) strcpy( mmap_file, "probe_down" ); if (strstr(cmd_buffer,"pu")!=NULL) strcpy( mmap_file, "probe_up" ); if (strstr(cmd_buffer,"re")!=NULL) strcpy( mmap_file, "restart" ); if (strstr(cmd_buffer,"don")!=NULL) strcpy( mmap_file, "displayON" ); if (strstr(cmd_buffer,"dof")!=NULL) strcpy( mmap_file, "displayOFF" ); if (strstr(cmd_buffer,"ac")!=NULL) strcpy( mmap_fileO, "accumulateXMGR" ); // if (strstr(cmd_buffer,"")!=NULL) strcpy( mmap_file, "" ); // if (strstr(cmd_buffer,"")!=NULL) strcpy( mmap_file, "" ); // NO this would spam the output printf("%s\n", mmap_file2 ); fflush(stdin); /* for (icc=0;icc<ic;icc++){ */ /* if ( strcmp(cmd_name,compile_table[icc].name)==0){ */ /* if (DEBUGGREG>0) */ /* printf(" matches =%d\n", icc); */ /* compile_table[icc].addr( cmd_param[0] ); */ /* }//match */ /* } //for icc=0--- */ /* //PERFORM ON YOUR OWN */ }// else ===== real command }// INF.WHILE. //==========================================CORE // NOW QUITTING ROUTINES =========================== global_flag_quit=-1; // SEND SIGNAL TO THREAD printf("[##M##] ........master is waiting for threads\n");fflush(stdin); // printf("%s\n","------------------------------Thread-close-begin");fflush(stdin); for (int tnum = 0; tnum < NTHREADS; tnum++) { printf("[##M##]... waiting thread %d finish ...\n", tnum+1);fflush(stdin); int pth_res = pthread_join(tinfo[tnum].thread_id, NULL ); if (pth_res != 0){printf("pthread_join failed%s'\n",""); //exit(1); // if no thread => quit to socat doesnot work } printf("[##M##] master join : thread %d (of %d) arrived\n", tnum+1, NTHREADS); // tinfo[tnum].thread_num, NTHREADS); fflush(stdin); // printf("thread %d/%d\n", tnum+1, NTHREADS);fflush(stdin); } if (tinfo!=NULL){ free(tinfo);} printf("%s\n","------------------------------Thread-close-end");fflush(stdin); // REMOVE LOCKFILE IS EXISTT ******************************** // this is important to let the script know "gregory has ended" // ................................socat has a problem with kill if ( filexists(lockfile)==1 ) { printf("File %s exist\n", lockfile );fflush(stdin); if( remove( lockfile ) != 0 ){ perror( "Error deleting file" ); }else{ puts( "File successfully deleted" ); } } exit(0); }//===================================================================MAIN
/*------------------------------------------- | Name:tstlcd_main | Description: | Parameters: | Return Type: | Comments: | See: ---------------------------------------------*/ int tstlcd_main(int argc,char* argv[]){ int fd; char buf[CMD_MAX+1]; struct prsopt_t _prs_opt; struct opt_t* opt; char* __stdlcd=(char*)0; char* __stdin=(char*)0; int i; unsigned int _opt=0; int item = 0; int item_nb = 0; char value[6] = {0}; char blnk_value[6] = {0}; int blnk= -1; char restart=0; //get option for(i=1; i<argc; i++) { if(argv[i][0]=='-') { unsigned char c; unsigned char l=strlen(argv[i]); for(c=1; c<l; c++) { switch(argv[i][c]) { case 'i': _opt |= OPT_MSK_I; if(argv[i][c+1]) break; if(argv[i+1][0]=='-') break; i++; if(!argv[i]) break; __stdin = argv[i]; break; case 'o': _opt |= OPT_MSK_O; if((i+1) == argc) //not enough parameter return -1; if(argv[i][c+1]) break; i++; if(argv[i]) __stdlcd = argv[i]; break; } } } } if(!__stdlcd) { fprintf(stderr,"error: lcd dev not defined\r\n"); return -1; } // if(__stdin) { close(STDIN_FILENO); if((fd=open(__stdin,O_RDONLY,0))<0) { fprintf(stderr,"error: cannot open %s\r\n",argv[i]); return -1; } } // fd=open(__stdlcd,O_WRONLY,0); if(fd<0) { printf("error: cannot open %s\r\n",__stdlcd); return -1; } // for(;; ) { long t_timeout=0; if(!(_opt&OPT_MSK_I)) { //printf(prompt); write(1,prompt,sizeof(prompt)-1); if(cmd_line(buf,CMD_MAX)<=0) return 0; }else{ x_cmd_line(buf,CMD_MAX); } blnk =0; opt= prsopt(&_prs_opt,buf,"aivblrmt!"); while(opt) { //printf("o=%c v=%s\r\n",opt->opt,opt->v); switch(opt->opt) { case 'i': { //item item = atoi(opt->v); } break; case 'v': //value { int i=0; item_nb = 0; memset(value,-1,sizeof(value)); while( (opt->v[i]!='\0') && (item_nb<sizeof(value)) ) { if(opt->v[i+1]=='.') { value[item_nb]=opt->v[i]-48+10; //add point segment i++; }else if( (opt->v[i]>=48) && (opt->v[i]<=57)) { value[item_nb] = opt->v[i]-48; }else if( (opt->v[i]>=65) && (opt->v[i]<=90)) { value[item_nb] = opt->v[i]-46; }else if( (opt->v[i]>=97) && (opt->v[i]<=122)) { value[item_nb] = opt->v[i]-77; }else if(opt->v[i]=='^') { value[item_nb] = opt->v[i]-48; //46 }else if(opt->v[i]=='-') { value[item_nb] = opt->v[i]+2; //47 }else if(opt->v[i]=='_') { value[item_nb] = opt->v[i]-47; //48 }else if(opt->v[i]=='*') { value[item_nb] = -1; }else{ value[item_nb] = 0; } item_nb++; i++; } } break; case 'b': //blink blnk = atoi(opt->v); break; case 'a': { //set/clr all item char setclr = 1; //1) reset blink lseek(fd,(off_t)514,SEEK_SET); write(fd,(char*)&setclr,1); //2)set or clr all item setclr = atoi(opt->v); lseek(fd,(off_t)512,SEEK_SET); write(fd,(char*)&setclr,1); } break; case 'l': { //backlight on/off char bckl = atoi(opt->v); lseek(fd,(off_t)513,SEEK_SET); write(fd,(char*)&bckl,1); } break; case 'r': { //reset blink char r_blnk = atoi(opt->v); if(!r_blnk) break; lseek(fd,(off_t)514,SEEK_SET); write(fd,(char*)&r_blnk,1); } case 't': { //timeout delay t_timeout = atol(opt->v)*1000L; //ms } break; case '!': { //restart script restart=1; } break; } //next option opt= prsopt(&_prs_opt,0,"ivbt!"); } // lseek(fd,(off_t)item,SEEK_SET); //110 win32, 200 m16c write(fd,value,item_nb); if(blnk>0) { memset(blnk_value,1,item_nb); lseek(fd,(off_t)(item+256),SEEK_SET); //110 win32, 200 m16c write(fd,blnk_value,item_nb); }else if(!blnk) { memset(blnk_value,0,item_nb); lseek(fd,(off_t)(item+256),SEEK_SET); //110 win32, 200 m16c write(fd,blnk_value,item_nb); } if(t_timeout) usleep(t_timeout); if(restart) lseek(0,0,SEEK_SET); blnk = -1; restart=0; } close(fd); return 0; }