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 (c) 2017 Peter Tribble.
27 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
32 /* All Rights Reserved */
41 #include <sys/types.h>
51 extern struct admin adm
;
53 extern char pkgloc
[], *pkginst
, *msgtext
;
55 static boolean_t preremoveCheck
= B_FALSE
;
56 static char *zoneName
= (char *)NULL
;
60 rcksetPreremoveCheck(boolean_t a_preremoveCheck
)
62 preremoveCheck
= a_preremoveCheck
;
66 rcksetZoneName(char *a_zoneName
)
68 zoneName
= a_zoneName
;
82 if (ADM(runlevel
, "nocheck")) {
86 pt
= getenv("RSTATES");
91 utmpx
.ut_type
= RUN_LVL
;
92 putmpx
= getutxid(&utmpx
);
94 progerr(ERR_RUNSTATE
);
97 uxstate
= strtok(&putmpx
->ut_line
[10], " \t\n");
99 rstates
= qstrdup(pt
);
100 if ((pt
= strtok(pt
, " \t\n, ")) == NULL
)
101 return (0); /* no list is no list */
103 if (strcmp(pt
, uxstate
) == NULL
) {
107 } while (pt
= strtok(NULL
, " \t\n, "));
109 if (preremoveCheck
== B_FALSE
) {
110 msgtext
= MSG_PKGREMOVE_RUNLEVEL
;
111 ptext(stderr
, msgtext
, uxstate
);
113 (void) fprintf(stdout
, "runlevel=%s", uxstate
);
116 pt
= strtok(rstates
, " \t\n, ");
118 if (preremoveCheck
== B_FALSE
) {
119 ptext(stderr
, "\\t%s", pt
);
121 (void) fprintf(stdout
, ":%s", pt
);
123 } while (pt
= strtok(NULL
, " \t\n, "));
125 if (preremoveCheck
== B_TRUE
) {
126 (void) fprintf(stdout
, "\n");
131 if (ADM(runlevel
, "quit")) {
135 if (echoGetFlag() == B_FALSE
) {
141 n
= ckyorn(ans
, NULL
, NULL
, HLP_PKGREMOVE_RUNLEVEL
,
142 ASK_PKGREMOVE_CONTINUE
);
148 if (strchr("yY", *ans
) == NULL
) {
161 if (ADM(rdepend
, "nocheck")) {
165 if (zoneName
== (char *)NULL
) {
166 echo(MSG_CHECKREMOVE_PKG_IN_GZ
, pkginst
);
168 echo(MSG_CHECKREMOVE_PKG_IN_ZONE
, pkginst
, zoneName
);
171 if (dockdeps(pkginst
, 1, preremoveCheck
)) {
172 msgtext
= MSG_PKGREMOVE_DEPEND
;
174 if (preremoveCheck
== B_FALSE
) {
178 if (ADM(rdepend
, "quit")) {
182 if (echoGetFlag() == B_FALSE
) {
188 n
= ckyorn(ans
, NULL
, NULL
, HLP_PKGREMOVE_DEPEND
,
189 ASK_PKGREMOVE_CONTINUE
);
195 if (strchr("yY", *ans
) == NULL
) {
213 if (ADM(action
, "nocheck")) {
217 (void) snprintf(path
, sizeof (path
), "%s/install", pkgloc
);
218 if ((dirfp
= opendir(path
)) == NULL
)
222 while ((dp
= readdir(dirfp
)) != NULL
) {
223 if ((strcmp(dp
->d_name
, "preremove") == NULL
) ||
224 (strcmp(dp
->d_name
, "postremove") == NULL
) ||
225 (strncmp(dp
->d_name
, "r.", 2) == NULL
)) {
230 (void) closedir(dirfp
);
233 if (preremoveCheck
== B_FALSE
) {
234 ptext(stderr
, MSG_PKGREMOVE_PRIV
);
236 msgtext
= MSG_PKGSCRIPTS_FOUND
;
238 if (ADM(action
, "quit")) {
242 if (echoGetFlag() == B_FALSE
) {
248 n
= ckyorn(ans
, NULL
, NULL
, HLP_PKGREMOVE_PRIV
,
249 ASK_PKGREMOVE_CONTINUE
);
255 if (strchr("yY", *ans
) == NULL
) {