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

📄 proc_names.c

📁 Sun Solaris 10 中的 DTrace 组件的源代码。请参看: http://www.sun.com/software/solaris/observability.jsp
💻 C
📖 第 1 页 / 共 2 页
字号:
	"getsockname",		/* 244 */	"getsockopt",		/* 245 */	"setsockopt",		/* 246 */	"sockconfig",		/* 247 */	"ntp_gettime",		/* 248 */	"ntp_adjtime",		/* 249 */	"lwp_mutex_unlock",	/* 250 */	"lwp_mutex_trylock",	/* 251 */	"lwp_mutex_init",	/* 252 */	"cladm",		/* 253 */	NULL,			/* 254 */	"umount2"		/* 255 */};/* SYSEND == max syscall number + 1 */#define	SYSEND	(sizeof (systable) / sizeof (systable[0]))/* * Return the name of a system call. * Manufacture a name for unknown system call. */char *proc_sysname(int sys, char *buf, size_t bufsz){	const char *name;	size_t len;	if (bufsz == 0)		/* force a program failure */		return (NULL);	if (sys >= 0 && sys < SYSEND)		name = systable[sys];	else		name = NULL;	if (name != NULL) {		len = strlen(name);		(void) strncpy(buf, name, bufsz);	} else {		len = snprintf(buf, bufsz, "SYS#%d", sys);	}	if (len >= bufsz)	/* ensure null-termination */		buf[bufsz-1] = '\0';	return (buf);}/* * Convert a string representation of a fault to the corresponding number. */intproc_str2flt(const char *str, int *fltnum){	char *next;	int i;	i = strtol(str, &next, 0);	if (i > 0 && i <= PRMAXFAULT && *next == '\0') {		*fltnum = i;		return (0);	}	for (i = 1; i <= PRMAXFAULT; i++) {		const char *s = rawfltname(i);		if (s && (strcasecmp(s, str) == 0 ||		    strcasecmp(s + 3, str) == 0)) {			*fltnum = i;			return (0);		}	}	return (-1);}/* * Convert a string representation of a signal to the signal number.  This * functionality is already available in libc, but the interface doesn't * optionally accept a "SIG" prefix.  We strip that first, and then call libc. */intproc_str2sig(const char *str, int *signum){	if (strncasecmp(str, "SIG", 3) == 0)		str += 3; /* skip prefix */	return (str2sig(str, signum));}/* * Convert a string representation of a system call to the corresponding number. * We do this by performing a simple linear search of the table above. */intproc_str2sys(const char *str, int *sysnum){	char *next;	int i;	i = strtol(str, &next, 0);	if (i > 0 && i <= PRMAXSYS && *next == '\0') {		*sysnum = i;		return (0);	}	for (i = 1; i < SYSEND; i++) {		if (systable[i] != NULL && strcmp(systable[i], str) == 0) {			*sysnum = i;			return (0);		}	}	return (-1);}/* * Convert a fltset_t to a string representation consisting of canonical * machine fault names separated by the given delimeter string.  If * m is non-zero (TRUE), set members are printed.  If m is zero (FALSE), set * non-members are printed.  If the specified buf is too small to hold the * complete formatted set, NULL is returned; otherwise buf is returned. */char *proc_fltset2str(const fltset_t *set, const char *delim, int m,	char *buf, size_t len){	char name[FLT2STR_MAX], *p = buf;	size_t n;	int i;	if (buf == NULL || len < 1) {		errno = EINVAL;		return (NULL);	}	buf[0] = '\0';  /* Set first byte to \0 */	for (i = 1; i <= PRMAXFAULT; i++) {		if ((prismember(set, i) != 0) ^ (m == 0)) {			(void) proc_fltname(i, name, sizeof (name));			if (buf[0] != '\0')				n = snprintf(p, len, "%s%s", delim, name);			else				n = snprintf(p, len, "%s", name);			if (n != strlen(p)) {				errno = ENAMETOOLONG; /* Output was truncated */				return (NULL);			}			len -= n;			p += n;		}	}	return (buf);}/* * Convert a sigset_t to a string representation consisting of canonical signal * names (without the SIG prefix). Parameters and return values analogous to * proc_fltset2str(). */char *proc_sigset2str(const sigset_t *set, const char *delim, int m,	char *buf, size_t len){	char name[SIG2STR_MAX], *p = buf;	size_t n;	int i;	if (buf == NULL || len < 1) {		errno = EINVAL;		return (NULL);	}	m = (m != 0);	/* Make sure m is 0 or 1 */	buf[0] = '\0';	/* Set first byte to \0 */	/*	 * Unlike proc_fltset2str() and proc_sysset2str(), we don't loop	 * until i <= NSIG here, because sigismember() rejects i == NSIG.	 */	for (i = 1; i < NSIG; i++) {		if (sigismember(set, i) == m) {			(void) sig2str(i, name);			if (buf[0] != '\0')				n = snprintf(p, len, "%s%s", delim, name);			else				n = snprintf(p, len, "%s", name);			if (n != strlen(p)) {				errno = ENAMETOOLONG; /* Output was truncated */				return (NULL);			}			len -= n;			p += n;		}	}	return (buf);}/* * Convert a sysset_t to a string representation consisting of canonical system * call names. Parameters and return values analogous to proc_fltset2str(). */char *proc_sysset2str(const sysset_t *set, const char *delim, int m,	char *buf, size_t len){	char name[SYS2STR_MAX], *p = buf;	size_t n;	int i;	if (buf == NULL || len < 1) {		errno = EINVAL;		return (NULL);	}	buf[0] = '\0';  /* Set first byte to \0 */	for (i = 1; i <= PRMAXSYS; i++) {		if ((prismember(set, i) != 0) ^ (m == 0)) {			(void) proc_sysname(i, name, sizeof (name));			if (buf[0] != '\0')				n = snprintf(p, len, "%s%s", delim, name);			else				n = snprintf(p, len, "%s", name);			if (n != strlen(p)) {				errno = ENAMETOOLONG; /* Output was truncated */				return (NULL);			}			len -= n;			p += n;		}	}	return (buf);}/* * Convert a string representation of a fault set (names separated by * one or more of the given delimeters) to a fltset_t. * If m is non-zero (TRUE), members of the string representation are set. * If m is zero (FALSE), non-members of the string representation are set. * This function returns NULL for success. Otherwise it returns a pointer * to the token of the string that couldn't be identified as a string * representation of a fault. */char *proc_str2fltset(const char *s, const char *delim, int m, fltset_t *set){	char *p, *q, *t = alloca(strlen(s) + 1);	int flt;	if (m) {		premptyset(set);	} else {		prfillset(set);	}	(void) strcpy(t, s);	for (p = strtok_r(t, delim, &q); p != NULL;	    p = strtok_r(NULL, delim, &q)) {		if (proc_str2flt(p, &flt) == -1) {			errno = EINVAL;			return ((char *)s + (p - t));		}		if (m)			praddset(set, flt);		else			prdelset(set, flt);	}	return (NULL);}/* * Convert a string representation of a signal set (names with or without the * SIG prefix separated by one or more of the given delimeters) to a sigset_t. * Parameters and return values analogous to proc_str2fltset(). */char *proc_str2sigset(const char *s, const char *delim, int m, sigset_t *set){	char *p, *q, *t = alloca(strlen(s) + 1);	int sig;	if (m) {		premptyset(set);	} else {		prfillset(set);	}	(void) strcpy(t, s);	for (p = strtok_r(t, delim, &q); p != NULL;	    p = strtok_r(NULL, delim, &q)) {		if (proc_str2sig(p, &sig) == -1) {			errno = EINVAL;			return ((char *)s + (p - t));		}		if (m)			praddset(set, sig);		else			prdelset(set, sig);	}	return (NULL);}/* * Convert a string representation of a system call set (names separated by * one or more of the given delimeters) to a sysset_t. Parameters and return * values analogous to proc_str2fltset(). */char *proc_str2sysset(const char *s, const char *delim, int m, sysset_t *set){	char *p, *q, *t = alloca(strlen(s) + 1);	int sys;	if (m) {		premptyset(set);	} else {		prfillset(set);	}	(void) strcpy(t, s);	for (p = strtok_r(t, delim, &q); p != NULL;	    p = strtok_r(NULL, delim, &q)) {		if (proc_str2sys(p, &sys) == -1) {			errno = EINVAL;			return ((char *)s + (p - t));		}		if (m)			praddset(set, sys);		else			prdelset(set, sys);	}	return (NULL);}

⌨️ 快捷键说明

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