Esempio n. 1
0
int main() {
char *eof; char line[100];
int customer;
cshmInit();
while(1) {
  printf("l cust   u cust   h[elp] p[rint] q[uit]:");
  eof=fgets(line, 100, stdin);
  if(eof==NULL) break;
  if(line[0]=='q') break;
  if(line[0]=='l') {
    customer= atoi(&line[2]);
    lockBakery(&ctpshmbase->swtriggers, customer);
  } else if(line[0]=='u') {
    customer= atoi(&line[2]);
    unlockBakery(&ctpshmbase->swtriggers, customer);
  } else if(line[0]=='p') {
    printBakery(&ctpshmbase->swtriggers);
  } else if(line[0]=='h') {
printf("Now l/u/p concerns swtriggers. bakery alg. used for\n\
2 groups of tasks (initialised in main_ctp.c):\n\
initBakery(swtriggers,4): 0:SOD/EOD 1:gcalib 2:ctp.exe 3:dims\n\
initBakery(ccread,5): 0:proxy 1:dims 2:ctp+busytool 3:smaq 4:inputs\n\
");
  } else {
    continue;
Esempio n. 2
0
/*----------------------------------------*/ int main(int argc, char **argv) {
int rc;
int ssmcr_tries=0;
infolog_SetFacility("CTP"); infolog_SetStream("",0);
#ifdef PQWAY
printf("main_ctp: opening rec/send queues...\n");
mq_rec= pq_open();
if(mq_rec==(mqd_t)-1) {
  infolog_trgboth(LOG_FATAL, "posix mq_rec not created");
  exit(8);
}
mq_sendmsg= pq_connect();
if(mq_sendmsg==(mqd_t)-1) {
  infolog_trgboth(LOG_FATAL, "posix mq_sendmsg not connected");
  exit(8);
}
#endif
signal(SIGUSR1, gotsignal); siginterrupt(SIGUSR1, 0);
signal(SIGQUIT, gotsignal); siginterrupt(SIGQUIT, 0);
signal(SIGKILL, gotsignal); siginterrupt(SIGKILL, 0); // -9
signal(SIGTERM, gotsignal); siginterrupt(SIGTERM, 0); // kill pid
signal(SIGINT, gotsignal); siginterrupt(SIGINT, 0);   // CTRL C   2
partmode[0]='\0';
printf("cshmInit i.e. initBakery(swtriggers/ccread/ssmcr ONLY once, when shm allocated)...\n");
/*printf("initBakery(swtriggers,4): 0:SOD/EOD 1:gcalib 2:ctp.exe 3:dims\n");
printf("initBakery(ccread,5): 0:proxy 1:dims 2:ctp+busytool 3:smaq 4:inputs\n");
*/
cshmInit();
setglobalflags(argc, argv);

/* changed in aug2016 (initBakery only once from now, when shm allocated)
printf("initBakery(swtriggers,4): 0:SOD/EOD 1:gcalib 2:ctp.exe 3:dims\n");
initBakery(&ctpshmbase->swtriggers, "swtriggers", swtriggers_N);
printf("initBakery(ccread,6): 0:proxy 1:dims 2:ctp+busytool 3:smaq 4:inputs 5:orbitddl2\n");
initBakery(&ctpshmbase->ccread, "ccread", ccread_N);
printf("initBakery(ssmcr,4): 0:smaq 1:orbitddl2 2:ctp 3:inputs\n");
initBakery(&ctpshmbase->ssmcr, "ssmcr", ssmcr_N);
*/
printBakery(&ctpshmbase->swtriggers);
printBakery(&ctpshmbase->ccread);
printBakery(&ctpshmbase->ssmcr);
unlockBakery(&ctpshmbase->swtriggers,swtriggers_ctpproxy);
unlockBakery(&ctpshmbase->ccread,ccread_ctpproxy);
unlockBakery(&ctpshmbase->ssmcr,ssmcr_ctpproxy);

/* Let' synchronise with smcr only, i.e. 
- ccread_dims,... can go in parallel with ctp_Initproxy, 
  orbitddl2: should use ccread_orbitddl2 customer when reading counters
  
- swtriggers_gcalib/_dims cannot appear (no global runs becasue ctpproxy being restarted)
*/
while(1) { // do not allow SSM usage (smaq) because ctp_Initproxy is initialising it
  char msg[100];
  rc= lockBakeryTimeout(&ctpshmbase->ssmcr,ssmcr_ctpproxy, 10);
  if(rc==1) {
    if(ssmcr_tries>0) {
      sprintf(msg, "Got ssmcr resource after %d attempts", ssmcr_tries);
      infolog_trgboth(LOG_INFO, msg);
    };
    break;  // ssmcr reserved for me now
  };
  ssmcr_tries++;
  sprintf(msg,"%d secs Waiting for ssmcr resource. Is smaq stopped?", ssmcr_tries*10);
  infolog_trgboth(LOG_WARNING, msg);
};
if(isArg(argc, argv, "configrunset")) {
  /* do we need before orbitddl2.py INT/L2 orbit in SYNC (automatic with L2a)?
  */
  int rc, reslen;
  char cmd[200];
  char result[1000]="";   // ~ 10 lines
  char orbchanged[]="Warning: orbitoffset changed:";
  if(envcmp("VMESITE", "PRIVATE")==0) {
    strcpy(cmd, "who");
  } else {
    strcpy(cmd, "orbitddl2.py configrunset");
  };
  infolog_trgboth(LOG_INFO, "Starting L0 orbit calibration (30s...)");
  rc= popenread(cmd, result, 1000);   // opens vme...
  reslen= strlen(result);
  if((rc==EXIT_FAILURE) || (reslen<=1)) { 
    infolog_trgboth(LOG_ERROR, "L0 orbit calibration problem");
  } else {
    int ixr= reslen;
    if(result[ixr-1]=='\n') {   //remove last NL character if present
      result[ixr-1]='\0';
      ixr= reslen-2;
    } else {
      ixr= reslen-1;   // pointer to the last non-NEWLINE character
    };
    while(ixr>=0) {    // find last line
      if(result[ixr]=='\n') {
        ixr++; break;
      };
      ixr--;
    };
    sprintf(cmd, "L0 orbit calibration: %s", &result[ixr]);
    if((strcmp(&result[ixr], "Everything ok")==0) ||
       (strncmp(&result[ixr], orbchanged, strlen(orbchanged))==0)
      ) {
      infolog_trgboth(LOG_INFO, cmd);
    } else {
      infolog_trgboth(LOG_ERROR, cmd);
      infolog_trgboth(LOG_ERROR, "ctpproxy not started"); 
      unlockBakery(&ctpshmbase->ssmcr,ssmcr_ctpproxy);
      rc=8; goto STP;
    };
  };
};
// init CTP after calibration (e.g. to repair modifications done by orbitddl2.py)
rc=ctp_Initproxy();
unlockBakery(&ctpshmbase->ssmcr,ssmcr_ctpproxy);
if(rc!=0) goto STP;

// DIM services not registered here (see ctpdims.c), they run in separae task:
// ds_register();
strcpy(obj,argv[1]);
smi_attach(obj, SMI_handle_command);
printf("CTP attached to: %s\n",obj);
/* if smi_volatile: stops the ctp_proxy in case TRIGGER domain is down
smi_volatile();   
*/
strcpy(errorReason,"not set"); smi_set_parER();
strcpy(ORBIT_NUMBER,""); smi_set_par("ORBIT_NUMBER",ORBIT_NUMBER,STRING);
smi_setState("RUNNING");
while(1) {
#ifdef PQWAY
  executectp("wait");
#else
  usleep(1000000);
#endif
  if(quit>9) break;
};
rc= ctp_Endproxy();
STP:
#ifdef PQWAY
pq_close(mq_sendmsg, 0);
pq_close(mq_rec, 1);
#endif
printf("Calling cshmDetach()...\n"); cshmDetach();
return (rc);
}