xref: /illumos-gate/usr/src/cmd/saf/readtab.c (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
237c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
26*34e48580Sdp  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
27*34e48580Sdp  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
30*34e48580Sdp #include <stdio.h>
31*34e48580Sdp #include <stdlib.h>
32*34e48580Sdp #include <signal.h>
33*34e48580Sdp #include "misc.h"
34*34e48580Sdp #include "msgs.h"
35*34e48580Sdp #include <sac.h>
36*34e48580Sdp #include "structs.h"
37*34e48580Sdp #include <sys/types.h>
38*34e48580Sdp #include <unistd.h>
39*34e48580Sdp #include "extern.h"
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * read_table - read in SAC's administrative file and build internal
447c478bd9Sstevel@tonic-gate  *		data structures
457c478bd9Sstevel@tonic-gate  *
467c478bd9Sstevel@tonic-gate  *	args:	startflag - flag to indicate if port monitor's should be
477c478bd9Sstevel@tonic-gate  *			    started as a side effect of reading
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate void
read_table(startflag)517c478bd9Sstevel@tonic-gate read_table(startflag)
527c478bd9Sstevel@tonic-gate int startflag;
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate 	FILE *fp;		/* scratch file pointer */
557c478bd9Sstevel@tonic-gate 	int ret;		/* return code from check_version */
567c478bd9Sstevel@tonic-gate 	struct sactab *sp;	/* working pointer to move through PM info */
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate # ifdef DEBUG
597c478bd9Sstevel@tonic-gate 	debug("in read_table");
607c478bd9Sstevel@tonic-gate # endif
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * make sure _sactab is ok
647c478bd9Sstevel@tonic-gate  */
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	Nentries = 0;
677c478bd9Sstevel@tonic-gate 	if ((ret = check_version(VERSION, SACTAB)) == 1)
687c478bd9Sstevel@tonic-gate 		error(E_BADVER, EXIT);
697c478bd9Sstevel@tonic-gate 	else if (ret == 2)
707c478bd9Sstevel@tonic-gate 		error(E_SACOPEN, EXIT);
717c478bd9Sstevel@tonic-gate 	else if (ret == 3)
727c478bd9Sstevel@tonic-gate 		error(E_BADFILE, EXIT);
737c478bd9Sstevel@tonic-gate 	fp = fopen(SACTAB, "r");
747c478bd9Sstevel@tonic-gate 	if (fp == NULL)
757c478bd9Sstevel@tonic-gate 		error(E_SACOPEN, EXIT);
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * mark all entries as invalid
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	for (sp = Sactab; sp; sp = sp->sc_next)
827c478bd9Sstevel@tonic-gate 		sp->sc_valid = 0;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate  * build internal structures
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	while (sp = read_entry(fp))
897c478bd9Sstevel@tonic-gate 		insert(sp, startflag);
907c478bd9Sstevel@tonic-gate 	purge();
917c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /*
967c478bd9Sstevel@tonic-gate  * read_entry - read an entry from _sactab
977c478bd9Sstevel@tonic-gate  *
987c478bd9Sstevel@tonic-gate  *	args:	fp - file pointer referencing _sactab
997c478bd9Sstevel@tonic-gate  */
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate struct sactab *
read_entry(fp)1027c478bd9Sstevel@tonic-gate read_entry(fp)
1037c478bd9Sstevel@tonic-gate FILE *fp;
1047c478bd9Sstevel@tonic-gate {
1057c478bd9Sstevel@tonic-gate 	register struct sactab *sp;	/* working pointer */
1067c478bd9Sstevel@tonic-gate 	register char *p;		/* scratch pointer */
1077c478bd9Sstevel@tonic-gate 	char buf[SIZE];			/* scratch buffer */
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate  * retrieve a line from the file
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	do {
1147c478bd9Sstevel@tonic-gate 		if (fgets(buf, SIZE, fp) == NULL)
1157c478bd9Sstevel@tonic-gate 			return(NULL);
1167c478bd9Sstevel@tonic-gate 		p = trim(buf);
1177c478bd9Sstevel@tonic-gate 	} while (*p == '\0');
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /*
1207c478bd9Sstevel@tonic-gate  * allocate a list element for it and then parse the line, parsed
1217c478bd9Sstevel@tonic-gate  * info goes into list element
1227c478bd9Sstevel@tonic-gate  */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	sp = (struct sactab *) calloc(1, sizeof(struct sactab));
1257c478bd9Sstevel@tonic-gate 	if (sp == NULL)
1267c478bd9Sstevel@tonic-gate 		error(E_MALLOC, EXIT);
1277c478bd9Sstevel@tonic-gate 	sp->sc_sstate = sp->sc_lstate = sp->sc_pstate = NOTRUNNING;
1287c478bd9Sstevel@tonic-gate 	(void) memset(sp->sc_utid, '\0', IDLEN);
1297c478bd9Sstevel@tonic-gate 	parse(p, sp);
1307c478bd9Sstevel@tonic-gate 	return(sp);
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate  * insert - insert a sactab entry into the linked list
1367c478bd9Sstevel@tonic-gate  *
1377c478bd9Sstevel@tonic-gate  *	args:	sp - entry to be inserted
1387c478bd9Sstevel@tonic-gate  *		startflag - flag to indicate if port monitor's should be
1397c478bd9Sstevel@tonic-gate  *			    started as a side effect of reading
1407c478bd9Sstevel@tonic-gate  */
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate void
insert(sp,startflag)1437c478bd9Sstevel@tonic-gate insert(sp, startflag)
1447c478bd9Sstevel@tonic-gate register struct sactab *sp;
1457c478bd9Sstevel@tonic-gate int startflag;
1467c478bd9Sstevel@tonic-gate {
1477c478bd9Sstevel@tonic-gate 	register struct sactab *tsp, *savtsp;	/* scratch pointers */
1487c478bd9Sstevel@tonic-gate 	int ret;				/* strcmp return value */
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate # ifdef DEBUG
1517c478bd9Sstevel@tonic-gate 	debug("in insert");
1527c478bd9Sstevel@tonic-gate # endif
1537c478bd9Sstevel@tonic-gate 	savtsp = tsp = Sactab;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * find the correct place to insert this element
1577c478bd9Sstevel@tonic-gate  */
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	while (tsp) {
1607c478bd9Sstevel@tonic-gate 		ret = strcmp(sp->sc_tag, tsp->sc_tag);
1617c478bd9Sstevel@tonic-gate # ifdef DEBUG
1627c478bd9Sstevel@tonic-gate 		(void) sprintf(Scratch, "sp->sc_tag <%s> tsp->sc_tag <%s>, ret is %d", sp->sc_tag, tsp->sc_tag, ret);
1637c478bd9Sstevel@tonic-gate 		debug(Scratch);
1647c478bd9Sstevel@tonic-gate # endif
1657c478bd9Sstevel@tonic-gate 		if (ret > 0) {
1667c478bd9Sstevel@tonic-gate 			/* keep on looking */
1677c478bd9Sstevel@tonic-gate 			savtsp = tsp;
1687c478bd9Sstevel@tonic-gate 			tsp = tsp->sc_next;
1697c478bd9Sstevel@tonic-gate 			continue;
1707c478bd9Sstevel@tonic-gate 		}
1717c478bd9Sstevel@tonic-gate 		else if (ret == 0) {
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate /*
1747c478bd9Sstevel@tonic-gate  * found an entry for it in the list, either a duplicate or we're
1757c478bd9Sstevel@tonic-gate  * rereading the file.
1767c478bd9Sstevel@tonic-gate  */
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 			if (tsp->sc_valid) {
1797c478bd9Sstevel@tonic-gate 				/* this is a duplicate entry, ignore it */
1807c478bd9Sstevel@tonic-gate 				(void) sprintf(Scratch, "Ignoring duplicate entry for <%s>", tsp->sc_tag);
1817c478bd9Sstevel@tonic-gate 				log(Scratch);
1827c478bd9Sstevel@tonic-gate 			}
1837c478bd9Sstevel@tonic-gate 			else {
1847c478bd9Sstevel@tonic-gate 				/* found a valid match, replace flags & restart max only */
1857c478bd9Sstevel@tonic-gate 				tsp->sc_rsmax = sp->sc_rsmax;
1867c478bd9Sstevel@tonic-gate 				tsp->sc_flags = sp->sc_flags;
1877c478bd9Sstevel@tonic-gate # ifdef DEBUG
1887c478bd9Sstevel@tonic-gate 				(void) sprintf(Scratch, "replacing <%s>", sp->sc_tag);
1897c478bd9Sstevel@tonic-gate 				debug(Scratch);
1907c478bd9Sstevel@tonic-gate # endif
1917c478bd9Sstevel@tonic-gate 				/* this entry is "current" */
1927c478bd9Sstevel@tonic-gate 				tsp->sc_valid = 1;
1937c478bd9Sstevel@tonic-gate 				Nentries++;
1947c478bd9Sstevel@tonic-gate 			}
1957c478bd9Sstevel@tonic-gate 			free(sp->sc_cmd);
1967c478bd9Sstevel@tonic-gate 			free(sp);
1977c478bd9Sstevel@tonic-gate 			return;
1987c478bd9Sstevel@tonic-gate 		}
1997c478bd9Sstevel@tonic-gate 		else {
2007c478bd9Sstevel@tonic-gate 			/* insert it here */
2017c478bd9Sstevel@tonic-gate 			if (tsp == Sactab) {
2027c478bd9Sstevel@tonic-gate 				sp->sc_next = Sactab;
2037c478bd9Sstevel@tonic-gate 				Sactab = sp;
2047c478bd9Sstevel@tonic-gate 			}
2057c478bd9Sstevel@tonic-gate 			else {
2067c478bd9Sstevel@tonic-gate 				sp->sc_next = savtsp->sc_next;
2077c478bd9Sstevel@tonic-gate 				savtsp->sc_next = sp;
2087c478bd9Sstevel@tonic-gate 			}
2097c478bd9Sstevel@tonic-gate # ifdef DEBUG
2107c478bd9Sstevel@tonic-gate 			(void) sprintf(Scratch, "adding <%s>", sp->sc_tag);
2117c478bd9Sstevel@tonic-gate 			debug(Scratch);
2127c478bd9Sstevel@tonic-gate # endif
2137c478bd9Sstevel@tonic-gate 			Nentries++;
2147c478bd9Sstevel@tonic-gate 			/* this entry is "current" */
2157c478bd9Sstevel@tonic-gate 			sp->sc_valid = 1;
2167c478bd9Sstevel@tonic-gate 			if (startflag && !(sp->sc_flags & X_FLAG))
2177c478bd9Sstevel@tonic-gate 				(void) startpm(sp);
2187c478bd9Sstevel@tonic-gate 			return;
2197c478bd9Sstevel@tonic-gate 		}
2207c478bd9Sstevel@tonic-gate 	}
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate /*
2237c478bd9Sstevel@tonic-gate  * either an empty list or should put element at end of list
2247c478bd9Sstevel@tonic-gate  */
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 	sp->sc_next = NULL;
2277c478bd9Sstevel@tonic-gate 	if (Sactab == NULL)
2287c478bd9Sstevel@tonic-gate 		Sactab = sp;
2297c478bd9Sstevel@tonic-gate 	else
2307c478bd9Sstevel@tonic-gate 		savtsp->sc_next = sp;
2317c478bd9Sstevel@tonic-gate # ifdef DEBUG
2327c478bd9Sstevel@tonic-gate 	(void) sprintf(Scratch, "adding <%s>", sp->sc_tag);
2337c478bd9Sstevel@tonic-gate 	debug(Scratch);
2347c478bd9Sstevel@tonic-gate # endif
2357c478bd9Sstevel@tonic-gate 	++Nentries;
2367c478bd9Sstevel@tonic-gate 	/* this entry is "current" */
2377c478bd9Sstevel@tonic-gate 	sp->sc_valid = 1;
2387c478bd9Sstevel@tonic-gate 	if (startflag && !(sp->sc_flags & X_FLAG))
2397c478bd9Sstevel@tonic-gate 		(void) startpm(sp);
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate /*
2457c478bd9Sstevel@tonic-gate  * purge - purge linked list of "old" entries
2467c478bd9Sstevel@tonic-gate  */
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate void
purge()2507c478bd9Sstevel@tonic-gate purge()
2517c478bd9Sstevel@tonic-gate {
2527c478bd9Sstevel@tonic-gate 	register struct sactab *sp;		/* working pointer */
2537c478bd9Sstevel@tonic-gate 	register struct sactab *savesp, *tsp;	/* scratch pointers */
2547c478bd9Sstevel@tonic-gate 	sigset_t cset;				/* for signal handling */
2557c478bd9Sstevel@tonic-gate 	sigset_t tset;				/* for signal handling */
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate # ifdef DEBUG
2587c478bd9Sstevel@tonic-gate 	debug("in purge");
2597c478bd9Sstevel@tonic-gate # endif
2607c478bd9Sstevel@tonic-gate 	/* get current signal mask */
2617c478bd9Sstevel@tonic-gate 	(void) sigprocmask(SIG_SETMASK, NULL, &cset);
2627c478bd9Sstevel@tonic-gate 	sp = savesp = Sactab;
2637c478bd9Sstevel@tonic-gate 	while (sp) {
2647c478bd9Sstevel@tonic-gate 		if (sp->sc_valid) {
2657c478bd9Sstevel@tonic-gate 			savesp = sp;
2667c478bd9Sstevel@tonic-gate 			sp = sp->sc_next;
2677c478bd9Sstevel@tonic-gate 			continue;
2687c478bd9Sstevel@tonic-gate 		}
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 		/* element should be removed */
2717c478bd9Sstevel@tonic-gate 		switch (sp->sc_sstate) {
2727c478bd9Sstevel@tonic-gate 		case UNKNOWN:
2737c478bd9Sstevel@tonic-gate 		case ENABLED:
2747c478bd9Sstevel@tonic-gate 		case DISABLED:
2757c478bd9Sstevel@tonic-gate 		case STARTING:
2767c478bd9Sstevel@tonic-gate 			/* need to kill it */
2777c478bd9Sstevel@tonic-gate 			tset = cset;
2787c478bd9Sstevel@tonic-gate 			(void) sigaddset(&tset, SIGALRM);
2797c478bd9Sstevel@tonic-gate 			(void) sigaddset(&tset, SIGCLD);
2807c478bd9Sstevel@tonic-gate 			(void) sigprocmask(SIG_SETMASK, &tset, NULL);
2817c478bd9Sstevel@tonic-gate 			if (sendsig(sp, SIGTERM))
2827c478bd9Sstevel@tonic-gate 				(void) sprintf(Scratch, "could not send SIGTERM to <%s>", sp->sc_tag);
2837c478bd9Sstevel@tonic-gate 			else
2847c478bd9Sstevel@tonic-gate 				(void) sprintf(Scratch, "terminating <%s>", sp->sc_tag);
2857c478bd9Sstevel@tonic-gate 			log(Scratch);
2867c478bd9Sstevel@tonic-gate 			(void) sigdelset(&tset, SIGALRM);
2877c478bd9Sstevel@tonic-gate 			(void) sigprocmask(SIG_SETMASK, &tset, NULL);
2887c478bd9Sstevel@tonic-gate 			/* fall thru */
2897c478bd9Sstevel@tonic-gate 		case STOPPING:
2907c478bd9Sstevel@tonic-gate 			(void) close(sp->sc_fd);
2917c478bd9Sstevel@tonic-gate 			/* fall thru */
2927c478bd9Sstevel@tonic-gate 		case NOTRUNNING:
2937c478bd9Sstevel@tonic-gate 		case FAILED:
2947c478bd9Sstevel@tonic-gate 			cleanutx(sp);
2957c478bd9Sstevel@tonic-gate 			tsp = sp;
2967c478bd9Sstevel@tonic-gate 			if (tsp == Sactab) {
2977c478bd9Sstevel@tonic-gate 				Sactab = sp->sc_next;
2987c478bd9Sstevel@tonic-gate 				savesp = Sactab;
2997c478bd9Sstevel@tonic-gate 			}
3007c478bd9Sstevel@tonic-gate 			else
3017c478bd9Sstevel@tonic-gate 				savesp->sc_next = sp->sc_next;
3027c478bd9Sstevel@tonic-gate # ifdef DEBUG
3037c478bd9Sstevel@tonic-gate 			(void) sprintf(Scratch, "purging <%s>", sp->sc_tag);
3047c478bd9Sstevel@tonic-gate 			debug(Scratch);
3057c478bd9Sstevel@tonic-gate # endif
3067c478bd9Sstevel@tonic-gate 			sp = sp->sc_next;
3077c478bd9Sstevel@tonic-gate 			free(tsp->sc_cmd);
3087c478bd9Sstevel@tonic-gate 			free(tsp->sc_comment);
3097c478bd9Sstevel@tonic-gate 			free(tsp);
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate /*
3127c478bd9Sstevel@tonic-gate  * all done cleaning up, restore signal mask
3137c478bd9Sstevel@tonic-gate  */
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate 			(void) sigprocmask(SIG_SETMASK, &cset, NULL);
3167c478bd9Sstevel@tonic-gate 			break;
3177c478bd9Sstevel@tonic-gate 		}
3187c478bd9Sstevel@tonic-gate 	}
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate /*
3237c478bd9Sstevel@tonic-gate  * dump_table - dump the internal SAC table, used to satisfy sacadm -l
3247c478bd9Sstevel@tonic-gate  */
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate char **
dump_table()3287c478bd9Sstevel@tonic-gate dump_table()
3297c478bd9Sstevel@tonic-gate {
3307c478bd9Sstevel@tonic-gate 	register struct sactab *sp;	/* working pointer */
3317c478bd9Sstevel@tonic-gate 	register char *p;		/* scratch pointer */
3327c478bd9Sstevel@tonic-gate 	register int size;		/* size of "dumped" table */
3337c478bd9Sstevel@tonic-gate 	char **info, **savinfo;		/* scratch pointers */
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate # ifdef DEBUG
3367c478bd9Sstevel@tonic-gate 	(void) sprintf(Scratch, "about to 'info' malloc %d entries", Nentries);
3377c478bd9Sstevel@tonic-gate 	debug(Scratch);
3387c478bd9Sstevel@tonic-gate # endif
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate /*
3417c478bd9Sstevel@tonic-gate  * get space for number of entries we have
3427c478bd9Sstevel@tonic-gate  */
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 	if (Nentries == 0)
3457c478bd9Sstevel@tonic-gate 		return(NULL);
3467c478bd9Sstevel@tonic-gate 	if ((info = (char **) malloc(Nentries * sizeof(char *))) == NULL) {
3477c478bd9Sstevel@tonic-gate 		error(E_MALLOC, CONT);
3487c478bd9Sstevel@tonic-gate 		return(NULL);
3497c478bd9Sstevel@tonic-gate 	}
3507c478bd9Sstevel@tonic-gate 	savinfo = info;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate /*
3537c478bd9Sstevel@tonic-gate  * traverse the list allocating space for entries and formatting them
3547c478bd9Sstevel@tonic-gate  */
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate 	for (sp = Sactab; sp; sp = sp->sc_next) {
3577c478bd9Sstevel@tonic-gate 		size = strlen(sp->sc_tag) + strlen(sp->sc_type) + strlen(sp->sc_cmd) + strlen(sp->sc_comment) + SLOP;
3587c478bd9Sstevel@tonic-gate 		if ((p = malloc((unsigned) size)) == NULL) {
3597c478bd9Sstevel@tonic-gate 			error(E_MALLOC, CONT);
3607c478bd9Sstevel@tonic-gate 			return(NULL);
3617c478bd9Sstevel@tonic-gate 		}
3627c478bd9Sstevel@tonic-gate 		(void) sprintf(p, "%s:%s:%d:%d:%d:%s:%s\n", sp->sc_tag, sp->sc_type,
3637c478bd9Sstevel@tonic-gate 			sp->sc_flags, sp->sc_rsmax, sp->sc_pstate, sp->sc_cmd, sp->sc_comment);
3647c478bd9Sstevel@tonic-gate 		*info++ = p;
3657c478bd9Sstevel@tonic-gate # ifdef DEBUG
3667c478bd9Sstevel@tonic-gate 		debug(*(info - 1));
3677c478bd9Sstevel@tonic-gate # endif
3687c478bd9Sstevel@tonic-gate 	}
3697c478bd9Sstevel@tonic-gate 	return(savinfo);
3707c478bd9Sstevel@tonic-gate }
371