Example #1
0
void lvmnotify_send(struct cmd_context *cmd)
{
	static const char _dbus_notification_failed_msg[] = "D-Bus notification failed";
	sd_bus *bus = NULL;
	sd_bus_message *m = NULL;
	sd_bus_error error = SD_BUS_ERROR_NULL;
	const char *cmd_name;
	int ret;
	int result = 0;

	if (!cmd->vg_notify && !cmd->lv_notify && !cmd->pv_notify)
		return;

	cmd->vg_notify = 0;
	cmd->lv_notify = 0;
	cmd->pv_notify = 0;

	cmd_name = get_cmd_name();

	ret = sd_bus_open_system(&bus);
	if (ret < 0) {
		log_debug_dbus("Failed to connect to dbus: %d", ret);
		return;
	}

	log_debug_dbus("Nofify dbus at %s.", LVM_DBUS_DESTINATION);

	ret = sd_bus_call_method(bus,
				 LVM_DBUS_DESTINATION,
				 LVM_DBUS_PATH,
				 LVM_DBUS_INTERFACE,
				 "ExternalEvent",
				 &error,
				 &m,
				 "s",
				 cmd_name);

	if (ret < 0) {
		if (sd_bus_error_has_name(&error, SD_BUS_SYSTEMD_NO_SUCH_UNIT_ERROR) ||
		    sd_bus_error_has_name(&error, SD_BUS_DBUS_SERVICE_UNKNOWN_ERROR))
			log_debug_dbus("%s: %s", _dbus_notification_failed_msg, error.message);
		else
			log_warn("WARNING: %s: %s", _dbus_notification_failed_msg, error.message);
		goto out;
	}

	ret = sd_bus_message_read(m, "i", &result);
	if (ret < 0)
		log_debug_dbus("Failed to parse dbus response message: %d", ret);
	if (result)
		log_debug_dbus("Bad return value from dbus service: %d", result);
out:
	sd_bus_error_free(&error);
	sd_bus_message_unref(m);
	sd_bus_flush_close_unref(bus);
}
int parse_cmd_str_to_cmd_struct (char* cmd_string , COMMAND* cmd_struct,unsigned address ){

	get_cmd_name (cmd_string ,  cmd_struct->cmd_name ) ;
	cmd_type (cmd_struct->cmd_name , cmd_struct->cmd_type );
	cmd_struct->b_is_labled = is_labled(cmd_string,cmd_struct->label);
	cmd_struct->inst_address = address;
	if (strcmp(cmd_struct->cmd_type,"R")==0){
		update_R_type(cmd_string,cmd_struct );
	}
	else if (strcmp(cmd_struct->cmd_type,"I")==0){
		update_I_type(cmd_string,cmd_struct );
	}
	else if (strcmp(cmd_struct->cmd_type,"J")==0){
		update_J_type(cmd_string,cmd_struct); 
	}

	//else the command is HALT and we don't have to update COMMAND struct.


	return 1 ; 

}
Example #3
0
int ifdhandler_process(ct_socket_t * sock, ifd_reader_t * reader,
		       ct_buf_t * argbuf, ct_buf_t * resbuf)
{
	unsigned char cmd, unit;
	ct_tlv_parser_t args;
	ct_tlv_builder_t resp;
	int rc;

	/* Get command and target unit */
	if (ct_buf_get(argbuf, &cmd, 1) < 0 || ct_buf_get(argbuf, &unit, 1) < 0)
		return IFD_ERROR_INVALID_MSG;

	ifd_debug(1, "ifdhandler_process(cmd=%s, unit=%u)",
		  get_cmd_name(cmd), unit);

	/* First, handle commands that don't do TLV encoded
	 * arguments - currently this is only CT_CMD_TRANSACT. */
	if (cmd == CT_CMD_TRANSACT_OLD) {
		/* Security - deny any APDUs if there's an
		 * exclusive lock held by some other client. */
		if ((rc =
		     ifdhandler_check_lock(sock, unit, IFD_LOCK_EXCLUSIVE)) < 0)
			return rc;
		return do_transact_old(reader, unit, argbuf, resbuf);
	}

	if ((rc = do_before_command(reader)) < 0) {
		return rc;
	}

	memset(&args, 0, sizeof(args));
	if (ct_tlv_parse(&args, argbuf) < 0)
		return IFD_ERROR_INVALID_MSG;
	if (args.use_large_tags)
		sock->use_large_tags = 1;

	ct_tlv_builder_init(&resp, resbuf, sock->use_large_tags);

	switch (cmd) {
	case CT_CMD_STATUS:
		rc = do_status(reader, unit, &args, &resp);
		break;

	case CT_CMD_OUTPUT:
		rc = do_output(reader, unit, &args, &resp);
		break;

	case CT_CMD_RESET:
	case CT_CMD_REQUEST_ICC:
		rc = do_reset(reader, unit, &args, &resp);
		break;

	case CT_CMD_EJECT_ICC:
		rc = do_eject(reader, unit, &args, &resp);
		break;

	case CT_CMD_PERFORM_VERIFY:
		rc = do_verify(reader, unit, &args, &resp);
		break;

	case CT_CMD_LOCK:
		rc = do_lock(sock, reader, unit, &args, &resp);
		break;

	case CT_CMD_UNLOCK:
		rc = do_unlock(sock, reader, unit, &args, &resp);
		break;

	case CT_CMD_MEMORY_READ:
		rc = do_memory_read(reader, unit, &args, &resp);
		break;

	case CT_CMD_MEMORY_WRITE:
		rc = do_memory_write(reader, unit, &args, &resp);
		break;

	case CT_CMD_TRANSACT:
		rc = do_transact(reader, unit, &args, &resp);
		break;
	case CT_CMD_SET_PROTOCOL:
		rc = do_set_protocol(reader, unit, &args, &resp);
		break;
	default:
		return IFD_ERROR_INVALID_CMD;
	}

	if (rc >= 0)
		rc = resp.error;

	/*
	 * TODO consider checking error
	 */
	do_after_command(reader);

	return rc;
}
Example #4
0
/**
 * This method is to parse and add the command attribute to command structure.
 **/
static pj_status_t add_cmd_node(pj_cli_t *cli,				  
				pj_cli_cmd_spec *group,					 
				pj_xml_node *xml_node,
				pj_cli_cmd_handler handler,
				pj_cli_cmd_spec **p_cmd,
				pj_cli_get_dyn_choice get_choice)
{
    pj_xml_node *root = xml_node;
    pj_xml_attr *attr;
    pj_xml_node *sub_node;
    pj_cli_cmd_spec *cmd;
    pj_cli_arg_spec args[PJ_CLI_MAX_ARGS];
    pj_str_t sc[PJ_CLI_MAX_SHORTCUTS];
    pj_status_t status = PJ_SUCCESS;

    if (pj_stricmp2(&root->name, "CMD"))
        return PJ_EINVAL;

    /* Initialize the command spec */
    cmd = PJ_POOL_ZALLOC_T(cli->pool, struct pj_cli_cmd_spec);
    
    /* Get the command attributes */
    attr = root->attr_head.next;
    while (attr != &root->attr_head) {
        if (!pj_stricmp2(&attr->name, "name")) {
            pj_strltrim(&attr->value);
            if (!attr->value.slen || 
		(get_cmd_name(cli, group, &attr->value)))                
            {
                return PJ_CLI_EBADNAME;
            }
            pj_strdup(cli->pool, &cmd->name, &attr->value);
        } else if (!pj_stricmp2(&attr->name, "id")) {	    
	    pj_bool_t is_valid = PJ_FALSE;
            if (attr->value.slen) {		
		pj_cli_cmd_id cmd_id = pj_strtol(&attr->value);
		if (!pj_hash_get(cli->cmd_id_hash, &cmd_id, 
		                 sizeof(pj_cli_cmd_id), NULL))
		    is_valid = PJ_TRUE;
	    } 
	    if (!is_valid)
		return PJ_CLI_EBADID;
            cmd->id = (pj_cli_cmd_id)pj_strtol(&attr->value);
        } else if (!pj_stricmp2(&attr->name, "sc")) {
            pj_scanner scanner;
            pj_str_t str;

            PJ_USE_EXCEPTION;

            pj_scan_init(&scanner, attr->value.ptr, attr->value.slen,
                         PJ_SCAN_AUTOSKIP_WS, &on_syntax_error);

            PJ_TRY {
                while (!pj_scan_is_eof(&scanner)) {
                    pj_scan_get_until_ch(&scanner, ',', &str);
                    pj_strrtrim(&str);
                    if (!pj_scan_is_eof(&scanner))
                        pj_scan_advance_n(&scanner, 1, PJ_TRUE);
                    if (!str.slen)
                        continue;

                    if (cmd->sc_cnt >= PJ_CLI_MAX_SHORTCUTS) {
                        PJ_THROW(PJ_CLI_ETOOMANYARGS);
                    }
                    /* Check whether the shortcuts are already used */
                    if (get_cmd_name(cli, &cli->root, &str)) {
                        PJ_THROW(PJ_CLI_EBADNAME);
                    }

                    pj_strassign(&sc[cmd->sc_cnt++], &str);
                }
            }
            PJ_CATCH_ANY {
                pj_scan_fini(&scanner);
                return (PJ_GET_EXCEPTION());
            }
            PJ_END;
            
        } else if (!pj_stricmp2(&attr->name, "desc")) {
Example #5
0
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