xref: /titanic_51/usr/src/cmd/lp/cmd/lpsched/disena.c (revision 791a814c934fcd4deb13b26c1f116ff283272a0d)
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 #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.9.1.4	*/
27 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
28 
29 #include "lpsched.h"
30 #include <time.h>
31 
32 /**
33  ** disable() - DISABLE PRINTER
34  **/
35 
36 int
37 disable(PSTATUS *pps, char *reason, int when)
38 {
39 	if (pps->status & PS_DISABLED)
40 		return (-1);
41 
42 	else {
43 		pps->status |= PS_DISABLED;
44 		time (&pps->dis_date);
45 		load_str (&pps->dis_reason, reason);
46 
47 		dump_pstatus ();
48 
49 		if (pps->status & PS_BUSY)
50 			switch (when) {
51 
52 			case DISABLE_STOP:
53 				/*
54 				 * Stop current job, requeue.
55 				 */
56 				if (pps->request)
57 				    pps->request->request->outcome |= RS_STOPPED;
58 				terminate (pps->exec);
59 				break;
60 
61 			case DISABLE_FINISH:
62 				/*
63 				 * Let current job finish.
64 				 */
65 				break;
66 
67 			case DISABLE_CANCEL:
68 				/*
69 				 * Cancel current job outright.
70 				 */
71 				if (pps->request)
72 				    cancel (pps->request, 1);
73 				break;
74 
75 			}
76 
77 		/*
78 		 * Need we check to see if requests assigned to
79 		 * this printer should be assigned elsewhere?
80 		 * No, if the "validate()" routine is properly
81 		 * assigning requests. If another printer is available
82 		 * for printing requests (that would otherwise be)
83 		 * assigned to this printer, at least one of those
84 		 * requests will be assigned to that other printer,
85 		 * and should be currently printing. Once it is done
86 		 * printing, the queue will be examined for the next
87 		 * request, and the one(s) assigned this printer will
88 		 * be picked up.
89 		 */
90 /*		(void)queue_repel (pps, 0, (qchk_fnc_type)0);	*/
91 
92 		return (0);
93 	}
94 }
95 
96 /**
97  ** enable() - ENABLE PRINTER
98  **/
99 
100 int
101 enable (register PSTATUS *pps)
102 {
103 	/*
104 	 * ``Enabling a printer'' includes clearing a fault and
105 	 * clearing the do-it-later flag to allow the printer
106 	 * to start up again.
107 	 */
108 	if (!(pps->status & (PS_FAULTED|PS_DISABLED|PS_LATER)))
109 		return (-1);
110 
111 	else {
112 		pps->status &= ~(PS_FAULTED|PS_DISABLED|PS_LATER);
113 		(void) time (&pps->dis_date);
114 
115 		dump_pstatus ();
116 
117 		if (pps->alert->active)
118 			cancel_alert (A_PRINTER, pps);
119 
120 		/*
121 		 * Attract the FIRST request that is waiting to
122 		 * print to this printer. In this regard we're acting
123 		 * like the printer just finished printing a request
124 		 * and is looking for another.
125 		 */
126 		queue_attract (pps, qchk_waiting, 1);
127 		return (0);
128 	}
129 }
130