Ejemplo n.º 1
0
    /**
       Gets the MaxProcessesPerUser
       \param[out]  mppu
       \returns     true if this value is supported by the implementation

       According to the CIM model:
       A value that indicates the maximum processes that a user
       can have associate with it.
    */
    bool OSInstance::GetMaxProcessesPerUser(unsigned int& mppu) const
    {
#if defined(linux) || defined(sun)
        // Not supported on Solaris, for some reason. We reuse the Linux code. 
        // Here's the Pegasus implementation for Linux. Spot the problem?
        // return sysconf(_SC_CHILD_MAX);
        long res = sysconf(_SC_CHILD_MAX);

        if (res == -1 && errno == 0)
        {
            res = INT_MAX;
        }

        mppu = static_cast<unsigned int>(res);

        return (res >= 0);
#elif defined(hpux)
        // We could use the same sysconf() call as on Linux,

        // but Pegasus uses gettune(), and so do we.
        uint64_t maxuprc = 0;
        if (gettune("maxuprc", &maxuprc) != 0)
        {
            return false;
        }
        mppu = maxuprc;
        return true;
#elif defined(aix)
        // Not supported in the Pegasus implementation for AIX.
        (void) mppu;
        return false;
#else
        #error Platform not supported
#endif
    }
Ejemplo n.º 2
0
/*
 * Using value of sp is very rough... To make it more real,
 * addr would need to be aligned to vps_pagesize.
 * The vps_pagesize is 'Default user page size (kBytes)'
 * and could be retrieved by gettune().
 */
static int
hpux_attr_getstackaddr(const pthread_attr_t *attr, void **addr)
{
    static uint64_t pagesize;
    size_t size;

    if (!pagesize) {
	if (gettune("vps_pagesize", &pagesize)) {
	    pagesize = 16;
	}
	pagesize *= 1024;
    }
    pthread_attr_getstacksize(attr, &size);
    *addr = (void *)((size_t)((char *)_Asm_get_sp() - size) & ~(pagesize - 1));
    return 0;
}
Ejemplo n.º 3
0
    /**
       Gets the MaxProcessMemorySize
       \param[out]  mpms
       \returns     true if this value is supported by the implementation

       According to the CIM model:
       Maximum number of Kbytes of memory that can be allocated
       to a Process. For Operating Systems with no virtual memory,
       this value is typically equal to the total amount of
       physical Memory minus memory used by the BIOS and OS. For
       some Operating Systems, this value may be infinity - in
       which case, 0 should be entered. In other cases, this value
       could be a constant - for example, 2G or 4G.
    */
    bool OSInstance::GetMaxProcessMemorySize(scxulong& mpms) const
    {
#if defined(linux) || defined(sun)
        struct rlimit rls;

        int res = getrlimit(RLIMIT_AS, &rls);
        if (0 == res)
        {
            if (RLIM_INFINITY == rls.rlim_max)
            {
                mpms = 0;
            }
            else
            {
                mpms = rls.rlim_max / 1024;
            }
        }
        return res == 0;
#elif defined(hpux)
        // Pegasus implements a very elaborate scheme that supports many
        // different versions of HP/UX through various mechanisms to get 
        // kernel configuration data. Since we only support 11v3 and on 
        // we can cut out all the older stuff and just reuse what we need.
        // But corrected to return the output in Kilobytes.

        const static char *maxsiz[3][2] = { { "maxdsiz", "maxdsiz_64bit" },
                                            { "maxssiz", "maxssiz_64bit" },
                                            { "maxtsiz", "maxtsiz_64bit" }};
        int is64 = sysconf(_SC_KERNEL_BITS) == 64 ? 1 : 0;
        uint64_t data = 0, sum = 0;
        for (int i = 0; i < 3; i++) {
            if (gettune(maxsiz[i][is64], &data) != 0) { return false; }
            sum += data;
        }
        mpms = sum / 1024;
        return true;
#elif defined(aix)
        // Not supported in the Pegasus implementation for AIX.
        (void) mpms;
        return false;
#else
        #error Platform not supported
#endif
    }
Ejemplo n.º 4
0
isc_result_t
isc_resource_setlimit(isc_resource_t resource, isc_resourcevalue_t value) {
	struct rlimit rl;
	ISC_PLATFORM_RLIMITTYPE rlim_value;
	int unixresult;
	int unixresource;
	isc_result_t result;

	result = resource2rlim(resource, &unixresource);
	if (result != ISC_R_SUCCESS)
		return (result);

	if (value == ISC_RESOURCE_UNLIMITED)
		rlim_value = RLIM_INFINITY;

	else {
		/*
		 * isc_resourcevalue_t was chosen as an unsigned 64 bit
		 * integer so that it could contain the maximum range of
		 * reasonable values.  Unfortunately, this exceeds the typical
		 * range on Unix systems.  Ensure the range of
		 * ISC_PLATFORM_RLIMITTYPE is not overflowed.
		 */
		isc_resourcevalue_t rlim_max;
		isc_boolean_t rlim_t_is_signed =
			ISC_TF(((double)(ISC_PLATFORM_RLIMITTYPE)-1) < 0);

		if (rlim_t_is_signed)
			rlim_max = ~((ISC_PLATFORM_RLIMITTYPE)1 <<
				     (sizeof(ISC_PLATFORM_RLIMITTYPE) * 8 - 1));
		else
			rlim_max = (ISC_PLATFORM_RLIMITTYPE)-1;

		if (value > rlim_max)
			value = rlim_max;

		rlim_value = value;
	}

	rl.rlim_cur = rl.rlim_max = rlim_value;
	unixresult = setrlimit(unixresource, &rl);

	if (unixresult == 0)
		return (ISC_R_SUCCESS);

#if defined(OPEN_MAX) && defined(__APPLE__)
	/*
	 * The Darwin kernel doesn't accept RLIM_INFINITY for rlim_cur; the
	 * maximum possible value is OPEN_MAX.  BIND8 used to use
	 * sysconf(_SC_OPEN_MAX) for such a case, but this value is much
	 * smaller than OPEN_MAX and is not really effective.
	 */
	if (resource == isc_resource_openfiles && rlim_value == RLIM_INFINITY) {
		rl.rlim_cur = OPEN_MAX;
		unixresult = setrlimit(unixresource, &rl);
		if (unixresult == 0)
			return (ISC_R_SUCCESS);
	}
#elif defined(__linux__)
#ifndef NR_OPEN
#define NR_OPEN (1024*1024)
#endif

	/*
	 * Some Linux kernels don't accept RLIM_INFINIT; the maximum
	 * possible value is the NR_OPEN defined in linux/fs.h.
	 */
	if (resource == isc_resource_openfiles && rlim_value == RLIM_INFINITY) {
		rl.rlim_cur = rl.rlim_max = NR_OPEN;
		unixresult = setrlimit(unixresource, &rl);
		if (unixresult == 0)
			return (ISC_R_SUCCESS);
	}
#elif defined(__hpux) && defined(HAVE_SYS_DYNTUNE_H)
	if (resource == isc_resource_openfiles && rlim_value == RLIM_INFINITY) {
		uint64_t maxfiles;
		if (gettune("maxfiles_lim", &maxfiles) == 0) {
			rl.rlim_cur = rl.rlim_max = maxfiles;
			unixresult = setrlimit(unixresource, &rl);
			if (unixresult == 0)
				return (ISC_R_SUCCESS);
		}
	}
#endif
	if (resource == isc_resource_openfiles && rlim_value == RLIM_INFINITY) {
		if (getrlimit(unixresource, &rl) == 0) {
			rl.rlim_cur = rl.rlim_max;
			unixresult = setrlimit(unixresource, &rl);
			if (unixresult == 0)
				return (ISC_R_SUCCESS);
		}
	}
	return (isc__errno2result(errno));
}