8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / svr4pkg / pkginstall / pkgenv.c
blob37437772c02c4d4e5c4446ce9f6fdf7eff93dbd0
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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 */
31 #include <stdio.h>
32 #include <limits.h>
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <sys/types.h>
36 #include <pkgstrct.h>
37 #include <string.h>
38 #include <locale.h>
39 #include <libintl.h>
40 #include <pkglib.h>
41 #include "install.h"
42 #include "libadm.h"
43 #include "libinst.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>"
51 char *pkgarch;
52 char *pkgvers;
53 char *pkgabrv;
54 char *pkgname;
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.
61 int
62 pkgenv(char *pkginst, char *p_pkginfo, char *p_pkgmap)
64 FILE *fp;
65 char *value,
66 path[PATH_MAX],
67 param[MAX_PKG_PARAM_LENGTH];
68 int errflg;
70 errflg = 0;
71 if (access(p_pkgmap, 0)) {
72 progerr(gettext(ERR_PKGMAP), p_pkgmap);
73 return (1);
75 if ((fp = fopen(p_pkginfo, "r")) == NULL) {
76 progerr(gettext(ERR_PKGINFO), p_pkginfo);
77 return (1);
79 param[0] = '\0';
80 while (value = fpkgparam(fp, param)) {
81 if (strcmp("PATH", param))
82 putparam(param, value);
83 free(value);
84 param[0] = '\0';
86 (void) fclose(fp);
88 * verify that required parameters are now present in
89 * the environment
91 if ((pkgabrv = getenv("PKG")) == NULL) {
92 progerr(gettext(ERR_NOPARAM), "PKG", path);
93 errflg++;
95 if (pkgnmchk(pkgabrv, NULL, 0) || strchr(pkgabrv, '.')) {
96 progerr(gettext(ERR_PKGBAD), pkgabrv);
97 errflg++;
99 (void) snprintf(pkgwild, sizeof (pkgwild), "%s.*", pkgabrv);
100 if ((pkgname = getenv("NAME")) == NULL) {
101 progerr(gettext(ERR_NOPARAM), "NAME", path);
102 errflg++;
104 if ((pkgarch = getenv("ARCH")) == NULL) {
105 progerr(gettext(ERR_NOPARAM), "ARCH", path);
106 errflg++;
108 if ((pkgvers = getenv("VERSION")) == NULL) {
109 progerr(gettext(ERR_NOPARAM), "VERSION", path);
110 errflg++;
112 if (getenv("CATEGORY") == NULL) {
113 progerr(gettext(ERR_NOPARAM), "CATEGORY", path);
114 errflg++;
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);
123 errflg++;
125 return (errflg);