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