xref: /onnv-gate/usr/src/lib/mpss/common/mpss.c (revision 1914:8a8c5f225b1b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1914Scasper  * Common Development and Distribution License (the "License").
6*1914Scasper  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*1914Scasper  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <stdio.h>
290Sstevel@tonic-gate #include <stdlib.h>
300Sstevel@tonic-gate #include <strings.h>
310Sstevel@tonic-gate #include <sys/mman.h>
320Sstevel@tonic-gate #include <fcntl.h>
330Sstevel@tonic-gate #include <stdlib.h>
340Sstevel@tonic-gate #include <unistd.h>
350Sstevel@tonic-gate #include <errno.h>
360Sstevel@tonic-gate #include <sys/types.h>
370Sstevel@tonic-gate #include <sys/stat.h>
380Sstevel@tonic-gate #include <sys/auxv.h>
390Sstevel@tonic-gate #include <stdarg.h>
400Sstevel@tonic-gate #include <syslog.h>
410Sstevel@tonic-gate #include <sys/param.h>
420Sstevel@tonic-gate #include <sys/sysmacros.h>
430Sstevel@tonic-gate #include <procfs.h>
440Sstevel@tonic-gate #include <libintl.h>
450Sstevel@tonic-gate #include <locale.h>
460Sstevel@tonic-gate 
470Sstevel@tonic-gate extern int	gmatch(const char *s, const char *p);
480Sstevel@tonic-gate 
490Sstevel@tonic-gate #pragma init(__mpssmain)
500Sstevel@tonic-gate 
510Sstevel@tonic-gate static const char *mpssident = "mpss.so.1";
520Sstevel@tonic-gate 
530Sstevel@tonic-gate /* environment variables */
540Sstevel@tonic-gate 
550Sstevel@tonic-gate #define	ENV_MPSSCFGFILE		"MPSSCFGFILE"
560Sstevel@tonic-gate #define	ENV_MPSSSTACK		"MPSSSTACK"
570Sstevel@tonic-gate #define	ENV_MPSSHEAP		"MPSSHEAP"
580Sstevel@tonic-gate #define	ENV_MPSSERRFILE		"MPSSERRFILE"
590Sstevel@tonic-gate 
600Sstevel@tonic-gate #define	MPSSHEAP	0
610Sstevel@tonic-gate #define	MPSSSTACK	1
620Sstevel@tonic-gate 
630Sstevel@tonic-gate /* config file */
640Sstevel@tonic-gate 
650Sstevel@tonic-gate #define	DEF_MPSSCFGFILE		"/etc/mpss.conf"
660Sstevel@tonic-gate #define	MAXLINELEN	MAXPATHLEN + 64
670Sstevel@tonic-gate #define	CFGDELIMITER	':'
680Sstevel@tonic-gate #define	ARGDELIMITER	' '
690Sstevel@tonic-gate 
700Sstevel@tonic-gate /*
710Sstevel@tonic-gate  * avoid malloc which causes certain applications to crash
720Sstevel@tonic-gate  */
730Sstevel@tonic-gate static char		lbuf[MAXLINELEN];
740Sstevel@tonic-gate static char		pbuf[MAXPATHLEN];
750Sstevel@tonic-gate 
760Sstevel@tonic-gate #ifdef MPSSDEBUG
770Sstevel@tonic-gate #define	ENV_MPSSDEBUG	"MPSSDEBUG"
780Sstevel@tonic-gate #define	MPSSPRINT(x, y)	if (mpssdebug & x) (void) fprintf y;
790Sstevel@tonic-gate 
800Sstevel@tonic-gate static int		mpssdebug;
810Sstevel@tonic-gate #else
820Sstevel@tonic-gate #define	MPSSPRINT(x, y)
830Sstevel@tonic-gate #endif
840Sstevel@tonic-gate 
850Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
860Sstevel@tonic-gate #define	TEXT_DOMAIN	"SYS_TEST"
870Sstevel@tonic-gate #endif
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /*PRINTFLIKE2*/
900Sstevel@tonic-gate static void
mpsserr(FILE * fp,char * fmt,...)910Sstevel@tonic-gate mpsserr(FILE *fp, char *fmt, ...)
920Sstevel@tonic-gate {
930Sstevel@tonic-gate 	va_list		ap;
940Sstevel@tonic-gate 	va_start(ap, fmt);
950Sstevel@tonic-gate 	if (fp)
960Sstevel@tonic-gate 		(void) vfprintf(fp, fmt, ap);
970Sstevel@tonic-gate 	else
980Sstevel@tonic-gate 		vsyslog(LOG_ERR, fmt, ap);
990Sstevel@tonic-gate 	va_end(ap);
1000Sstevel@tonic-gate }
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate /*
1030Sstevel@tonic-gate  * Return the pointer to the fully-resolved path name of the process's
1040Sstevel@tonic-gate  * executable file obtained from the AT_SUN_EXECNAME aux vector entry.
1050Sstevel@tonic-gate  */
1060Sstevel@tonic-gate static const char *
mygetexecname(void)1070Sstevel@tonic-gate mygetexecname(void)
1080Sstevel@tonic-gate {
1090Sstevel@tonic-gate 	const char	*execname = NULL;
1100Sstevel@tonic-gate 	static auxv_t	auxb;
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 	/*
1130Sstevel@tonic-gate 	 * The first time through, read the initial aux vector that was
1140Sstevel@tonic-gate 	 * passed to the process at exec(2).  Only do this once.
1150Sstevel@tonic-gate 	 */
1160Sstevel@tonic-gate 	int fd = open("/proc/self/auxv", O_RDONLY);
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 	if (fd >= 0) {
1190Sstevel@tonic-gate 		while (read(fd, &auxb, sizeof (auxv_t)) == sizeof (auxv_t)) {
1200Sstevel@tonic-gate 			if (auxb.a_type == AT_SUN_EXECNAME) {
1210Sstevel@tonic-gate 				execname = auxb.a_un.a_ptr;
1220Sstevel@tonic-gate 				break;
1230Sstevel@tonic-gate 			}
1240Sstevel@tonic-gate 		}
1250Sstevel@tonic-gate 		(void) close(fd);
1260Sstevel@tonic-gate 	}
1270Sstevel@tonic-gate 	return (execname);
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate static size_t
atosz(char * szstr)1310Sstevel@tonic-gate atosz(char *szstr)
1320Sstevel@tonic-gate {
1330Sstevel@tonic-gate 	size_t		sz;
1340Sstevel@tonic-gate 	char		*endptr, c;
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 	sz = strtoll(szstr, &endptr, 0);
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 	while (c = *endptr++) {
1390Sstevel@tonic-gate 		switch (c) {
1400Sstevel@tonic-gate 		case 't':
1410Sstevel@tonic-gate 		case 'T':
1420Sstevel@tonic-gate 			sz *= 1024;
1430Sstevel@tonic-gate 		/*FALLTHRU*/
1440Sstevel@tonic-gate 		case 'g':
1450Sstevel@tonic-gate 		case 'G':
1460Sstevel@tonic-gate 			sz *= 1024;
1470Sstevel@tonic-gate 		/*FALLTHRU*/
1480Sstevel@tonic-gate 		case 'm':
1490Sstevel@tonic-gate 		case 'M':
1500Sstevel@tonic-gate 			sz *= 1024;
1510Sstevel@tonic-gate 		/*FALLTHRU*/
1520Sstevel@tonic-gate 		case 'k':
1530Sstevel@tonic-gate 		case 'K':
1540Sstevel@tonic-gate 			sz *= 1024;
1550Sstevel@tonic-gate 		default:
1560Sstevel@tonic-gate 			break;
1570Sstevel@tonic-gate 		}
1580Sstevel@tonic-gate 	}
1590Sstevel@tonic-gate 	return (sz);
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate }
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate #define	PGSZELEM	(8 * sizeof (void *))
1640Sstevel@tonic-gate static size_t		pgsz[PGSZELEM];
1650Sstevel@tonic-gate static int		nelem;
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate static int
pgszok(size_t sz)1680Sstevel@tonic-gate pgszok(size_t sz)
1690Sstevel@tonic-gate {
1700Sstevel@tonic-gate 	int		i;
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate 	if (sz == 0)
1730Sstevel@tonic-gate 		return (1);
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 	for (i = 0; i < nelem; i++) {
1760Sstevel@tonic-gate 		if (sz == pgsz[i])
1770Sstevel@tonic-gate 			break;
1780Sstevel@tonic-gate 	}
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate 	return (i < nelem);
1810Sstevel@tonic-gate }
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate static void
pgszinit()1840Sstevel@tonic-gate pgszinit()
1850Sstevel@tonic-gate {
1860Sstevel@tonic-gate 	nelem = getpagesizes(NULL, 0);
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate 	if (!nelem)
1890Sstevel@tonic-gate 		return;
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate 	if (nelem > PGSZELEM)
1920Sstevel@tonic-gate 		nelem = PGSZELEM;
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate 	(void) getpagesizes(pgsz, nelem);
1950Sstevel@tonic-gate #ifdef MPSSDEBUG
1960Sstevel@tonic-gate 	pgsz[nelem] = 0x800000;
1970Sstevel@tonic-gate 	nelem++;
1980Sstevel@tonic-gate #endif
1990Sstevel@tonic-gate }
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate static int
pgszset(size_t sz,uint_t flags)2030Sstevel@tonic-gate pgszset(size_t sz, uint_t flags)
2040Sstevel@tonic-gate {
2050Sstevel@tonic-gate 	struct memcntl_mha	mpss;
2060Sstevel@tonic-gate 	int		rc;
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate 	mpss.mha_cmd = (flags == MPSSHEAP) ?
2090Sstevel@tonic-gate 	    MHA_MAPSIZE_BSSBRK: MHA_MAPSIZE_STACK;
2100Sstevel@tonic-gate 	mpss.mha_pagesize = sz;
2110Sstevel@tonic-gate 	mpss.mha_flags = 0;
2120Sstevel@tonic-gate 	rc = memcntl(NULL, 0, MC_HAT_ADVISE, (caddr_t)&mpss, 0, 0);
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate 	return (rc);
2150Sstevel@tonic-gate }
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate /*
2180Sstevel@tonic-gate  * check if exec name matches cfgname found in mpss cfg file.
2190Sstevel@tonic-gate  */
2200Sstevel@tonic-gate static int
fnmatch(const char * execname,char * cfgname,char * cwd)2210Sstevel@tonic-gate fnmatch(const char *execname, char *cfgname, char *cwd)
2220Sstevel@tonic-gate {
2230Sstevel@tonic-gate 	const char	*ename;
2240Sstevel@tonic-gate 	int		rc;
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 	/* cfgname should not have a '/' unless it begins with one */
2270Sstevel@tonic-gate 	if (cfgname[0] == '/') {
2280Sstevel@tonic-gate 		/*
2290Sstevel@tonic-gate 		 * if execname does not begin with a '/', prepend the
2300Sstevel@tonic-gate 		 * current directory.
2310Sstevel@tonic-gate 		 */
2320Sstevel@tonic-gate 		if (execname[0] != '/') {
2330Sstevel@tonic-gate 			ename = (const char *)strcat(cwd, execname);
2340Sstevel@tonic-gate 		} else
2350Sstevel@tonic-gate 			ename = execname;
2360Sstevel@tonic-gate 	} else {	/* simple cfg name */
2370Sstevel@tonic-gate 		if (ename = strrchr(execname, '/'))
2380Sstevel@tonic-gate 			/* execname is a path name - get the base name */
2390Sstevel@tonic-gate 			ename++;
2400Sstevel@tonic-gate 		else
2410Sstevel@tonic-gate 			ename = execname;
2420Sstevel@tonic-gate 	}
2430Sstevel@tonic-gate 	rc = gmatch(ename, cfgname);
2440Sstevel@tonic-gate 	MPSSPRINT(2, (stderr, "gmatch: %s %s %s %d\n",
2450Sstevel@tonic-gate 	    cfgname, ename, execname, rc));
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate 	return (rc);
2480Sstevel@tonic-gate }
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate /*
2510Sstevel@tonic-gate  * Check if string matches any of exec arguments.
2520Sstevel@tonic-gate  */
2530Sstevel@tonic-gate static int
argmatch(char * str,FILE * errfp)2540Sstevel@tonic-gate argmatch(char *str, FILE *errfp)
2550Sstevel@tonic-gate {
2560Sstevel@tonic-gate 	int fd;
2570Sstevel@tonic-gate 	psinfo_t pi;
2580Sstevel@tonic-gate 	int rc = 0;
2590Sstevel@tonic-gate 	int arg;
2600Sstevel@tonic-gate 	char **argv;
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate 	fd = open("/proc/self/psinfo", O_RDONLY);
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate 	if (fd >= 0) {
2650Sstevel@tonic-gate 		if (read(fd, &pi, sizeof (pi)) == sizeof (pi)) {
2660Sstevel@tonic-gate 			argv = (char **)pi.pr_argv;
2670Sstevel@tonic-gate 			argv++;
2680Sstevel@tonic-gate 			MPSSPRINT(2, (stderr, "argmatch: %s ", str));
2690Sstevel@tonic-gate 			for (arg = 1; arg < pi.pr_argc; arg++, argv++) {
2700Sstevel@tonic-gate 				if (rc = gmatch(*argv, str)) {
2710Sstevel@tonic-gate 					MPSSPRINT(2, (stderr, "%s ", *argv));
2720Sstevel@tonic-gate 					break;
2730Sstevel@tonic-gate 				}
2740Sstevel@tonic-gate 			}
2750Sstevel@tonic-gate 			MPSSPRINT(2, (stderr, "%d\n", rc));
2760Sstevel@tonic-gate 		} else {
2770Sstevel@tonic-gate 			mpsserr(errfp, dgettext(TEXT_DOMAIN,
2780Sstevel@tonic-gate 			    "%s: /proc/self/psinfo read failed [%s]\n"),
2790Sstevel@tonic-gate 			    mpssident, strerror(errno));
2800Sstevel@tonic-gate 		}
2810Sstevel@tonic-gate 		(void) close(fd);
2820Sstevel@tonic-gate 	} else {
2830Sstevel@tonic-gate 		mpsserr(errfp, dgettext(TEXT_DOMAIN,
2840Sstevel@tonic-gate 		    "%s: /proc/self/psinfo open failed [%s]\n"),
2850Sstevel@tonic-gate 		    mpssident, strerror(errno));
2860Sstevel@tonic-gate 	}
2870Sstevel@tonic-gate 	return (rc);
2880Sstevel@tonic-gate }
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate static int
empty(char * str)2910Sstevel@tonic-gate empty(char *str)
2920Sstevel@tonic-gate {
2930Sstevel@tonic-gate 	char	c;
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate 	while ((c = *str) == '\n' || c == ' ' || c == '\t')
2960Sstevel@tonic-gate 		str++;
2970Sstevel@tonic-gate 	return (*str == '\0');
2980Sstevel@tonic-gate }
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate void
__mpssmain()3010Sstevel@tonic-gate __mpssmain()
3020Sstevel@tonic-gate {
3030Sstevel@tonic-gate 	static size_t	heapsz = (size_t)-1, stacksz = (size_t)-1, sz;
3040Sstevel@tonic-gate 	char		*cfgfile, *errfile;
3050Sstevel@tonic-gate 	const char	*execname;
3060Sstevel@tonic-gate 	char		*cwd;
3070Sstevel@tonic-gate 	int		cwdlen;
3080Sstevel@tonic-gate 	FILE		*fp = NULL, *errfp = NULL;
3090Sstevel@tonic-gate 	char		*tok, *tokheap = NULL, *tokstack = NULL, *tokarg;
3100Sstevel@tonic-gate 	char		*str, *envheap, *envstack;
3110Sstevel@tonic-gate 	int		lineno = 0;
3120Sstevel@tonic-gate 	char		*locale;
3130Sstevel@tonic-gate 
3140Sstevel@tonic-gate 	/*
3150Sstevel@tonic-gate 	 * If a private error file is indicated then set the locale
3160Sstevel@tonic-gate 	 * for error messages for the duration of this routine.
3170Sstevel@tonic-gate 	 * Error messages destined for syslog should not be translated
3180Sstevel@tonic-gate 	 * and thus come from the default C locale.
3190Sstevel@tonic-gate 	 */
3200Sstevel@tonic-gate 	if ((errfile = getenv(ENV_MPSSERRFILE)) != NULL) {
321*1914Scasper 		errfp = fopen(errfile, "aF");
3220Sstevel@tonic-gate 		if (errfp) {
3230Sstevel@tonic-gate 			locale = setlocale(LC_MESSAGES, "");
3240Sstevel@tonic-gate 		} else {
3250Sstevel@tonic-gate 			mpsserr(NULL, dgettext(TEXT_DOMAIN,
3260Sstevel@tonic-gate 			    "%s: cannot open error file: %s [%s]\n"),
3270Sstevel@tonic-gate 			    mpssident, errfile, strerror(errno));
3280Sstevel@tonic-gate 		}
3290Sstevel@tonic-gate 	}
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate #ifdef MPSSDEBUG
3320Sstevel@tonic-gate 	if (str = getenv(ENV_MPSSDEBUG))
3330Sstevel@tonic-gate 		mpssdebug = atosz(str);
3340Sstevel@tonic-gate #endif
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate 	pgszinit();
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate 	if (envstack = getenv(ENV_MPSSSTACK)) {
3390Sstevel@tonic-gate 		sz = atosz(envstack);
3400Sstevel@tonic-gate 		if (pgszok(sz))
3410Sstevel@tonic-gate 			stacksz = sz;
3420Sstevel@tonic-gate 		else
3430Sstevel@tonic-gate 			mpsserr(errfp, dgettext(TEXT_DOMAIN,
3440Sstevel@tonic-gate 			    "%s: invalid stack page size specified:"
3450Sstevel@tonic-gate 			    " MPSSSTACK=%s\n"),
3460Sstevel@tonic-gate 			    mpssident, envstack);
3470Sstevel@tonic-gate 	}
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate 	if (envheap = getenv(ENV_MPSSHEAP)) {
3500Sstevel@tonic-gate 		sz = atosz(envheap);
3510Sstevel@tonic-gate 		if (pgszok(sz))
3520Sstevel@tonic-gate 			heapsz = sz;
3530Sstevel@tonic-gate 		else
3540Sstevel@tonic-gate 			mpsserr(errfp, dgettext(TEXT_DOMAIN,
3550Sstevel@tonic-gate 			    "%s: invalid heap page size specified:"
3560Sstevel@tonic-gate 			    " MPSSHEAP=%s\n"),
3570Sstevel@tonic-gate 			    mpssident, envheap);
3580Sstevel@tonic-gate 	}
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 	/*
3610Sstevel@tonic-gate 	 * Open specified cfg file or default one.
3620Sstevel@tonic-gate 	 */
3630Sstevel@tonic-gate 	if (cfgfile = getenv(ENV_MPSSCFGFILE)) {
364*1914Scasper 		fp = fopen(cfgfile, "rF");
3650Sstevel@tonic-gate 		if (!fp) {
3660Sstevel@tonic-gate 			mpsserr(errfp, dgettext(TEXT_DOMAIN,
3670Sstevel@tonic-gate 			    "%s: cannot open configuration file: %s [%s]\n"),
3680Sstevel@tonic-gate 			    mpssident, cfgfile, strerror(errno));
3690Sstevel@tonic-gate 		}
3700Sstevel@tonic-gate 	} else {
3710Sstevel@tonic-gate 		cfgfile = DEF_MPSSCFGFILE;
372*1914Scasper 		fp = fopen(cfgfile, "rF");
3730Sstevel@tonic-gate 	}
3740Sstevel@tonic-gate 
3750Sstevel@tonic-gate 	execname = mygetexecname();
3760Sstevel@tonic-gate 
3770Sstevel@tonic-gate 	if (fp) {
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate 		cwd = getcwd(pbuf, MAXPATHLEN);
3800Sstevel@tonic-gate 		if (!cwd)
3810Sstevel@tonic-gate 			return;
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate 		cwd = strcat(cwd, "/");
3840Sstevel@tonic-gate 		cwdlen = strlen(cwd);
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate 		while (fgets(lbuf, MAXLINELEN, fp)) {
3870Sstevel@tonic-gate 			lineno++;
3880Sstevel@tonic-gate 			if (empty(lbuf))
3890Sstevel@tonic-gate 				continue;
3900Sstevel@tonic-gate 			/*
3910Sstevel@tonic-gate 			 * Make sure line wasn't truncated.
3920Sstevel@tonic-gate 			 */
3930Sstevel@tonic-gate 			if (strlen(lbuf) >= MAXLINELEN - 1) {
3940Sstevel@tonic-gate 				mpsserr(errfp, dgettext(TEXT_DOMAIN,
3950Sstevel@tonic-gate 				    "%s: invalid entry, "
3960Sstevel@tonic-gate 				    "line too long - cfgfile:"
3970Sstevel@tonic-gate 				    " %s, line: %d\n"),
3980Sstevel@tonic-gate 				    mpssident, cfgfile, lineno);
3990Sstevel@tonic-gate 				continue;
4000Sstevel@tonic-gate 			}
4010Sstevel@tonic-gate 			/*
4020Sstevel@tonic-gate 			 * parse right to left in case delimiter is
4030Sstevel@tonic-gate 			 * in name.
4040Sstevel@tonic-gate 			 */
4050Sstevel@tonic-gate 			if (!(tokstack = strrchr(lbuf, CFGDELIMITER))) {
4060Sstevel@tonic-gate 				mpsserr(errfp, dgettext(TEXT_DOMAIN,
4070Sstevel@tonic-gate 				    "%s: no delimiters specified - cfgfile:"
4080Sstevel@tonic-gate 				    " %s, line: %d\n"),
4090Sstevel@tonic-gate 				    mpssident, cfgfile, lineno);
4100Sstevel@tonic-gate 				continue;
4110Sstevel@tonic-gate 			}
4120Sstevel@tonic-gate 			/* found delimiter in lbuf */
4130Sstevel@tonic-gate 			*tokstack++ = '\0';
4140Sstevel@tonic-gate 			/* remove for error message */
4150Sstevel@tonic-gate 			if (str = strrchr(tokstack, '\n'))
4160Sstevel@tonic-gate 				*str = '\0';
4170Sstevel@tonic-gate 			if (!(tokheap = strrchr(lbuf, CFGDELIMITER))) {
4180Sstevel@tonic-gate 				mpsserr(errfp, dgettext(TEXT_DOMAIN,
4190Sstevel@tonic-gate 				    "%s: invalid entry, "
4200Sstevel@tonic-gate 				    "missing delimiter - cfgfile: %s,"
4210Sstevel@tonic-gate 				    " line: %d\n"),
4220Sstevel@tonic-gate 				    mpssident, cfgfile, lineno);
4230Sstevel@tonic-gate 				continue;
4240Sstevel@tonic-gate 			}
4250Sstevel@tonic-gate 			*tokheap++ = '\0';
4260Sstevel@tonic-gate 
4270Sstevel@tonic-gate 			/* exec-args is optional */
4280Sstevel@tonic-gate 			if (tokarg = strrchr(lbuf, ARGDELIMITER)) {
4290Sstevel@tonic-gate 				*tokarg++ = '\0';
4300Sstevel@tonic-gate 			}
4310Sstevel@tonic-gate 
4320Sstevel@tonic-gate 			tok = lbuf;
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate 			if (!fnmatch(execname, tok, cwd)) {
4350Sstevel@tonic-gate 				tokheap = tokstack = tokarg = NULL;
4360Sstevel@tonic-gate 				cwd[cwdlen] = '\0';
4370Sstevel@tonic-gate 				continue;
4380Sstevel@tonic-gate 			}
4390Sstevel@tonic-gate 
4400Sstevel@tonic-gate 			if (tokarg &&
4410Sstevel@tonic-gate 			    !empty(tokarg) &&
4420Sstevel@tonic-gate 			    !argmatch(tokarg, errfp)) {
4430Sstevel@tonic-gate 				tokheap = tokstack = tokarg = NULL;
4440Sstevel@tonic-gate 				cwd[cwdlen] = '\0';
4450Sstevel@tonic-gate 				continue;
4460Sstevel@tonic-gate 			}
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate 			/* heap token */
4490Sstevel@tonic-gate 			if (empty(tokheap)) {
4500Sstevel@tonic-gate 				/* empty cfg entry */
4510Sstevel@tonic-gate 				heapsz = (size_t)-1;
4520Sstevel@tonic-gate 			} else {
4530Sstevel@tonic-gate 				sz = atosz(tokheap);
4540Sstevel@tonic-gate 				if (pgszok(sz))
4550Sstevel@tonic-gate 					heapsz = sz;
4560Sstevel@tonic-gate 				else {
4570Sstevel@tonic-gate 					mpsserr(errfp, dgettext(TEXT_DOMAIN,
4580Sstevel@tonic-gate 					    "%s: invalid heap page size"
4590Sstevel@tonic-gate 					    " specified (%s) for %s - "
4600Sstevel@tonic-gate 					    "cfgfile: %s, line: %d\n"),
4610Sstevel@tonic-gate 					    mpssident, tokheap,
4620Sstevel@tonic-gate 					    execname, cfgfile,
4630Sstevel@tonic-gate 					    lineno);
4640Sstevel@tonic-gate 					heapsz = (size_t)-1;
4650Sstevel@tonic-gate 				}
4660Sstevel@tonic-gate 			}
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate 			/* stack token */
4690Sstevel@tonic-gate 			if (empty(tokstack)) {
4700Sstevel@tonic-gate 				stacksz = (size_t)-1;
4710Sstevel@tonic-gate 				break;
4720Sstevel@tonic-gate 			} else {
4730Sstevel@tonic-gate 				sz = atosz(tokstack);
4740Sstevel@tonic-gate 				if (pgszok(sz))
4750Sstevel@tonic-gate 					stacksz = sz;
4760Sstevel@tonic-gate 				else {
4770Sstevel@tonic-gate 					mpsserr(errfp, dgettext(TEXT_DOMAIN,
4780Sstevel@tonic-gate 					    "%s: invalid stack page size"
4790Sstevel@tonic-gate 					    " specified (%s) for %s - "
4800Sstevel@tonic-gate 					    "cfgfile: %s, line: %d\n"),
4810Sstevel@tonic-gate 					    mpssident, tokstack,
4820Sstevel@tonic-gate 					    execname, cfgfile, lineno);
4830Sstevel@tonic-gate 					stacksz = (size_t)-1;
4840Sstevel@tonic-gate 				}
4850Sstevel@tonic-gate 			}
4860Sstevel@tonic-gate 			break;
4870Sstevel@tonic-gate 		}
4880Sstevel@tonic-gate 		(void) fclose(fp);
4890Sstevel@tonic-gate 	}
4900Sstevel@tonic-gate 
4910Sstevel@tonic-gate 	if ((heapsz != (size_t)-1) && (pgszset(heapsz, MPSSHEAP) < 0))
4920Sstevel@tonic-gate 		mpsserr(errfp, dgettext(TEXT_DOMAIN,
4930Sstevel@tonic-gate 		    "%s: memcntl() failed [%s]: heap page size (%s)"
4940Sstevel@tonic-gate 		    " for %s not set\n"),
4950Sstevel@tonic-gate 		    mpssident, strerror(errno), (tokheap) ? tokheap : envheap,
4960Sstevel@tonic-gate 		    execname);
4970Sstevel@tonic-gate 	if ((stacksz != (size_t)-1) && (pgszset(stacksz, MPSSSTACK) < 0))
4980Sstevel@tonic-gate 		mpsserr(errfp, dgettext(TEXT_DOMAIN,
4990Sstevel@tonic-gate 		    "%s: memcntl() failed [%s]: stack page size (%s)"
5000Sstevel@tonic-gate 		    " for %s not set\n"),
5010Sstevel@tonic-gate 		    mpssident, strerror(errno), (tokstack) ? tokstack: envstack,
5020Sstevel@tonic-gate 		    execname);
5030Sstevel@tonic-gate 
5040Sstevel@tonic-gate 	if (errfp) {
5050Sstevel@tonic-gate 		(void) fclose(errfp);
5060Sstevel@tonic-gate 		(void) setlocale(LC_MESSAGES, locale);
5070Sstevel@tonic-gate 	} else {
5080Sstevel@tonic-gate 		/* close log file: no-op if nothing logged to syslog */
5090Sstevel@tonic-gate 		closelog();
5100Sstevel@tonic-gate 	}
5110Sstevel@tonic-gate }
512