Exemple #1
0
void
cleanup_execute_dirs( StringList &list )
{
	char const *exec_path;

	list.rewind();

	while( (exec_path = list.next()) ) {
#if defined(WIN32)
		dynuser nobody_login;
		// remove all users matching this prefix
		nobody_login.cleanup_condor_users("condor-run-");

		// get rid of everything in the execute directory
		Directory execute_dir(exec_path);

		execute_dir.Rewind();
		while ( execute_dir.Next() ) {
			check_recovery_file( execute_dir.GetFullPath() );
		}

		execute_dir.Remove_Entire_Directory();
#else
		// if we're using PrivSep, the Switchboard will only allow
		// us to remove subdirectories of EXECUTE - so we need to
		// list them and ask the Switchboard to delete each one
		//

		pair_strings_vector root_dirs = root_dir_list();
		for (pair_strings_vector::const_iterator it=root_dirs.begin(); it != root_dirs.end(); ++it) {
			const char * exec_path_full = dirscat(it->second.c_str(), exec_path);
			if(exec_path_full) {
				dprintf(D_FULLDEBUG, "Looking at %s\n",exec_path_full);
			}
			Directory execute_dir( exec_path_full, PRIV_ROOT );

			execute_dir.Rewind();
			while ( execute_dir.Next() ) {
				check_recovery_file( execute_dir.GetFullPath() );
			}

			if (privsep_enabled()) {
				execute_dir.Rewind();
				while (execute_dir.Next()) {
					dprintf(D_FULLDEBUG, "Attempting to remove %s\n",execute_dir.GetFullPath());
					privsep_remove_dir(execute_dir.GetFullPath());
				}
			}
			else {
				execute_dir.Remove_Entire_Directory();
			}
			delete [] exec_path_full;
		}
#endif
	}
}
Exemple #2
0
void
VMUniverseMgr::freeVM(pid_t s_pid)
{
	VMStarterInfo *info = findVMStarterInfoWithStarterPid(s_pid);
	if( !info ) {
		return;
	}

	MyString pid_dir;
	Directory execute_dir(info->m_execute_dir.Value(), PRIV_ROOT);
	pid_dir.formatstr("dir_%ld", (long)s_pid);

	if( execute_dir.Find_Named_Entry( pid_dir.Value() ) ) {
		// starter didn't exit cleanly,
		// maybe it seems to be killed by startd.
		// So we need to make sure that VM is really destroyed. 
		killVM(info);
	}

	m_vm_used_memory -= info->m_memory;
	m_vm_starter_list.Delete(info);
	delete info;

	if( !m_vm_starter_list.Number() && m_needCheck ) { 
		// the last vm job is just finished
		// if m_needCheck is true, we need to call docheckVMUniverse
		docheckVMUniverse();
	}
}
Exemple #3
0
void
cleanup_execute_dir(int pid, char const *exec_path, bool remove_exec_subdir)
{
	ASSERT( pid );

#if defined(WIN32)
	MyString buf;
	dynuser nobody_login;

	if ( nobody_login.reuse_accounts() == false ) {
	// before removing subdir, remove any nobody-user account associated
	// with this starter pid.  this account might have been left around
	// if the starter did not clean up completely.
	//sprintf(buf,"condor-run-dir_%d",pid);
		buf.formatstr("condor-run-%d",pid);
		if ( nobody_login.deleteuser(buf.Value()) ) {
			dprintf(D_FULLDEBUG,"Removed account %s left by starter\n",buf.Value());
		}
	}

	// now remove the subdirectory.  NOTE: we only remove the 
	// subdirectory _after_ removing the nobody account, because the
	// existence of the subdirectory persistantly tells us that the
	// account may still exist [in case the startd blows up as well].

	buf.formatstr( "%s\\dir_%d", exec_path, pid );
 
	check_recovery_file( buf.Value() );

	Directory dir( buf.Value() );
	dir.Remove_Full_Path(buf.Value());



#else /* UNIX */

	MyString	pid_dir;
	MyString pid_dir_path;

		// We're trying to delete a specific subdirectory, either
		// b/c a starter just exited and we might need to clean up
		// after it, or because we're in a recursive call.
	pid_dir.formatstr( "dir_%d", pid );
	pid_dir_path.formatstr( "%s/%s", exec_path, pid_dir.Value() );

	check_recovery_file( pid_dir_path.Value() );

		// if we're using PrivSep, we won't have the permissions
		// needed to clean up - ask the Switchboard to do it; but
		// before we do that, use stat to see if there's anything
		// to clean up and save the Switchboard invocation if not
	if (privsep_enabled()) {
		struct stat stat_buf;
		if (stat(pid_dir_path.Value(), &stat_buf) == -1) {
			return;
		}
		if (!privsep_remove_dir(pid_dir_path.Value())) {
			dprintf(D_ALWAYS,
			        "privsep_remove_dir failed to remove %s\n",
			        pid_dir_path.Value());
		}
		return;
	}

	// Instantiate a directory object pointing at the execute directory
	pair_strings_vector root_dirs = root_dir_list();
	for (pair_strings_vector::const_iterator it=root_dirs.begin(); it != root_dirs.end(); ++it) {
		const char * exec_path_full = dirscat(it->second.c_str(), exec_path);

		Directory execute_dir( exec_path_full, PRIV_ROOT );

		if (remove_exec_subdir) {
			// Remove entire subdirectory; used to remove
			// an encrypted execute directory
			execute_dir.Remove_Full_Path(exec_path_full);
		} else {
			// Look for specific pid_dir subdir
			if ( execute_dir.Find_Named_Entry( pid_dir.Value() ) ) {
				// Remove the execute directory
				execute_dir.Remove_Current_File();
			}
		}
		delete [] exec_path_full;
	}
#endif  /* UNIX */
}