⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mom_mach.c

📁 OpenPBS
💻 C
📖 第 1 页 / 共 4 页
字号:
availmem(attrib)struct	rm_attribute	*attrib;{	char	*id = "availmem";	struct	statfs	fsbuf;	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (statfs(procfs, &fsbuf, sizeof(struct statfs), 0) == -1) {		log_err(errno, id, "statfs");		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	DBPRT(("%s: bsize=%ld bfree=%lld\n", id,		fsbuf.f_bsize, fsbuf.f_bfree))	sprintf(ret_string, "%llukb", 		((rlim64_t)fsbuf.f_bsize * (rlim64_t)fsbuf.f_bfree) >> 10);	return ret_string;}static char	*ncpus(attrib)struct	rm_attribute	*attrib;{	char		*id = "ncpus";	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	sprintf(ret_string, "%ld", sysmp(MP_NAPROCS));	return ret_string;}/* * physmem() - return amount of physical memory in system in KB as string */static char	*physmem(attrib)struct	rm_attribute	*attrib;{	char		*id = "physmem";	unsigned int	pmem;	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (lseek(kfd, (off_t)kern_addr[KSYM_PHYS], SEEK_SET) == -1) {		sprintf(log_buffer, "lseek to 0x%llx", kern_addr[KSYM_PHYS]);		log_err(errno, id, log_buffer);		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	if (read(kfd, (char *)&pmem, sizeof(pmem)) != sizeof(pmem)) {		log_err(errno, id, "read");		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	sprintf(ret_string, "%llukb",((rlim64_t)pmem*(rlim64_t)pagesize) >> 10);	return ret_string;}/* * size_fs() - return file system size in Kb as string  */char	*size_fs(param)char	*param;{	char		*id = "size_fs";	struct	statfs	fsbuf;	if (param[0] != '/') {		sprintf(log_buffer, "%s: not full path filesystem name: %s\n",			id, param);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (statfs(param, &fsbuf, sizeof(struct statfs), 0) == -1) {		log_err(errno, id, "statfs");		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	sprintf(ret_string, "%llukb", 		((rlim64_t)fsbuf.f_bsize * (rlim64_t)fsbuf.f_bfree) >> 10);	return ret_string;}/* * size_file() - return file size in Kb as string  */char	*size_file(param)char	*param;{	char		*id = "size_file";	struct	stat64   sbuf;	if (param[0] != '/') {		sprintf(log_buffer, "%s: not full path filesystem name: %s\n",			id, param);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (stat64(param, &sbuf) == -1) {		log_err(errno, id, "stat");		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	sprintf(ret_string, "%llukb", (sbuf.st_size+512)>>10);	return ret_string;}char	*size(attrib)struct	rm_attribute	*attrib;{	char	*id = "size";	char	*param;	if (attrib == NULL) {		log_err(-1, id, no_parm);		rm_errno = RM_ERR_NOPARAM;		return NULL;	}	if (momgetattr(NULL)) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	param = attrib->a_value;	if (strcmp(attrib->a_qualifier, "file") == 0)		return (size_file(param));	else if (strcmp(attrib->a_qualifier, "fs") == 0)		return (size_fs(param));	else {		rm_errno = RM_ERR_BADPARAM;		return NULL;	}}time_t	maxtm;static voidsetmax(dev)char	*dev;{	struct	stat	sb;	if (stat(dev, &sb) == -1)		return;	if (maxtm < sb.st_atime)		maxtm = sb.st_atime;	return;}char	*idletime(attrib)struct	rm_attribute	*attrib;{	char	*id = "idletime";	DIR	*dp;	struct	dirent	*de;	char	ttyname[50];	time_t	curtm;	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if ((dp=opendir("/dev")) == NULL) {		log_err(errno, id, "opendir /dev");		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	maxtm = 0;	curtm = time(NULL);	setmax("/dev/mouse");	while ((de=readdir(dp)) != NULL) {		if (maxtm >= curtm)			break;		if (strncmp(de->d_name, "tty", 3))			continue;		sprintf(ttyname, "/dev/%s", de->d_name);		setmax(ttyname);	}	closedir(dp);	sprintf(ret_string, "%d", MAX(0, curtm - maxtm));	return ret_string;}intget_la(rv)	double	*rv;{	char	*id = "get_la";	int 	load;	if (lseek(kfd, (off_t)kern_addr[KSYM_LOAD], SEEK_SET) == -1) {		sprintf(log_buffer, "lseek to 0x%llx", kern_addr[KSYM_LOAD]);		log_err(errno, id, log_buffer);		return (rm_errno = RM_ERR_SYSTEM);	}	if (read(kfd, (char *)&load, sizeof(load)) != sizeof(load)) {		log_err(errno, id, "read");		return (rm_errno = RM_ERR_SYSTEM);	}	/*	** SGI does not have FSCALE like the SUN so the 1024	** divisor was found by experment compairing the result	** of this routine to uptime.	*/	*rv = (double)load/1024.0;	return 0;}u_longgracetime(secs)u_long	secs;{	time_t	now = time((time_t *)NULL);	if (secs > now)		/* time is in the future */		return (secs - now);	else		return 0;}static char	*quota(attrib)struct	rm_attribute	*attrib;{	char	*id = "quota";	int			type;	dev_t			dirdev;	uid_t			uid;	struct	stat		sb;	struct	mntent		*me;	struct	dqblk		qi;	FILE			*m;	struct	passwd		*pw;	static	char		*type_array[] = {		"harddata",		"softdata",		"currdata",		"hardfile",		"softfile",		"currfile",		"timedata",		"timefile",	};	enum	type_name {		harddata,		softdata,		currdata,		hardfile,		softfile,		currfile,		timedata,		timefile,		type_end	};	if (attrib == NULL) {		log_err(-1, id, no_parm);		rm_errno = RM_ERR_NOPARAM;		return NULL;	}	if (strcmp(attrib->a_qualifier, "type")) {		sprintf(log_buffer, "unknown qualifier %s",			attrib->a_qualifier);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}			for (type=0; type<type_end; type++) {		if (strcmp(attrib->a_value, type_array[type]) == 0)			break;	}	if (type == type_end) {		/* check to see if command is legal */		sprintf(log_buffer, "bad param: %s=%s",			attrib->a_qualifier, attrib->a_value);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if ((attrib = momgetattr(NULL)) == NULL) {		log_err(-1, id, no_parm);		rm_errno = RM_ERR_NOPARAM;		return NULL;	}	if (strcmp(attrib->a_qualifier, "dir") != 0) {		sprintf(log_buffer, "bad param: %s=%s",			attrib->a_qualifier, attrib->a_value);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (attrib->a_value[0] != '/') {	/* must be absolute path */		sprintf(log_buffer,			"not an absolute path: %s", attrib->a_value);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if (stat(attrib->a_value, &sb) == -1) {		sprintf(log_buffer, "stat: %s", attrib->a_value);		log_err(errno, id, log_buffer);		rm_errno = RM_ERR_EXIST;		return NULL;	}	dirdev = sb.st_dev;	DBPRT(("dir has devnum %d\n", dirdev))	if ((m = setmntent(MOUNTED, "r")) == NULL) {		log_err(errno, id, "setmntent");		rm_errno = RM_ERR_SYSTEM;                return NULL;        }	while ((me = getmntent(m)) != NULL) {		if (strcmp(me->mnt_type, MNTTYPE_IGNORE) == 0)			continue;		if (stat(me->mnt_dir, &sb) == -1) {			sprintf(log_buffer, "stat: %s", me->mnt_dir);			log_err(errno, id, log_buffer);			continue;		}		DBPRT(("%s\t%s\t%d\n", me->mnt_fsname, me->mnt_dir, sb.st_dev))		if (sb.st_dev == dirdev)			break;	}	endmntent(m);	if (me == NULL)	{		sprintf(log_buffer,			"filesystem %s not found", attrib->a_value);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_EXIST;		return NULL;	}	if (hasmntopt(me, MNTOPT_QUOTA) == NULL) {		sprintf(log_buffer,			"no quotas on filesystem %s", me->mnt_dir);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_EXIST;		return NULL;	}	if ((attrib = momgetattr(NULL)) == NULL) {		log_err(-1, id, no_parm);		rm_errno = RM_ERR_NOPARAM;		return NULL;	}	if (strcmp(attrib->a_qualifier, "user") != 0) {		sprintf(log_buffer, "bad param: %s=%s",			attrib->a_qualifier, attrib->a_value);		log_err(-1, id, log_buffer);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	if ((uid = (uid_t)atoi(attrib->a_value)) == 0) {		if ((pw = getpwnam(attrib->a_value)) == NULL) {			sprintf(log_buffer,				"user not found: %s", attrib->a_value);			log_err(-1, id, log_buffer);			rm_errno = RM_ERR_EXIST;			return NULL;		}		uid = pw->pw_uid;	}	if (quotactl(Q_GETQUOTA, me->mnt_fsname, uid, (caddr_t)&qi) == -1) {		log_err(errno, id, "quotactl");		rm_errno = RM_ERR_SYSTEM;		return NULL;	}	/* all size values in KB */	switch (type) {	case harddata:		sprintf(ret_string, "%ukb", BBTOB(qi.dqb_bhardlimit) >> 10);		break;	case softdata:		sprintf(ret_string, "%ukb", BBTOB(qi.dqb_bsoftlimit) >> 10);		break;	case currdata:		sprintf(ret_string, "%ukb", BBTOB(qi.dqb_curblocks) >> 10);		break;	case hardfile:		sprintf(ret_string, "%u", qi.dqb_fhardlimit);		break;	case softfile:		sprintf(ret_string, "%u", qi.dqb_fsoftlimit);		break;	case currfile:		sprintf(ret_string, "%u", qi.dqb_curfiles);		break;	case timedata:		sprintf(ret_string, "%lu",gracetime((u_long)qi.dqb_btimelimit));		break;	case timefile:		sprintf(ret_string, "%lu",gracetime((u_long)qi.dqb_ftimelimit));		break;	}	return ret_string;}#if	NODEMASK != 0#define MAXCNODES 64	/* Maximum number of nodes available in a nodemask. *//*** Return a MAXCNODES-bit string with a '1' in each position where there** are two CPUs available for a node.*/static char    *availmask(attrib)    struct	rm_attribute	*attrib;{	char		*id = "availmask";	int		nprocs, i;	cnodeid_t	cpumap[MAXCNODES * 2];	char		nodect[MAXCNODES];	if (attrib) {		log_err(-1, id, extra_parm);		rm_errno = RM_ERR_BADPARAM;		return NULL;	}	/* Initialize cpu/node count and cpumap. */	for (i = 0; i < MAXCNODES; i++) {		nodect[i] = 0;		cpumap[i * 2] = cpumap[i * 2 + 1] = -1;	}	nprocs = sysmp(MP_NPROCS);	if (nprocs < 1) {		log_err(errno, id, "sysmp(MP_NPROCS");		rm_errno = RM_ERR_SYSTEM;		return (NULL);	}	if (sysmp(MP_NUMA_GETCPUNODEMAP, (void *)cpumap, 	    sizeof(cnodeid_t) * nprocs) != 0) 	{		log_err(errno, id, "sysmp(MP_NUMA_GETCPUNODEMAP");		rm_errno = RM_ERR_SYSTEM;		return (NULL);	}	/* 	 * cpumap[] now contains either -1, or the number of the node that	 * corresponds to that CPU.  Each node needs to have 2 CPUs - count 	 * up the references to each node, and generate the return string 	 * based on whether exactly 2 CPUs map to the node at the n'th 	 * position (from the right) or not.	 */	for (i = 0; i < MAXCNODES * 2; i++)		if (cpumap[i] != (cnodeid_t)(-1))			nodect[cpumap[i]] ++;	/* Create the null-terminated string for the nodect ref'd in map[]. */	for (i = 0; i < MAXCNODES; i++)		ret_string[MAXCNODES - (i + 1)] = (nodect[i] == 2 ? '1' : '0');	ret_string[i] = '\0';		return ret_string;}#endif /* NODEMASK */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -