int autosa(int argc, char *argv[], int retc, char *retv[]) { DPRINT1( "%s command invoked\n", argv[ 0 ] ); if (argc > 1) { if (send2Acq(12, "1") < 0) Werrprintf("autosa message was not sent"); } else { if (send2Acq(12, "0") < 0) Werrprintf("autosa message was not sent"); } RETURN; }
int autora(int argc, char *argv[], int retc, char *retv[]) { char tmpPath[MAXPATH]; int ival; DPRINT0("autora command invoked\n"); /* resume is implicit */ ival = ok_to_acquire(); if (ival != -2) release_console2(); if ( (ival != 0) && (ival != -4)) { /* Acquisition needs to be Idle or in automation mode */ report_acq_perm_error( argv[0], ival ); ABORT; } if (argc == 1) { strcpy(tmpPath,userdir); strcat(tmpPath,"/global"); DPRINT1("copying Global parameters to '%s' file.\n",tmpPath); if (P_save(GLOBAL,tmpPath)) { Werrprintf("Problem saving global parameters in '%s'.",tmpPath); } } P_getstring(GLOBAL,"autodir",&tmpPath[ 0 ], 1, MAXPATH); setAutoDir(tmpPath); if (send2Acq(11, tmpPath) < 0) Werrprintf("autora message was not sent"); RETURN; }
int resume(int argc, char *argv[], int retc, char *retv[]) { char resume_arg[MAXPATH]; DPRINT0("resume command invoked\n"); GET_ACQ_ID(resume_arg); if (send2Acq(13, resume_arg) < 0) Werrprintf("resume message was not sent"); RETURN; }
void autoqMsgOff() { if (receivingMsg) { if (is_acqproc_active()) { send2Acq(AUTOQMSG, "recvmsg off"); } } receivingMsg = 0; }
int send2AcqWithAuth( int cmd_for_acq, char *msg_for_acq ) { char *ourmsg; int ival, tlen, ulen; struct passwd *getpwuid(); struct passwd *pasinfo; pasinfo = getpwuid((int) getuid()); ulen = strlen( pasinfo->pw_name ); tlen = ulen + 2 + 6 + strlen( msg_for_acq ) + 1; ourmsg = (char *) malloc( tlen ); sprintf( ourmsg, "%s,,%d\n%s", pasinfo->pw_name, getpid(), msg_for_acq ); ival = send2Acq( cmd_for_acq, ourmsg ); free( ourmsg ); return( ival ); }
int autoq(int argc, char *argv[], int retc, char *retv[]) { char autodir[MAXPATH]; char lockPath[MAXPATH]; char idPath[MAXPATH]; char lockLogPath[MAXPATH]; char idLogPath[MAXPATH]; char logBasePath[MAXPATH]; char *blockname = "autoqBlock"; char *lockname = "lockEnterQ"; time_t lockSecs = 5; /* default lock timeout */ int res = 1; if (argc < 2) { Werrprintf("usage: %s requires add, get, lock, unlock, sendmsg, or recvmsg argument", argv[0]); ABORT; } if ( !strcmp(argv[1],"sendmsg") || !strcmp(argv[1],"recvmsg") ) { res = 4; } else { #ifdef VNMRJ if ( ! strcmp(argv[1],"add") ) P_getstring(GLOBAL,"autodir",autodir,1,MAXPATH); else #endif getAutoDir(autodir, MAXPATH); sprintf(lockPath,"%s/%s",autodir,lockname); sprintf(idPath,"%s/eq_%s_%s_%d",autodir,HostName,UserName,HostPid); } if ( ! strcmp(argv[1],"add") ) { char queuename[MAXPATH]; if (argc < 3) { Werrprintf("usage: %s('add',filename) requires a filename.",argv[0]); ABORT; } if (argc == 4) strcpy(queuename,argv[3]); else strcpy(queuename,"std"); /* Wait for get operations to complete first */ blockedByGet(autodir, blockname); if ( lockit(lockPath,idPath,lockSecs) ) { res = addQueueFile(autodir, argv[2], queuename); unlockit(lockPath,idPath); } else { res = -4; } } else if ( ! strcmp(argv[1],"get") ) { FILE *fd; char blockfile[MAXPATH]; if (argc < 3) { Werrprintf("usage: %s('get',filename) requires a filename.",argv[0]); ABORT; } /* The get operation will block add and lock from other processes */ sprintf(blockfile,"%s/%s",autodir,blockname); fd = fopen(blockfile,"w"); fclose(fd); if ( lockit(lockPath,idPath,lockSecs) ) { res = getQueueFile(autodir, argv[2]); unlockit(lockPath,idPath); } else { res = -4; } #ifdef TESTING if (argc == 4) sleepnano(atoi(argv[3])); #endif /* Allow access by add and lock from other processes */ unlink(blockfile); } else if ( ! strcmp(argv[1],"lock") ) { if (argc == 3) { lockSecs = atoi(argv[2]); if (lockSecs < 1) lockSecs = 1; else if (lockSecs > 15) lockSecs = 15; } /* Wait for get operations to complete first */ blockedByGet(autodir, blockname); DPRINT1("lock called with %ld timeout\n",lockSecs); res = lockit(lockPath,idPath,lockSecs); } else if ( ! strcmp(argv[1],"unlock") ) { unlockit(lockPath,idPath); res = 1; } else if ( ! strcmp(argv[1],"addAcct") ) { char accFile[MAXPATH]; char idFile[MAXPATH]; if (argc != 3) { Werrprintf("autoq('addAcct',filename) requires filename as the second argument"); ABORT; } if ( access(argv[2], R_OK|W_OK) ) { Werrprintf("autoq('addAcct',filename) filename does not exist or has wrong permissions"); ABORT; } res = 0; strcpy(lockPath, getenv("vnmrsystem") ); strcat(lockPath,"/adm/accounting/"); strcpy(accFile, lockPath); strcat(accFile,"acctLog.xml"); if ( !access(accFile,F_OK) ) { FILE *inputFd; int bufSize=4095; char buf[bufSize+1]; int size = 0; inputFd = fopen(argv[2],"r"); if (inputFd) { size = fread(buf, 1, bufSize, inputFd); /* Terminate the buffer */ buf[size] = 0; fclose(inputFd); } unlink(argv[2]); if (size) { lockSecs = 2; // Create filepaths for the lock files to lock acctLog strcpy(idPath, lockPath); strcat(lockPath, "acctLogLock"); sprintf(idFile, "acctLogLockId_%s_%d", HostName, HostPid); strcat(idPath, idFile); DPRINT1("lock called with %ld timeout\n",lockSecs); if ( lockit(lockPath,idPath,lockSecs) ) { const char root_end[]="</accounting>\n"; FILE *xmlFd; xmlFd = fopen(accFile,"r+"); if (xmlFd) { /* find the closing /> at the end and put log info above that */ fseek(xmlFd,-strlen(root_end),SEEK_END); /* Write to the log file */ fprintf(xmlFd,"%s",buf); fprintf(xmlFd,"%s",root_end); fflush(xmlFd); fclose(xmlFd); } unlockit(lockPath,idPath); res = 1; } } } } else if ( ! strcmp(argv[1],"locklog") ) { lockSecs = 15; // Create filepaths for the lock files to lock acctLog strcpy(logBasePath, (char *)getenv("vnmrsystem") ); strcat(logBasePath,"/adm/accounting/"); sprintf(lockLogPath, "%s%s", logBasePath, "acctLogLock"); sprintf(idLogPath, "%sacctLogLockId_%s_%d", logBasePath, HostName, HostPid); /* Wait for get operations to complete first */ blockedByGet(autodir, blockname); DPRINT1("lock called with %ld timeout\n",lockSecs); res = lockit(lockLogPath,idLogPath,lockSecs); } else if ( ! strcmp(argv[1],"unlocklog") ) { // Create filepaths for the lock files to lock acctLog strcpy(logBasePath, (char *)getenv("vnmrsystem") ); strcat(logBasePath,"/adm/accounting/"); sprintf(lockLogPath, "%s%s", logBasePath, "acctLogLock"); sprintf(idLogPath, "%sacctLogLockId_%s_%d", logBasePath, HostName, HostPid); unlockit(lockLogPath,idLogPath); res = 1; } else if (res == 4) /* ( !strcmp(argv[1],"sendmsg") || !strcmp(argv[1],"recvmsg") ) */ { if ( ! strcmp(argv[1],"recvmsg") ) { if ( (argc != 3) || ( strcmp(argv[2],"on") && strcmp(argv[2],"off")) ) { Werrprintf("autoq %s requires 'on' or 'off' as the second argument",argv[1]); ABORT; } } if (argc != 3) { Werrprintf("autoq %s requires another argument",argv[1]); ABORT; } res = 1; if (is_acqproc_active()) { char msg[MAXSTR]; sprintf(msg,"%s %s",argv[1],argv[2]); if (send2Acq(AUTOQMSG, msg) < 0) res = 0; if (res) receivingMsg = ( ! strcmp(argv[2],"on")); } } DPRINT1("operation returns %d\n",res); if (retc) { retv[0] = intString(res); } RETURN; }