xref: /onnv-gate/usr/src/cmd/svr4pkg/libinst/eptstat.c (revision 9781:ccf49524d5dc)
1*9781SMoriah.Waterland@Sun.COM /*
2*9781SMoriah.Waterland@Sun.COM  * CDDL HEADER START
3*9781SMoriah.Waterland@Sun.COM  *
4*9781SMoriah.Waterland@Sun.COM  * The contents of this file are subject to the terms of the
5*9781SMoriah.Waterland@Sun.COM  * Common Development and Distribution License (the "License").
6*9781SMoriah.Waterland@Sun.COM  * You may not use this file except in compliance with the License.
7*9781SMoriah.Waterland@Sun.COM  *
8*9781SMoriah.Waterland@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9781SMoriah.Waterland@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*9781SMoriah.Waterland@Sun.COM  * See the License for the specific language governing permissions
11*9781SMoriah.Waterland@Sun.COM  * and limitations under the License.
12*9781SMoriah.Waterland@Sun.COM  *
13*9781SMoriah.Waterland@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*9781SMoriah.Waterland@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9781SMoriah.Waterland@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*9781SMoriah.Waterland@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*9781SMoriah.Waterland@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*9781SMoriah.Waterland@Sun.COM  *
19*9781SMoriah.Waterland@Sun.COM  * CDDL HEADER END
20*9781SMoriah.Waterland@Sun.COM  */
21*9781SMoriah.Waterland@Sun.COM 
22*9781SMoriah.Waterland@Sun.COM /*
23*9781SMoriah.Waterland@Sun.COM  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*9781SMoriah.Waterland@Sun.COM  * Use is subject to license terms.
25*9781SMoriah.Waterland@Sun.COM  */
26*9781SMoriah.Waterland@Sun.COM 
27*9781SMoriah.Waterland@Sun.COM /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*9781SMoriah.Waterland@Sun.COM /* All Rights Reserved */
29*9781SMoriah.Waterland@Sun.COM 
30*9781SMoriah.Waterland@Sun.COM 
31*9781SMoriah.Waterland@Sun.COM #include <stdio.h>
32*9781SMoriah.Waterland@Sun.COM #include <errno.h>
33*9781SMoriah.Waterland@Sun.COM #include <stdlib.h>
34*9781SMoriah.Waterland@Sun.COM #include <unistd.h>
35*9781SMoriah.Waterland@Sun.COM #include <string.h>
36*9781SMoriah.Waterland@Sun.COM #include <malloc.h>
37*9781SMoriah.Waterland@Sun.COM #include <assert.h>
38*9781SMoriah.Waterland@Sun.COM #include <sys/stat.h>
39*9781SMoriah.Waterland@Sun.COM #include <pkgstrct.h>
40*9781SMoriah.Waterland@Sun.COM #include <pkginfo.h>
41*9781SMoriah.Waterland@Sun.COM #include <locale.h>
42*9781SMoriah.Waterland@Sun.COM #include <libintl.h>
43*9781SMoriah.Waterland@Sun.COM #include <pkglib.h>
44*9781SMoriah.Waterland@Sun.COM #include <install.h>
45*9781SMoriah.Waterland@Sun.COM #include <libinst.h>
46*9781SMoriah.Waterland@Sun.COM #include <libadm.h>
47*9781SMoriah.Waterland@Sun.COM 
48*9781SMoriah.Waterland@Sun.COM #define	PINFOALLOC	200
49*9781SMoriah.Waterland@Sun.COM 
50*9781SMoriah.Waterland@Sun.COM #define	ERR_MEMORY	"memory allocation failure, errno=%d"
51*9781SMoriah.Waterland@Sun.COM 
52*9781SMoriah.Waterland@Sun.COM int	otherstoo;
53*9781SMoriah.Waterland@Sun.COM char	*useclass;
54*9781SMoriah.Waterland@Sun.COM 
55*9781SMoriah.Waterland@Sun.COM static int pinfo_handle = -1;
56*9781SMoriah.Waterland@Sun.COM 
57*9781SMoriah.Waterland@Sun.COM /* Free all allocated package info structures. */
58*9781SMoriah.Waterland@Sun.COM void
pinfo_free(void)59*9781SMoriah.Waterland@Sun.COM pinfo_free(void)
60*9781SMoriah.Waterland@Sun.COM {
61*9781SMoriah.Waterland@Sun.COM 	bl_free(pinfo_handle);
62*9781SMoriah.Waterland@Sun.COM }
63*9781SMoriah.Waterland@Sun.COM 
64*9781SMoriah.Waterland@Sun.COM /*
65*9781SMoriah.Waterland@Sun.COM  * This function manipulates the pinfo entry corresponding to the package
66*9781SMoriah.Waterland@Sun.COM  * indicated on the command line.
67*9781SMoriah.Waterland@Sun.COM  */
68*9781SMoriah.Waterland@Sun.COM struct pinfo *
eptstat(struct cfent * entry,char * pkg,char c)69*9781SMoriah.Waterland@Sun.COM eptstat(struct cfent *entry, char *pkg, char c)
70*9781SMoriah.Waterland@Sun.COM {
71*9781SMoriah.Waterland@Sun.COM 	struct pinfo *pinfo, *last, *me, *myparent;
72*9781SMoriah.Waterland@Sun.COM 
73*9781SMoriah.Waterland@Sun.COM 	otherstoo = 0;
74*9781SMoriah.Waterland@Sun.COM 	useclass = entry->pkg_class;
75*9781SMoriah.Waterland@Sun.COM 
76*9781SMoriah.Waterland@Sun.COM 	me = myparent = last = (struct pinfo *)0;
77*9781SMoriah.Waterland@Sun.COM 
78*9781SMoriah.Waterland@Sun.COM 	if (pinfo_handle == -1) {
79*9781SMoriah.Waterland@Sun.COM 		pinfo_handle = bl_create(PINFOALLOC, sizeof (struct pinfo),
80*9781SMoriah.Waterland@Sun.COM 		    "package data");
81*9781SMoriah.Waterland@Sun.COM 	}
82*9781SMoriah.Waterland@Sun.COM 
83*9781SMoriah.Waterland@Sun.COM 	for (pinfo = entry->pinfo; pinfo; pinfo = pinfo->next) {
84*9781SMoriah.Waterland@Sun.COM 		if (strcmp(pkg, pinfo->pkg) == 0) {
85*9781SMoriah.Waterland@Sun.COM 			if (*pinfo->aclass)
86*9781SMoriah.Waterland@Sun.COM 				useclass = pinfo->aclass;
87*9781SMoriah.Waterland@Sun.COM 			myparent = last;
88*9781SMoriah.Waterland@Sun.COM 			me = pinfo;
89*9781SMoriah.Waterland@Sun.COM 		} else
90*9781SMoriah.Waterland@Sun.COM 			otherstoo++;
91*9781SMoriah.Waterland@Sun.COM 		last = pinfo;
92*9781SMoriah.Waterland@Sun.COM 	}
93*9781SMoriah.Waterland@Sun.COM 
94*9781SMoriah.Waterland@Sun.COM 	if (c) {
95*9781SMoriah.Waterland@Sun.COM 		/*
96*9781SMoriah.Waterland@Sun.COM 		 * use a delete/add strategy to keep package list
97*9781SMoriah.Waterland@Sun.COM 		 * ordered by modification time
98*9781SMoriah.Waterland@Sun.COM 		 */
99*9781SMoriah.Waterland@Sun.COM 		if (me) {
100*9781SMoriah.Waterland@Sun.COM 			/* remove from list first */
101*9781SMoriah.Waterland@Sun.COM 			if (myparent)
102*9781SMoriah.Waterland@Sun.COM 				myparent->next = me->next;
103*9781SMoriah.Waterland@Sun.COM 			else
104*9781SMoriah.Waterland@Sun.COM 				entry->pinfo = me->next;
105*9781SMoriah.Waterland@Sun.COM 			if (me == last)
106*9781SMoriah.Waterland@Sun.COM 				last = myparent;
107*9781SMoriah.Waterland@Sun.COM 			entry->npkgs--;
108*9781SMoriah.Waterland@Sun.COM 			/* leave 'me' around until later! */
109*9781SMoriah.Waterland@Sun.COM 		}
110*9781SMoriah.Waterland@Sun.COM 		if ((c != STAT_NEXT) && (me || (c != RM_RDY))) {
111*9781SMoriah.Waterland@Sun.COM 			/* need to add onto end */
112*9781SMoriah.Waterland@Sun.COM 			entry->npkgs++;
113*9781SMoriah.Waterland@Sun.COM 			if (me == NULL) {
114*9781SMoriah.Waterland@Sun.COM 				/* LINTED pointer cast may result in impro... */
115*9781SMoriah.Waterland@Sun.COM 				me = (struct pinfo *)
116*9781SMoriah.Waterland@Sun.COM 				    bl_next_avail(pinfo_handle);
117*9781SMoriah.Waterland@Sun.COM 				if (me == NULL) {
118*9781SMoriah.Waterland@Sun.COM 					progerr(gettext(ERR_MEMORY), errno);
119*9781SMoriah.Waterland@Sun.COM 					quit(99);
120*9781SMoriah.Waterland@Sun.COM 				}
121*9781SMoriah.Waterland@Sun.COM 			} else {
122*9781SMoriah.Waterland@Sun.COM 				me->next = (struct pinfo *)NULL;
123*9781SMoriah.Waterland@Sun.COM 				if (entry->npkgs == 1) {
124*9781SMoriah.Waterland@Sun.COM 					if (me->aclass[0])
125*9781SMoriah.Waterland@Sun.COM 						(void) strcpy(entry->pkg_class,
126*9781SMoriah.Waterland@Sun.COM 							me->aclass);
127*9781SMoriah.Waterland@Sun.COM 					useclass = entry->pkg_class;
128*9781SMoriah.Waterland@Sun.COM 				} else
129*9781SMoriah.Waterland@Sun.COM 					useclass = me->aclass;
130*9781SMoriah.Waterland@Sun.COM 			}
131*9781SMoriah.Waterland@Sun.COM 			(void) strncpy(me->pkg, pkg, PKGSIZ);
132*9781SMoriah.Waterland@Sun.COM 
133*9781SMoriah.Waterland@Sun.COM 			/*
134*9781SMoriah.Waterland@Sun.COM 			 * Only change status for local objects.  Need
135*9781SMoriah.Waterland@Sun.COM 			 * to maintain "shared" status for objects that
136*9781SMoriah.Waterland@Sun.COM 			 * are provided from a server.
137*9781SMoriah.Waterland@Sun.COM 			 */
138*9781SMoriah.Waterland@Sun.COM 			if (me->status != SERVED_FILE)
139*9781SMoriah.Waterland@Sun.COM 				me->status = ((c == DUP_ENTRY) ? '\0' : c);
140*9781SMoriah.Waterland@Sun.COM 
141*9781SMoriah.Waterland@Sun.COM 			if (last)
142*9781SMoriah.Waterland@Sun.COM 				last->next = me; /* add to end */
143*9781SMoriah.Waterland@Sun.COM 			else
144*9781SMoriah.Waterland@Sun.COM 				entry->pinfo = me; /* only item */
145*9781SMoriah.Waterland@Sun.COM 		} else {
146*9781SMoriah.Waterland@Sun.COM 			/* just wanted to remove this package from list */
147*9781SMoriah.Waterland@Sun.COM 			if (me) {
148*9781SMoriah.Waterland@Sun.COM 				free(me);
149*9781SMoriah.Waterland@Sun.COM 				me = (struct pinfo *)0;
150*9781SMoriah.Waterland@Sun.COM 			}
151*9781SMoriah.Waterland@Sun.COM 		}
152*9781SMoriah.Waterland@Sun.COM 	}
153*9781SMoriah.Waterland@Sun.COM 	return (me);
154*9781SMoriah.Waterland@Sun.COM }
155