4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
35 #include <sys/types.h>
45 #define ERR_PKGINFO "unable to access pkginfo file <%s>"
46 #define ERR_PKGMAP "unable to access pkgmap file <%s>"
47 #define ERR_NOPARAM "%s parameter is not defined in <%s>"
48 #define ERR_PKGBAD "PKG parameter is invalid <%s>"
49 #define ERR_PKGMTCH "PKG parameter <%s> does not match instance <%s>"
55 char pkgwild
[PKGSIZ
+1];
58 * This function confirms the presence of pkgmap and pkginfo and verifies
59 * that the mandatory parameters are available in the environment.
62 pkgenv(char *pkginst
, char *p_pkginfo
, char *p_pkgmap
)
67 param
[MAX_PKG_PARAM_LENGTH
];
71 if (access(p_pkgmap
, 0)) {
72 progerr(gettext(ERR_PKGMAP
), p_pkgmap
);
75 if ((fp
= fopen(p_pkginfo
, "r")) == NULL
) {
76 progerr(gettext(ERR_PKGINFO
), p_pkginfo
);
80 while (value
= fpkgparam(fp
, param
)) {
81 if (strcmp("PATH", param
))
82 putparam(param
, value
);
88 * verify that required parameters are now present in
91 if ((pkgabrv
= getenv("PKG")) == NULL
) {
92 progerr(gettext(ERR_NOPARAM
), "PKG", path
);
95 if (pkgnmchk(pkgabrv
, NULL
, 0) || strchr(pkgabrv
, '.')) {
96 progerr(gettext(ERR_PKGBAD
), pkgabrv
);
99 (void) snprintf(pkgwild
, sizeof (pkgwild
), "%s.*", pkgabrv
);
100 if ((pkgname
= getenv("NAME")) == NULL
) {
101 progerr(gettext(ERR_NOPARAM
), "NAME", path
);
104 if ((pkgarch
= getenv("ARCH")) == NULL
) {
105 progerr(gettext(ERR_NOPARAM
), "ARCH", path
);
108 if ((pkgvers
= getenv("VERSION")) == NULL
) {
109 progerr(gettext(ERR_NOPARAM
), "VERSION", path
);
112 if (getenv("CATEGORY") == NULL
) {
113 progerr(gettext(ERR_NOPARAM
), "CATEGORY", path
);
117 * verify consistency between PKG parameter and pkginst that
118 * was determined from the directory structure
120 (void) snprintf(param
, sizeof (param
), "%s.*", pkgabrv
);
121 if (pkgnmchk(pkginst
, param
, 0)) {
122 progerr(gettext(ERR_PKGMTCH
), pkgabrv
, pkginst
);