コード例 #1
0
int BackupStoreAccountsControl::BlockSizeOfDiscSet(int discSetNum)
{
	// Get controller, check disc set number
	RaidFileController &controller(RaidFileController::GetController());
	if(discSetNum < 0 || discSetNum >= controller.GetNumDiscSets())
	{
		BOX_FATAL("Disc set " << discSetNum << " does not exist.");
		exit(1);
	}
	
	// Return block size
	return controller.GetDiscSet(discSetNum).GetBlockSize();
}
コード例 #2
0
bool checkfilesleftopen()
{
	if(!filedes_initialised)
	{
		// Not used correctly, pretend that there were things 
		// left open so this gets investigated
		BOX_FATAL("File descriptor test was not initialised");
		return false;
	}

	// Count the file descriptors open
	return check_filedes(true);
}
コード例 #3
0
bool check_filedes(bool report)
{
	bool allOk = true;

	// See how many file descriptors there are with values < 256.
	// In order to avoid disturbing things, we scan the file descriptors
	// first, marking the ones that were OPEN at startup (report == FALSE)
	// as STILLOPEN and the ones that were not as LEAKED. Then we run
	// through again and print the results.
	for(int d = 0; d < FILEDES_MAX; ++d)
	{
		if(::fcntl(d, F_GETFD) != -1)
		{
			// File descriptor obviously exists, but is it /dev/log?
			// Mark it as OPEN for now, and we'll find out later.
			if(report)
			{
				if(filedes_open[d] == OPEN)
				{
					filedes_open[d] = STILLOPEN;
				}
				else
				{
					filedes_open[d] = LEAKED;
				}
			}
			else
			{
				filedes_open[d] = OPEN;
			}
		}
		else
		{
			filedes_open[d] = CLOSED;
		}
	}

	if(!report)
	{
		filedes_initialised = true;
		return true;
	}

	// Now loop again, reporting differences.
	for(int d = 0; d < FILEDES_MAX; ++d)
	{
		if(filedes_open[d] != LEAKED)
		{
			continue;
		}

		bool stat_success = false;
		struct stat st;
		if(fstat(d, &st) == 0)
		{
			stat_success = true;

			if(st.st_mode & S_IFSOCK)
			{
				char buffer[256];
				socklen_t addrlen = sizeof(buffer);

#ifdef HAVE_GETPEERNAME
				if(getpeername(d, (sockaddr*)buffer, &addrlen) != 0)
				{
					BOX_LOG_SYS_WARNING("Failed to getpeername(" << 
						d << "), cannot identify /dev/log");
				}
				else
				{
					struct sockaddr_un *sa = 
						(struct sockaddr_un *)buffer;
					if(sa->sun_family == PF_UNIX &&
						!strcmp(sa->sun_path, "/dev/log"))
					{
						// it's a syslog socket, ignore it
						filedes_open[d] = SYSLOG;
					}
				}
#endif // HAVE_GETPEERNAME
			}
		}

		if(filedes_open[d] == SYSLOG)
		{
			// Different libcs have different ideas
			// about when to open and close this
			// socket, and it's not a leak, so
			// ignore it.
		}
		else if(stat_success)
		{
			int m = st.st_mode;
			#define flag(x) ((m & x) ? #x " " : "")
			BOX_FATAL("File descriptor " << d << 
				" left open (type == " <<
				flag(S_IFIFO) <<
				flag(S_IFCHR) <<
				flag(S_IFDIR) <<
				flag(S_IFBLK) <<
				flag(S_IFREG) <<
				flag(S_IFLNK) <<
				flag(S_IFSOCK) <<
				" or " << m << ")");
			allOk = false;
		}
		else
		{
			BOX_FATAL("File descriptor " << d << 
				" left open (and stat failed)");
			allOk = false;
		}
	}

	if (!report && allOk)
	{
		filedes_initialised = true;
	}
	
	return allOk;
}