1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23*0Sstevel@tonic-gate /* All Rights Reserved */
24*0Sstevel@tonic-gate
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate /*
27*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28*0Sstevel@tonic-gate * Use is subject to license terms.
29*0Sstevel@tonic-gate */
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate # include <stdarg.h>
34*0Sstevel@tonic-gate # include "lpsched.h"
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gate typedef struct fault FLT;
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate struct fault
39*0Sstevel@tonic-gate {
40*0Sstevel@tonic-gate FLT * next;
41*0Sstevel@tonic-gate int type;
42*0Sstevel@tonic-gate int i1;
43*0Sstevel@tonic-gate char * s1;
44*0Sstevel@tonic-gate RSTATUS * r1;
45*0Sstevel@tonic-gate MESG * ident;
46*0Sstevel@tonic-gate };
47*0Sstevel@tonic-gate
48*0Sstevel@tonic-gate static void free_flt ( FLT * );
49*0Sstevel@tonic-gate static void do_flt_acts ( MESG * );
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate static FLT Fault_Head = { NULL, 0, 0, NULL, NULL, NULL };
52*0Sstevel@tonic-gate static FLT * Fault_List = &Fault_Head;
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate void
add_flt_act(MESG * md,...)55*0Sstevel@tonic-gate add_flt_act(MESG * md, ...)
56*0Sstevel@tonic-gate {
57*0Sstevel@tonic-gate va_list arg;
58*0Sstevel@tonic-gate FLT *f;
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate va_start (arg, md);
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate f = (FLT *)Malloc(sizeof(FLT));
63*0Sstevel@tonic-gate
64*0Sstevel@tonic-gate (void) memset((char *)f, 0, sizeof(FLT));
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gate f->type = (int)va_arg(arg, int);
67*0Sstevel@tonic-gate f->ident = md;
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate if (md->on_discon == NULL)
70*0Sstevel@tonic-gate if (mon_discon(md, do_flt_acts))
71*0Sstevel@tonic-gate mallocfail();
72*0Sstevel@tonic-gate
73*0Sstevel@tonic-gate switch(f->type)
74*0Sstevel@tonic-gate {
75*0Sstevel@tonic-gate case FLT_FILES:
76*0Sstevel@tonic-gate f->s1 = Strdup((char *)va_arg(arg, char *));
77*0Sstevel@tonic-gate f->i1 = (int)va_arg(arg, int);
78*0Sstevel@tonic-gate break;
79*0Sstevel@tonic-gate
80*0Sstevel@tonic-gate case FLT_CHANGE:
81*0Sstevel@tonic-gate f->r1 = (RSTATUS *)va_arg(arg, RSTATUS *);
82*0Sstevel@tonic-gate break;
83*0Sstevel@tonic-gate }
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate va_end(arg);
86*0Sstevel@tonic-gate
87*0Sstevel@tonic-gate f->next = Fault_List->next;
88*0Sstevel@tonic-gate Fault_List->next = f;
89*0Sstevel@tonic-gate }
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gate void
del_flt_act(MESG * md,...)93*0Sstevel@tonic-gate del_flt_act(MESG *md, ...)
94*0Sstevel@tonic-gate {
95*0Sstevel@tonic-gate va_list arg;
96*0Sstevel@tonic-gate int type;
97*0Sstevel@tonic-gate FLT *fp;
98*0Sstevel@tonic-gate FLT *f;
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate va_start(arg, md);
101*0Sstevel@tonic-gate
102*0Sstevel@tonic-gate type = (int)va_arg(arg, int);
103*0Sstevel@tonic-gate
104*0Sstevel@tonic-gate for (f = Fault_List; f->next; f = f->next)
105*0Sstevel@tonic-gate if (f->next->type == type && f->next->ident == md)
106*0Sstevel@tonic-gate {
107*0Sstevel@tonic-gate fp = f->next;
108*0Sstevel@tonic-gate f->next = f->next->next;
109*0Sstevel@tonic-gate free_flt(fp);
110*0Sstevel@tonic-gate break;
111*0Sstevel@tonic-gate }
112*0Sstevel@tonic-gate
113*0Sstevel@tonic-gate va_end(arg);
114*0Sstevel@tonic-gate }
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gate static void
do_flt_acts(MESG * md)117*0Sstevel@tonic-gate do_flt_acts(MESG *md)
118*0Sstevel@tonic-gate {
119*0Sstevel@tonic-gate FLT *f;
120*0Sstevel@tonic-gate FLT *fp;
121*0Sstevel@tonic-gate char *file;
122*0Sstevel@tonic-gate char id[15];
123*0Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
124*0Sstevel@tonic-gate struct stat tmpBuf;
125*0Sstevel@tonic-gate char attrFile[BUFSIZ];
126*0Sstevel@tonic-gate #endif
127*0Sstevel@tonic-gate
128*0Sstevel@tonic-gate for (f = Fault_List; f && f->next; f = f->next)
129*0Sstevel@tonic-gate if (f->next->ident == md)
130*0Sstevel@tonic-gate {
131*0Sstevel@tonic-gate fp = f->next;
132*0Sstevel@tonic-gate f->next = f->next->next;
133*0Sstevel@tonic-gate
134*0Sstevel@tonic-gate switch (fp->type)
135*0Sstevel@tonic-gate {
136*0Sstevel@tonic-gate case FLT_FILES:
137*0Sstevel@tonic-gate /* remove files created with alloc_files */
138*0Sstevel@tonic-gate
139*0Sstevel@tonic-gate while(fp->i1--)
140*0Sstevel@tonic-gate {
141*0Sstevel@tonic-gate (void) snprintf(id, sizeof (id), "%s-%d", fp->s1, fp->i1);
142*0Sstevel@tonic-gate file = makepath(Lp_Temp, id, (char *)0);
143*0Sstevel@tonic-gate (void) Unlink(file);
144*0Sstevel@tonic-gate Free(file);
145*0Sstevel@tonic-gate }
146*0Sstevel@tonic-gate
147*0Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
148*0Sstevel@tonic-gate /*
149*0Sstevel@tonic-gate * check if the PAPI attribute file exists, if it does delete it
150*0Sstevel@tonic-gate */
151*0Sstevel@tonic-gate (void) snprintf(attrFile, sizeof (attrFile),
152*0Sstevel@tonic-gate "%s-%s", fp->s1, LP_PAPIATTRNAME);
153*0Sstevel@tonic-gate file = makepath(Lp_Temp, attrFile, (char *)0);
154*0Sstevel@tonic-gate if ((file != NULL) && (stat(file, &tmpBuf) == 0))
155*0Sstevel@tonic-gate {
156*0Sstevel@tonic-gate (void) Unlink(file);
157*0Sstevel@tonic-gate }
158*0Sstevel@tonic-gate Free(file);
159*0Sstevel@tonic-gate #endif
160*0Sstevel@tonic-gate break;
161*0Sstevel@tonic-gate
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate case FLT_CHANGE:
164*0Sstevel@tonic-gate /* clear RS_CHANGE bit, write request file, and schedule */
165*0Sstevel@tonic-gate fp->r1->request->outcome &= ~RS_CHANGING;
166*0Sstevel@tonic-gate putrequest(fp->r1->req_file, fp->r1->request);
167*0Sstevel@tonic-gate if (NEEDS_FILTERING(fp->r1))
168*0Sstevel@tonic-gate schedule(/* LP_FILTER */ EV_SLOWF, fp->r1);
169*0Sstevel@tonic-gate else
170*0Sstevel@tonic-gate schedule(/* LP_PRINTER */ EV_INTERF, fp->r1->printer);
171*0Sstevel@tonic-gate break;
172*0Sstevel@tonic-gate }
173*0Sstevel@tonic-gate free_flt(fp);
174*0Sstevel@tonic-gate }
175*0Sstevel@tonic-gate }
176*0Sstevel@tonic-gate
177*0Sstevel@tonic-gate static void
free_flt(FLT * f)178*0Sstevel@tonic-gate free_flt(FLT *f)
179*0Sstevel@tonic-gate {
180*0Sstevel@tonic-gate if (f->s1)
181*0Sstevel@tonic-gate Free(f->s1);
182*0Sstevel@tonic-gate Free((char *)f);
183*0Sstevel@tonic-gate }
184