void BaseShadow::checkSwap( void ) { int reserved_swap, free_swap; // Reserved swap is specified in megabytes reserved_swap = param_integer( "RESERVED_SWAP", 0 ); reserved_swap *= 1024; if( reserved_swap == 0 ) { // We're not supposed to care about swap space at all, so // none of the rest of the checks matter at all. return; } free_swap = sysapi_swap_space(); dprintf( D_FULLDEBUG, "*** Reserved Swap = %d\n", reserved_swap ); dprintf( D_FULLDEBUG, "*** Free Swap = %d\n", free_swap ); if( free_swap < reserved_swap ) { dprintf( D_ALWAYS, "Not enough reserved swap space\n" ); DC_Exit( JOB_NO_MEM ); } }
/* this function calls every function in sysapi that makes sense to call and prints out its value */ extern "C" void sysapi_test_dump_functions(void) { int foo = 0; long long loo = 0; float bar = 0; const char *qux = NULL; time_t t0, t1; dprintf(D_ALWAYS, "SysAPI: Calling SysAPI functions....\n"); qux = sysapi_ckptpltfrm_raw(); dprintf(D_ALWAYS, "SysAPI: sysapi_ckptpltfrm_raw -> %s\n", qux); qux = sysapi_ckptpltfrm(); dprintf(D_ALWAYS, "SysAPI: sysapi_ckptpltfrm -> %s\n", qux); foo = sysapi_phys_memory_raw(); dprintf(D_ALWAYS, "SysAPI: sysapi_phys_memory_raw() -> %d\n", foo); foo = sysapi_phys_memory(); dprintf(D_ALWAYS, "SysAPI: sysapi_phys_memory() -> %d\n", foo); loo = sysapi_disk_space_raw("/"); dprintf(D_ALWAYS, "SysAPI: sysapi_disk_space_raw() -> %" PRIi64 "\n", loo); loo = sysapi_disk_space("/"); dprintf(D_ALWAYS, "SysAPI: sysapi_disk_space() -> %" PRIi64 "\n", loo); sysapi_ncpus_raw(&foo,NULL); dprintf(D_ALWAYS, "SysAPI: sysapi_ncpus_raw() -> %d\n", foo); sysapi_ncpus_raw(&foo, NULL); dprintf(D_ALWAYS, "SysAPI: sysapi_ncpus() -> %d\n", foo); foo = sysapi_mips_raw(); dprintf(D_ALWAYS, "SysAPI: sysapi_mips_raw() -> %d\n", foo); foo = sysapi_mips(); dprintf(D_ALWAYS, "SysAPI: sysapi_mips() -> %d\n", foo); foo = sysapi_kflops_raw(); dprintf(D_ALWAYS, "SysAPI: sysapi_kflops_raw() -> %d\n", foo); foo = sysapi_kflops(); dprintf(D_ALWAYS, "SysAPI: sysapi_kflops() -> %d\n", foo); sysapi_idle_time_raw(&t0, &t1); dprintf(D_ALWAYS,"SysAPI: sysapi_idle_time_raw() -> (%f,%f)\n",(float)t0,(float)t1); sysapi_idle_time(&t0, &t1); dprintf(D_ALWAYS, "SysAPI: sysapi_idle_time() -> (%f,%f)\n", (float)t0, (float)t1); bar = sysapi_load_avg_raw(); dprintf(D_ALWAYS, "SysAPI: sysapi_load_avg_raw() -> %f\n", bar); bar = sysapi_load_avg(); dprintf(D_ALWAYS, "SysAPI: sysapi_load_avg() -> %f\n", bar); qux = sysapi_condor_arch(); dprintf(D_ALWAYS, "SysAPI: sysapi_condor_arch -> %s\n", qux); qux = sysapi_uname_arch(); dprintf(D_ALWAYS, "SysAPI: sysapi_uname_arch -> %s\n", qux); qux = sysapi_opsys(); dprintf(D_ALWAYS, "SysAPI: sysapi_opsys -> %s\n", qux); foo = sysapi_swap_space_raw(); dprintf(D_ALWAYS, "SysAPI: sysapi_swap_space_raw() -> %d\n", foo); foo = sysapi_swap_space(); dprintf(D_ALWAYS, "SysAPI: sysapi_swap_space() -> %d\n", foo); }
/*ARGSUSED*/ int main(int argc, char *argv[] ) { char *tmp = NULL; int reserved_swap, free_swap; char *host = NULL, *cluster = NULL, *proc = NULL; char *bogus_capability; int i; set_mySubSystem( "SHADOW", SUBSYSTEM_TYPE_SHADOW ); myDistro->Init( argc, argv ); if( argc == 2 && strncasecmp(argv[1], "-cl", 3) == MATCH ) { printClassAd(); exit( 0 ); } #if defined(SYSCALL_DEBUG) SyscallLabel = argv[0] + 7; #endif #if !defined(WIN32) install_sig_handler(SIGPIPE, (SIG_HANDLER)SIG_IGN ); #endif if( argc > 1 ) { if( strcmp("-t",argv[1]) == MATCH ) { Termlog = 1; argv++; argc--; } } ShadowBDate = LastRestartTime = time(0); _EXCEPT_Cleanup = ExceptCleanup; MyPid = getpid(); config(); /* Start up with condor.condor privileges. */ /* we need to do this AFTER we call config() so that if CONDOR_IDS is being defined in the config file, we'll get the right value */ set_condor_priv(); if(Termlog) dprintf_set_tool_debug(get_mySubSystem()->getName(), 0); else dprintf_config( get_mySubSystem()->getName() ); DebugId = whoami; // create a database connection object dprintf( D_ALWAYS, "******* Standard Shadow starting up *******\n" ); dprintf( D_ALWAYS, "** %s\n", CondorVersion() ); dprintf( D_ALWAYS, "** %s\n", CondorPlatform() ); dprintf( D_ALWAYS, "*******************************************\n" ); reserved_swap = param_integer("RESERVED_SWAP", 0); reserved_swap *= 1024; /* megabytes -> kb */ bool use_sql_log = param_boolean("QUILL_USE_SQL_LOG", false); FILEObj = FILESQL::createInstance(use_sql_log); free_swap = sysapi_swap_space(); dprintf( D_FULLDEBUG, "*** Reserved Swap = %d\n", reserved_swap ); dprintf( D_FULLDEBUG, "*** Free Swap = %d\n", free_swap ); if( reserved_swap && free_swap < reserved_swap ) { dprintf( D_ALWAYS, "Not enough reserved swap space\n" ); if(FILEObj) { delete FILEObj; } exit( JOB_NO_MEM ); } dprintf(D_ALWAYS, "uid=%d, euid=%d, gid=%d, egid=%d\n", getuid(), geteuid(), getgid(), getegid()); dprintf(D_FULLDEBUG, "argc = %d\n", argc); for(i = 0; i < argc; i++) { dprintf(D_FULLDEBUG, "argv[%d] = %s\n", i, argv[i]); } if( argc < 6 ) { usage(); } if (param_boolean("SHADOW_DEBUG_WAIT", false, false)) { int debug_wait = 1; dprintf(D_ALWAYS, "SHADOW_DEBUG_WAIT is TRUE, waiting for debugger to attach to pid %d.\n", (int)::getpid()); while (debug_wait) { sleep(1); } } CheckSpoolVersion(SPOOL_MIN_VERSION_SHADOW_SUPPORTS,SPOOL_CUR_VERSION_SHADOW_SUPPORTS); if( strcmp("-pipe",argv[1]) == 0 ) { bogus_capability = argv[2]; cluster = argv[3]; proc = argv[4]; // read the big comment in the function for why this is here. RemoveNewShadowDroppings(cluster, proc); pipe_setup( cluster, proc, bogus_capability ); } else { schedd = argv[1]; host = argv[2]; bogus_capability = argv[3]; cluster = argv[4]; proc = argv[5]; if ( argc > 6 ) { IpcFile = argv[6]; dprintf(D_FULLDEBUG,"Setting IpcFile to %s\n",IpcFile); } else { IpcFile = NULL; } // read the big comment in the function for why this is here. RemoveNewShadowDroppings(cluster, proc); regular_setup( host, cluster, proc ); } scheddName = getenv( EnvGetName( ENV_SCHEDD_NAME ) ); #if 0 /* Don't want to share log file lock between child and pnarent */ (void)close( LockFd ); LockFd = -1; #endif // initialize the user log initializeUserLog(); My_Filesystem_Domain = param( "FILESYSTEM_DOMAIN" ); dprintf( D_ALWAYS, "My_Filesystem_Domain = \"%s\"\n", My_Filesystem_Domain ); My_UID_Domain = param( "UID_DOMAIN" ); dprintf( D_ALWAYS, "My_UID_Domain = \"%s\"\n", My_UID_Domain ); UseAFS = param_boolean_crufty( "USE_AFS", false ) ? TRUE : FALSE; UseNFS = param_boolean_crufty( "USE_NFS", false ) ? TRUE : FALSE; // if job specifies a checkpoint server host, this overrides // the config file parameters tmp = NULL; if (JobAd->LookupString(ATTR_CKPT_SERVER, &tmp) == 1) { if (CkptServerHost) free(CkptServerHost); UseCkptServer = TRUE; CkptServerHost = strdup(tmp); StarterChoosesCkptServer = FALSE; free(tmp); } else { free(tmp); if (CkptServerHost) { free(CkptServerHost); } CkptServerHost = param( "CKPT_SERVER_HOST" ); UseCkptServer = FALSE; if( CkptServerHost && param_boolean_crufty( "USE_CKPT_SERVER", true ) ) { UseCkptServer = TRUE; } StarterChoosesCkptServer = param_boolean_crufty("STARTER_CHOOSES_CKPT_SERVER", true) ? TRUE : FALSE; } // Initialize location of our checkpoint file. If we stored it // on a checkpoint server then set LastCkptServer. Otherwise, // LastCkptServer should be NULL to indicate that we should // look on the local disk for our checkpoint file. LastCkptServer = NULL; if (JobAd->LookupString(ATTR_LAST_CKPT_SERVER, &LastCkptServer) == 0) { free(LastCkptServer); LastCkptServer = NULL; } // LIGO if (param_boolean("ALWAYS_USE_LOCAL_CKPT_SERVER", false)) { if (LastCkptServer) { char *remoteHost = NULL; JobAd->LookupString(ATTR_REMOTE_HOST, &remoteHost); char *machineName = strrchr(remoteHost, '@'); if (machineName == NULL) { machineName = remoteHost; } else { machineName++; } LastCkptServer = strdup(machineName); CkptServerHost = strdup(machineName); dprintf(D_ALWAYS, "ALWAYS_USE_LOCAL_CKPT_SERVER is true, forcing LastCkptServer to %s\n", LastCkptServer); } else { dprintf(D_ALWAYS, "ALWAYS_USE_LOCAL_CKPT_SERVER is true, but checkpoint is not on server, restoring file local file\n"); } } MaxDiscardedRunTime = param_integer( "MAX_DISCARDED_RUN_TIME", 3600 ); CompressPeriodicCkpt = param_boolean( "COMPRESS_PERIODIC_CKPT", false ); PeriodicSync = param_boolean( "PERIODIC_MEMORY_SYNC", false ); CompressVacateCkpt = param_boolean( "COMPRESS_VACATE_CKPT", false ); SlowCkptSpeed = param_integer( "SLOW_CKPT_SPEED", 0 ); // Install signal handlers such that all signals are blocked when inside // the handler. sigset_t fullset; sigfillset(&fullset); install_sig_handler_with_mask( SIGCHLD,&fullset, reaper ); // SIGUSR1 is sent by the schedd when a job is removed with // condor_rm. install_sig_handler_with_mask( SIGUSR1, &fullset, handle_sigusr1 ); // SIGQUIT is sent for a fast shutdow. install_sig_handler_with_mask( SIGQUIT, &fullset, handle_sigquit ); // SIGTERM is sent for a graceful shutdow. install_sig_handler_with_mask( SIGTERM, &fullset, handle_sigterm ); /* Here we block the async signals. We do this mainly because on HPUX, * XDR wigs out if it is interrupted by a signal. We do it on all * platforms because it seems like a safe idea. We unblock the signals * during before select(), which is where we spend most of our time. */ block_signal(SIGCHLD); block_signal(SIGUSR1); /* If the completed job had been committed to the job queue, but for some reason the shadow exited wierdly and the schedd is trying to run it again, then simply write the job termination events and send the email as if the job had just ended. */ if (terminate_is_pending() == TRUE) { /* This function will exit()! */ handle_terminate_pending(); } HandleSyscalls(); Wrapup(); /* HACK! WHOOO!!!!! Throw the old shadow away already! */ /* This will figure out whether or not the job should go on hold AFTER the job has exited for whatever reason, or if the job should be allowed to exit. It modifies ExitReason approriately for job holding, or, get this, just EXCEPTs if the jobs is supposed to go into idle state and not leave. :) */ /* Small change by Todd : only check the static policy if the job really exited of its own accord -- we don't want to even evaluate the static policy if the job exited because it was preempted, for instance */ if (check_static_policy && (ExitReason == JOB_EXITED || ExitReason == JOB_KILLED || ExitReason == JOB_COREDUMPED)) { static_policy(); } if( My_UID_Domain ) { free( My_UID_Domain ); } if( My_Filesystem_Domain ) { free( My_Filesystem_Domain ); } if(FILEObj) { delete FILEObj; } dprintf( D_ALWAYS, "********** Shadow Exiting(%d) **********\n", ExitReason ); exit( ExitReason ); }
void MachAttributes::compute( amask_t how_much ) { // the startd doesn't normally call the init() method (bug?), // it just starts calling compute, so in order to gurantee that // init happens, we put check here to see if user settings have been initialized if ( ! m_user_settings_init) init_user_settings(); if( IS_STATIC(how_much) && IS_SHARED(how_much) ) { // Since we need real values for them as soon as a // MachAttributes object is instantiated, we handle number // of CPUs and physical memory in the constructor, not // here. -Derek Wright 2/5/99 // Arch, OpSys, FileSystemDomain and UidDomain. Note: // these will always return something, since config() will // insert values if we don't have them in the config file. if( m_arch ) { free( m_arch ); } m_arch = param( "ARCH" ); if( m_opsys ) { free( m_opsys ); } m_opsys = param( "OPSYS" ); m_opsysver = param_integer( "OPSYSVER", 0 ); if( m_opsys_and_ver ) { free( m_opsys_and_ver ); } m_opsys_and_ver = param( "OPSYSANDVER" ); m_opsys_major_ver = param_integer( "OPSYSMAJORVER", 0 ); if( m_opsys_name ) { free( m_opsys_name ); } m_opsys_name = param( "OPSYSNAME" ); if( m_opsys_long_name ) { free( m_opsys_long_name ); } m_opsys_long_name = param( "OPSYSLONGNAME" ); if( m_opsys_short_name ) { free( m_opsys_short_name ); } m_opsys_short_name = param( "OPSYSSHORTNAME" ); if( m_opsys_legacy ) { free( m_opsys_legacy ); } m_opsys_legacy = param( "OPSYSLEGACY" ); // temporary attributes for raw utsname info if( m_utsname_sysname ) { free( m_utsname_sysname ); } if( m_utsname_nodename ) { free( m_utsname_nodename ); } if( m_utsname_release ) { free( m_utsname_release ); } if( m_utsname_version ) { free( m_utsname_version ); } if( m_utsname_machine ) { free( m_utsname_machine ); } m_utsname_sysname = param( "UTSNAME_SYSNAME" ); m_utsname_nodename = param( "UTSNAME_NODENAME" ); m_utsname_release = param( "UTSNAME_RELEASE" ); m_utsname_version = param( "UTSNAME_VERSION" ); m_utsname_machine = param( "UTSNAME_MACHINE" ); if( m_uid_domain ) { free( m_uid_domain ); } m_uid_domain = param( "UID_DOMAIN" ); dprintf( D_FULLDEBUG, "%s = \"%s\"\n", ATTR_UID_DOMAIN, m_uid_domain ); if( m_filesystem_domain ) { free( m_filesystem_domain ); } m_filesystem_domain = param( "FILESYSTEM_DOMAIN" ); dprintf( D_FULLDEBUG, "%s = \"%s\"\n", ATTR_FILE_SYSTEM_DOMAIN, m_filesystem_domain ); m_idle_interval = param_integer( "IDLE_INTERVAL", -1 ); // checkpoint platform signature if (m_ckptpltfrm) { free(m_ckptpltfrm); } const char * ckptpltfrm = param( ATTR_CHECKPOINT_PLATFORM ); if( ckptpltfrm == NULL ) { ckptpltfrm = sysapi_ckptpltfrm(); } m_ckptpltfrm = strdup( ckptpltfrm ); pair_strings_vector root_dirs = root_dir_list(); std::stringstream result; unsigned int chroot_count = 0; for (pair_strings_vector::const_iterator it=root_dirs.begin(); it != root_dirs.end(); ++it, ++chroot_count) { if (chroot_count) { result << ", "; } result << it->first; } if (chroot_count > 1) { std::string result_str = result.str(); dprintf(D_FULLDEBUG, "Named chroots: %s\n", result_str.c_str() ); m_named_chroot = result_str; } } if( IS_UPDATE(how_much) && IS_SHARED(how_much) ) { m_virt_mem = sysapi_swap_space(); dprintf( D_FULLDEBUG, "Swap space: %lu\n", m_virt_mem ); #if defined(WIN32) credd_test(); #endif } if( IS_TIMEOUT(how_much) && IS_SHARED(how_much) ) { m_load = sysapi_load_avg(); sysapi_idle_time( &m_idle, &m_console_idle ); time_t my_timer; struct tm *the_time; time( &my_timer ); the_time = localtime(&my_timer); m_clock_min = (the_time->tm_hour * 60) + the_time->tm_min; m_clock_day = the_time->tm_wday; if (m_last_keypress < my_timer - m_idle) { if (m_idle_interval >= 0) { int duration = my_timer - m_last_keypress; if (duration > m_idle_interval) { if (m_seen_keypress) { dprintf(D_IDLE, "end idle interval of %d sec.\n", duration); } else { dprintf(D_IDLE, "first keyboard event %d sec. after startup\n", duration); } } } m_last_keypress = my_timer; m_seen_keypress = true; } #ifdef WIN32 update_all_WinPerf_results(); #endif AttribValue *pav = NULL; m_lst_dynamic.Rewind(); while ((pav = m_lst_dynamic.Next()) ) { if (pav) { #ifdef WIN32 if ( ! update_WinPerf_Value(pav)) pav->vtype = AttribValue_DataType_Max; // undefined vtype #else if (pav->pquery) { // insert code to update pav from pav->pquery } #endif } } } if( IS_TIMEOUT(how_much) && IS_SUMMED(how_much) ) { m_condor_load = resmgr->sum( &Resource::condor_load ); if( m_condor_load > m_load ) { m_condor_load = m_load; } } }