void printOutput( ClassAd* reply, DCStartd* startd ) { char* claimid = NULL; char* last_state = NULL; if( cmd == CA_REQUEST_CLAIM ) { reply->LookupString( ATTR_CLAIM_ID, &claimid ); } if( CA_PATH ) { fPrintAd( CA_PATH, *reply ); fclose( CA_PATH ); printf( "Successfully sent %s to startd at %s\n", getCommandString(cmd), startd->addr() ); printf( "Result ClassAd written to %s\n", classad_path ); if( cmd == CA_REQUEST_CLAIM ) { printf( "ID of new claim is: \"%s\"\n", claimid ); free( claimid ); } return; } if( cmd == CA_REQUEST_CLAIM ) { fprintf( stderr, "Successfully sent %s to startd at %s\n", getCommandString(cmd), startd->addr() ); fprintf( stderr, "WARNING: You did not specify " "-classad, printing to STDOUT\n" ); fPrintAd( stdout, *reply ); fprintf( stderr, "ID of new claim is: \"%s\"\n", claimid ); free( claimid ); return; } printf( "Successfully sent %s to startd at %s\n", getCommandString(cmd), startd->addr() ); switch( cmd ) { case CA_REQUEST_CLAIM: EXCEPT( "Already handled CA_REQUEST_CLAIM!" ); break; case CA_RELEASE_CLAIM: if( reply->LookupString(ATTR_LAST_CLAIM_STATE, &last_state) ) { printf( "State of claim when it was released: \"%s\"\n", last_state ); free( last_state ); } else { fprintf( stderr, "Warning: " "reply ClassAd did not contain attribute \"%s\"\n", ATTR_LAST_CLAIM_STATE ); } break; default: // nothing else yet to print break; } }
bool DCStartd::requestClaim( ClaimType cType, const ClassAd* req_ad, ClassAd* reply, int timeout ) { setCmdStr( "requestClaim" ); std::string err_msg; switch( cType ) { case CLAIM_COD: case CLAIM_OPPORTUNISTIC: break; default: err_msg = "Invalid ClaimType ("; err_msg += (int)cType; err_msg += ')'; newError( CA_INVALID_REQUEST, err_msg.c_str() ); return false; } ClassAd req( *req_ad ); char buf[1024]; // Add our own attributes to the request ad we're sending sprintf( buf, "%s = \"%s\"", ATTR_COMMAND, getCommandString(CA_REQUEST_CLAIM) ); req.Insert( buf ); sprintf( buf, "%s = \"%s\"", ATTR_CLAIM_TYPE, getClaimTypeString(cType) ); req.Insert( buf ); return sendCACmd( &req, reply, true, timeout ); }
//------------------------------------------------------------------------- bool CVCRControl::CServerDevice::sendCommand(CVCRCommand command, const t_channel_id channel_id, const event_id_t epgid, const std::string& epgTitle, unsigned char apids) { printf("Send command: %d channel_id: " PRINTF_CHANNEL_ID_TYPE_NO_LEADING_ZEROS " epg: %s(%llx)\n", command, channel_id, epgTitle.c_str(), epgid); if(serverConnect()) { std::string extMessage = getCommandString(command, channel_id, epgid, epgTitle, apids); printf("sending to vcr-client:\n\n%s\n", extMessage.c_str()); write(sock_fd, extMessage.c_str() , extMessage.length() ); serverDisconnect(); deviceState = command; return true; } else return false; }
bool DCStartd::releaseClaim( VacateType vType, ClassAd* reply, int timeout ) { setCmdStr( "releaseClaim" ); if( ! checkClaimId() ) { return false; } if( ! checkVacateType(vType) ) { return false; } ClassAd req; // Add our own attributes to the request ad we're sending req.Assign( ATTR_COMMAND, getCommandString(CA_RELEASE_CLAIM) ); req.Assign( ATTR_CLAIM_ID, claim_id ); req.Assign( ATTR_VACATE_TYPE, getVacateTypeString(vType) ); // since release could take a while, if we didn't already get // told what timeout to use, set the timeout to 0 so we don't // bail out prematurely... if( timeout < 0 ) { return sendCACmd( &req, reply, true, 0 ); } else { return sendCACmd( &req, reply, true, timeout ); } }
bool DCStartd::locateStarter( const char* global_job_id, const char *claimId, const char *schedd_public_addr, ClassAd* reply, int timeout ) { setCmdStr( "locateStarter" ); ClassAd req; // Add our own attributes to the request ad we're sending req.Assign(ATTR_COMMAND,getCommandString( CA_LOCATE_STARTER )); req.Assign(ATTR_GLOBAL_JOB_ID,global_job_id); req.Assign(ATTR_CLAIM_ID, claimId); if ( schedd_public_addr ) { req.Assign(ATTR_SCHEDD_IP_ADDR,schedd_public_addr); } // if this claim is associated with a security session ClaimIdParser cidp( claimId ); return sendCACmd( &req, reply, false, timeout, cidp.secSessionId() ); }
int JICLocal::reconnect( ReliSock* s, ClassAd* /*ad*/ ) { // Someday this might mean something, for now it doesn't. sendErrorReply( s, getCommandString(CA_RECONNECT_JOB), CA_FAILURE, "Starter using JICLocal does not support reconnect" ); return FALSE; }
bool VMProc::reportVMInfoToStartd(int cmd, const char *value) { Daemon startd(DT_STARTD, NULL); if( !startd.locate() ) { dprintf(D_ALWAYS,"ERROR: %s\n", startd.error()); return false; } char* addr = startd.addr(); if( !addr ) { dprintf(D_ALWAYS,"Can't find the address of local startd\n"); return false; } // Using udp packet SafeSock ssock; ssock.timeout( 5 ); // 5 seconds timeout ssock.encode(); if( !ssock.connect(addr) ) { dprintf( D_ALWAYS, "Failed to connect to local startd(%s)\n", addr); return false; } if( !startd.startCommand(cmd, &ssock) ) { dprintf( D_ALWAYS, "Failed to send UDP command(%s) " "to local startd %s\n", getCommandString(cmd), addr); return false; } // Send the pid of this starter MyString s_pid; s_pid += (int)daemonCore->getpid(); char *starter_pid = strdup(s_pid.Value()); ASSERT(starter_pid); ssock.code(starter_pid); // Send vm info char *vm_value = strdup(value); ASSERT(vm_value); ssock.code(vm_value); if( !ssock.end_of_message() ) { dprintf( D_FULLDEBUG, "Failed to send EOM to local startd %s\n", addr); free(starter_pid); free(vm_value); return false; } free(starter_pid); free(vm_value); sleep(1); return true; }
bool DCStartd::updateMachineAd( const ClassAd * update, ClassAd * reply, int timeout ) { setCmdStr( "updateMachineAd" ); ClassAd u( * update ); u.Assign( ATTR_COMMAND, getCommandString( CA_UPDATE_MACHINE_AD ) ); return sendCACmd( & u, reply, true, timeout ); }
// return the command name for known commmand or "command NNN" for unknown commands // returned pointer is valid forever and the caller does not free it const char* getCommandStringSafe( int num ) { char const *result = getCommandString(num); if (result) return result; return getUnknownCommandString(num); }
bool LX200SS2000PC::getCalenderDate(int& year,int& month,int& day) { char date[16]; bool result = ( getCommandString(PortFD, date, ":GC#") == 0 ); DEBUGF(INDI::Logger::DBG_DEBUG, "LX200SS2000PC::getCalenderDate():: Date string from telescope: %s", date); if (result) { result = ( sscanf(date, "%d%*c%d%*c%d", &month, &day, &year) == 3 ); // Meade format is MM/DD/YY DEBUGF(INDI::Logger::DBG_DEBUG, "setCalenderDate: Date retrieved from telescope: %02d/%02d/%02d.", month, day, year); if (result) year += ( year > 50 ? 1900 : 2000 ); // Year 50 or later is in the 20th century, anything less is in the 21st century. } return result; }
char const * DCMsg::name() { if( m_cmd_str ) { return m_cmd_str; } m_cmd_str = getCommandString( m_cmd ); if( !m_cmd_str ) { std::string buf; sprintf(buf,"command %d",m_cmd); m_cmd_str = buf.c_str(); } return m_cmd_str; }
bool DCStartd::activateClaim( const ClassAd* job_ad, ClassAd* reply, int timeout ) { setCmdStr( "activateClaim" ); if( ! checkClaimId() ) { return false; } ClassAd req( *job_ad ); // Add our own attributes to the request ad we're sending req.Assign( ATTR_COMMAND, getCommandString(CA_ACTIVATE_CLAIM) ); req.Assign( ATTR_CLAIM_ID, claim_id ); return sendCACmd( &req, reply, true, timeout ); }
bool DCStartd::resumeClaim( ClassAd* reply, int timeout ) { setCmdStr( "resumeClaim" ); if( ! checkClaimId() ) { return false; } ClassAd req; // Add our own attributes to the request ad we're sending req.Assign( ATTR_COMMAND, getCommandString(CA_RESUME_CLAIM) ); req.Assign( ATTR_CLAIM_ID, claim_id ); return sendCACmd( &req, reply, true, timeout ); }
int main( int argc, char *argv[] ) { myDistro->Init( argc, argv ); config(); dprintf_config_tool_on_error(0); dprintf_OnExitDumpOnErrorBuffer(stderr); parseArgv( argc, argv ); DCStartd startd( target, pool ); if( ! startd.locate() ) { fprintf( stderr, "ERROR: %s\n", startd.error() ); exit( 1 ); } bool rval = false; if( cmd == DRAIN_JOBS ) { std::string request_id; rval = startd.drainJobs( how_fast, resume_on_completion, draining_check_expr, request_id ); if( rval ) { printf("Sent request to drain %s\n",startd.name()); if (dash_verbose && ! request_id.empty()) { printf("\tRequest id: %s\n", request_id.c_str()); } } } else if( cmd == CANCEL_DRAIN_JOBS ) { rval = startd.cancelDrainJobs( cancel_request_id ); if( rval ) { printf("Sent request to cancel draining on %s\n",startd.name()); } } if( ! rval ) { fprintf( stderr, "Attempt to send %s to startd %s failed\n%s\n", getCommandString(cmd), startd.addr(), startd.error() ); return 1; } dprintf_SetExitCode(0); return 0; }
bool DCStarter::reconnect( ClassAd* req, ClassAd* reply, ReliSock* rsock, int timeout, char const *sec_session_id ) { setCmdStr( "reconnectJob" ); std::string line; // Add our own attributes to the request ad we're sending line = ATTR_COMMAND; line += "=\""; line += getCommandString( CA_RECONNECT_JOB ); line += '"'; req->Insert( line.c_str() ); return sendCACmd( req, reply, rsock, false, timeout, sec_session_id ); }
int main( int argc, char *argv[] ) { #ifndef WIN32 // Ignore SIGPIPE so if we cannot connect to a daemon we do not // blowup with a sig 13. install_sig_handler(SIGPIPE, SIG_IGN ); #endif myDistro->Init( argc, argv ); config(); cmd = getCommandFromArgv( argc, argv ); parseArgv( argc, argv ); DCStartd startd( target, pool ? pool->addr() : NULL ); if( needs_id ) { assert( claim_id ); startd.setClaimId( claim_id ); } if( ! startd.locate() ) { fprintf( stderr, "ERROR: %s\n", startd.error() ); exit( 1 ); } bool rval = FALSE; int irval; ClassAd reply; ClassAd ad; switch( cmd ) { case CA_REQUEST_CLAIM: fillRequestAd( &ad ); rval = startd.requestClaim( CLAIM_COD, &ad, &reply, timeout ); break; case CA_ACTIVATE_CLAIM: fillActivateAd( &ad ); irval = startd.activateClaim( &ad, &reply, timeout ); rval = (irval == OK); break; case CA_SUSPEND_CLAIM: rval = startd.suspendClaim( &reply, timeout ); break; case CA_RESUME_CLAIM: rval = startd.resumeClaim( &reply, timeout ); break; case CA_DEACTIVATE_CLAIM: rval = startd.deactivateClaim( vacate_type, &reply, timeout ); break; case CA_RELEASE_CLAIM: rval = startd.releaseClaim( vacate_type, &reply, timeout ); break; case CA_RENEW_LEASE_FOR_CLAIM: rval = startd.renewLeaseForClaim( &reply, timeout ); break; case DELEGATE_GSI_CRED_STARTD: irval = startd.delegateX509Proxy( proxy_file, 0, NULL ); rval = (irval == OK); break; } if( ! rval ) { fprintf( stderr, "Attempt to send %s to startd %s failed\n%s\n", getCommandString(cmd), startd.addr(), startd.error() ); return 1; } printOutput( &reply, &startd ); return 0; }
void SharedPortEndpoint::DoListenerAccept(ReliSock *return_remote_sock) { #ifdef WIN32 dprintf(D_FULLDEBUG, "SharedPortEndpoint: Entered DoListerAccept Win32 path.\n"); ReliSock *remote_sock = return_remote_sock; if(!remote_sock) { remote_sock = new ReliSock; } EnterCriticalSection(&received_lock); if(!received_sockets.empty()) { WSAPROTOCOL_INFO *received_socket = received_sockets.front(); received_sockets.pop(); LeaveCriticalSection(&received_lock); remote_sock->assign(received_socket); remote_sock->enter_connected_state(); remote_sock->isClient(false); if(!return_remote_sock) daemonCore->HandleReqAsync(remote_sock); HeapFree(GetProcessHeap(), NULL, received_socket); } else { LeaveCriticalSection(&received_lock); dprintf(D_ALWAYS, "SharedPortEndpoint: DoListenerAccept: No connections, error.\n"); } #else ReliSock *accepted_sock = m_listener_sock.accept(); if( !accepted_sock ) { dprintf(D_ALWAYS, "SharedPortEndpoint: failed to accept connection on %s\n", m_full_name.Value()); return; } // Currently, instead of having daemonCore handle the command // for us, we read it here. This means we only support the raw // command protocol. accepted_sock->decode(); int cmd; if( !accepted_sock->get(cmd) ) { dprintf(D_ALWAYS, "SharedPortEndpoint: failed to read command on %s\n", m_full_name.Value()); delete accepted_sock; return; } if( cmd != SHARED_PORT_PASS_SOCK ) { dprintf(D_ALWAYS, "SharedPortEndpoint: received unexpected command %d (%s) on named socket %s\n", cmd, getCommandString(cmd), m_full_name.Value()); delete accepted_sock; return; } if( !accepted_sock->end_of_message() ) { dprintf(D_ALWAYS, "SharedPortEndpoint: failed to read end of message for cmd %s on %s\n", getCommandString(cmd), m_full_name.Value()); delete accepted_sock; return; } dprintf(D_COMMAND|D_FULLDEBUG, "SharedPortEndpoint: received command %d SHARED_PORT_PASS_SOCK on named socket %s\n", cmd, m_full_name.Value()); ReceiveSocket(accepted_sock,return_remote_sock); delete accepted_sock; #endif }
void VMRegister::sendEventToHost(int cmd, void *data) { if( !m_vm_host_daemon ) return; if( !vmapi_sendCommand(m_vm_host_daemon->addr(), cmd, data) ) { dprintf( D_FULLDEBUG, "Can't send a VM event command(%s) to the host machine(%s)\n", getCommandString(cmd), m_vm_host_daemon->addr() ); return; } }
void ioptronHC8406::sendScopeTime() { char cdate[32]={0}; double ctime; int h, m, s; int utc_h, utc_m, utc_s; double lx200_utc_offset = 0; char utc_offset_res[32]={0}; int day, month, year, result; struct tm ltm; struct tm utm; time_t time_epoch; if (isSimulation()) { snprintf(cdate, 32, "%d-%02d-%02dT%02d:%02d:%02d", 1979, 6, 25, 3, 30, 30); IDLog("Telescope ISO date and time: %s\n", cdate); IUSaveText(&TimeT[0], cdate); IUSaveText(&TimeT[1], "3"); IDSetText(&TimeTP, nullptr); return; } //getCommandSexa(PortFD, &lx200_utc_offset, ":GG#"); //tcflush(PortFD, TCIOFLUSH); getCommandString(PortFD, utc_offset_res, ":GG#"); f_scansexa(utc_offset_res,&lx200_utc_offset); result = sscanf(utc_offset_res, "%d%*c%d%*c%d", &utc_h, &utc_m, &utc_s); if (result != 3) { DEBUG(INDI::Logger::DBG_ERROR, "Error reading UTC offset from Telescope."); return; } DEBUGF(INDI::Logger::DBG_DEBUG, "<VAL> UTC offset: %d:%d:%d --->%g",utc_h,utc_m, utc_s, lx200_utc_offset); // LX200 TimeT Offset is defined at the number of hours added to LOCAL TIME to get TimeT. This is contrary to the normal definition. DEBUGF(INDI::Logger::DBG_DEBUG, "<VAL> UTC offset str: %s",utc_offset_res); IUSaveText(&TimeT[1], utc_offset_res); //IUSaveText(&TimeT[1], lx200_utc_offset); getLocalTime24(PortFD, &ctime); getSexComponents(ctime, &h, &m, &s); getCalendarDate(PortFD, cdate); result = sscanf(cdate, "%d%*c%d%*c%d", &year, &month, &day); if (result != 3) { DEBUG(INDI::Logger::DBG_ERROR, "Error reading date from Telescope."); return; } // Let's fill in the local time ltm.tm_sec = s; ltm.tm_min = m; ltm.tm_hour = h; ltm.tm_mday = day; ltm.tm_mon = month - 1; ltm.tm_year = year - 1900; // Get time epoch time_epoch = mktime(<m); // Convert to TimeT //time_epoch -= (int)(atof(TimeT[1].text) * 3600.0); time_epoch -= (int)(lx200_utc_offset * 3600.0); // Get UTC (we're using localtime_r, but since we shifted time_epoch above by UTCOffset, we should be getting the real UTC time localtime_r(&time_epoch, &utm); /* Format it into ISO 8601 */ strftime(cdate, 32, "%Y-%m-%dT%H:%M:%S", &utm); IUSaveText(&TimeT[0], cdate); DEBUGF(INDI::Logger::DBG_DEBUG, "Mount controller Local Time: %02d:%02d:%02d", h, m, s); DEBUGF(INDI::Logger::DBG_DEBUG, "Mount controller UTC Time: %s", TimeT[0].text); // Let's send everything to the client IDSetText(&TimeTP, nullptr); }