]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
c07d5b2d | 2 | * "$Id: scsi-irix.c 177 2006-06-21 00:20:03Z jlovell $" |
ef416fc2 | 3 | * |
4 | * IRIX SCSI printer support for the Common UNIX Printing System (CUPS). | |
5 | * | |
6 | * Copyright 2003-2005 by Easy Software Products, all rights reserved. | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or | |
9 | * without modification, are permitted provided that the | |
10 | * following conditions are met: | |
11 | * | |
12 | * 1. Redistributions of source code must retain the above | |
13 | * copyright notice, this list of conditions and the | |
14 | * following disclaimer. | |
15 | * | |
16 | * 2. Redistributions in binary form must reproduce the | |
17 | * above copyright notice, this list of conditions and | |
18 | * the following disclaimer in the documentation and/or | |
19 | * other materials provided with the distribution. | |
20 | * | |
21 | * 3. All advertising materials mentioning features or use | |
22 | * of this software must display the following | |
23 | * acknowledgement: | |
24 | * | |
25 | * This product includes software developed by Easy | |
26 | * Software Products. | |
27 | * | |
28 | * 4. The name of Easy Software Products may not be used to | |
29 | * endorse or promote products derived from this software | |
30 | * without specific prior written permission. | |
31 | * | |
32 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS | |
33 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | |
34 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
35 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
36 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS | |
37 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
39 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
40 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
41 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
42 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | |
43 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
44 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | |
45 | * DAMAGE. | |
46 | * | |
47 | * Contents: | |
48 | * | |
49 | * list_devices() - List the available SCSI printer devices. | |
50 | * print_device() - Print a file to a SCSI device. | |
51 | */ | |
52 | ||
53 | /* | |
54 | * Include necessary headers. | |
55 | */ | |
56 | ||
57 | #include <bstring.h> /* memcpy() and friends */ | |
58 | #include <sys/dsreq.h> /* SCSI interface stuff */ | |
59 | ||
60 | ||
61 | /* | |
62 | * 'list_devices()' - List the available SCSI printer devices. | |
63 | */ | |
64 | ||
65 | void | |
66 | list_devices(void) | |
67 | { | |
68 | puts("direct scsi \"Unknown\" \"SCSI Printer\""); | |
69 | } | |
70 | ||
71 | ||
72 | /* | |
73 | * 'print_device()' - Print a file to a SCSI device. | |
74 | */ | |
75 | ||
76 | int /* O - Print status */ | |
77 | print_device(const char *resource, /* I - SCSI device */ | |
78 | int fd, /* I - File to print */ | |
79 | int copies) /* I - Number of copies to print */ | |
80 | { | |
81 | int scsi_fd; /* SCSI file descriptor */ | |
82 | char buffer[8192]; /* Data buffer */ | |
83 | int bytes; /* Number of bytes */ | |
84 | int try; /* Current try */ | |
85 | dsreq_t scsi_req; /* SCSI request */ | |
86 | char scsi_cmd[6]; /* SCSI command data */ | |
87 | #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) | |
88 | struct sigaction action; /* Actions for POSIX signals */ | |
89 | #endif /* HAVE_SIGACTION && !HAVE_SIGSET */ | |
90 | ||
91 | ||
92 | /* | |
93 | * Make sure we have a valid resource name... | |
94 | */ | |
95 | ||
96 | if (strncmp(resource, "/dev/scsi/", 10) != 0) | |
97 | { | |
98 | fprintf(stderr, "ERROR: Bad SCSI device file \"%s\"!\n", resource); | |
99 | return (CUPS_BACKEND_STOP); | |
100 | } | |
101 | ||
102 | /* | |
103 | * Open the SCSI device file... | |
104 | */ | |
105 | ||
757d2cad | 106 | fputs("STATE: +connecting-to-device\n", stderr); |
107 | ||
ef416fc2 | 108 | do |
109 | { | |
110 | if ((scsi_fd = open(resource, O_RDWR | O_EXCL)) == -1) | |
111 | { | |
112 | if (getenv("CLASS") != NULL) | |
113 | { | |
114 | /* | |
115 | * If the CLASS environment variable is set, the job was submitted | |
116 | * to a class and not to a specific queue. In this case, we want | |
117 | * to abort immediately so that the job can be requeued on the next | |
118 | * available printer in the class. | |
119 | */ | |
120 | ||
121 | fputs("INFO: Unable to open SCSI device, queuing on next printer in class...\n", | |
122 | stderr); | |
123 | ||
124 | /* | |
125 | * Sleep 5 seconds to keep the job from requeuing too rapidly... | |
126 | */ | |
127 | ||
128 | sleep(5); | |
129 | ||
130 | return (1); | |
131 | } | |
132 | ||
133 | if (errno != EAGAIN && errno != EBUSY) | |
134 | { | |
135 | fprintf(stderr, "ERROR: Unable to open SCSI device \"%s\" - %s\n", | |
136 | resource, strerror(errno)); | |
137 | return (CUPS_BACKEND_FAILED); | |
138 | } | |
139 | else | |
140 | { | |
141 | fprintf(stderr, "INFO: SCSI device \"%s\" busy; retrying...\n", | |
142 | resource); | |
143 | sleep(30); | |
144 | } | |
145 | } | |
146 | } | |
147 | while (scsi_fd == -1); | |
148 | ||
757d2cad | 149 | fputs("STATE: -connecting-to-device\n", stderr); |
150 | ||
ef416fc2 | 151 | /* |
152 | * Now that we are "connected" to the port, ignore SIGTERM so that we | |
153 | * can finish out any page data the driver sends (e.g. to eject the | |
154 | * current page... Only ignore SIGTERM if we are printing data from | |
155 | * stdin (otherwise you can't cancel raw jobs...) | |
156 | */ | |
157 | ||
158 | if (fd != 0) | |
159 | { | |
160 | #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */ | |
161 | sigset(SIGTERM, SIG_IGN); | |
162 | #elif defined(HAVE_SIGACTION) | |
163 | memset(&action, 0, sizeof(action)); | |
164 | ||
165 | sigemptyset(&action.sa_mask); | |
166 | action.sa_handler = SIG_IGN; | |
167 | sigaction(SIGTERM, &action, NULL); | |
168 | #else | |
169 | signal(SIGTERM, SIG_IGN); | |
170 | #endif /* HAVE_SIGSET */ | |
171 | } | |
172 | ||
173 | /* | |
174 | * Copy the print file to the device... | |
175 | */ | |
176 | ||
177 | while (copies > 0) | |
178 | { | |
179 | if (fd != 0) | |
180 | lseek(fd, 0, SEEK_SET); | |
181 | ||
182 | while ((bytes = read(fd, buffer, sizeof(buffer))) > 0) | |
183 | { | |
184 | memset(&scsi_req, 0, sizeof(scsi_req)); | |
185 | ||
186 | scsi_req.ds_flags = DSRQ_WRITE; | |
187 | scsi_req.ds_time = 60 * 1000; | |
188 | scsi_req.ds_cmdbuf = scsi_cmd; | |
189 | scsi_req.ds_cmdlen = 6; | |
190 | scsi_req.ds_databuf = buffer; | |
191 | scsi_req.ds_datalen = bytes; | |
192 | ||
193 | scsi_cmd[0] = 0x0a; /* Group 0 print command */ | |
194 | scsi_cmd[1] = 0x00; | |
195 | scsi_cmd[2] = bytes / 65536; | |
196 | scsi_cmd[3] = bytes / 256; | |
197 | scsi_cmd[4] = bytes; | |
198 | scsi_cmd[5] = 0x00; | |
199 | ||
200 | for (try = 0; try < 10; try ++) | |
201 | if (ioctl(scsi_fd, DS_ENTER, &scsi_req) < 0 || | |
202 | scsi_req.ds_status != 0) | |
203 | { | |
204 | fprintf(stderr, "WARNING: SCSI command timed out (%d); retrying...\n", | |
205 | scsi_req.ds_status); | |
206 | sleep(try + 1); | |
207 | } | |
208 | else | |
209 | break; | |
210 | ||
211 | if (try >= 10) | |
212 | { | |
213 | fprintf(stderr, "ERROR: Unable to send print data (%d)\n", | |
214 | scsi_req.ds_status); | |
215 | close(scsi_fd); | |
216 | return (CUPS_BACKEND_FAILED); | |
217 | } | |
218 | } | |
219 | ||
220 | copies --; | |
221 | } | |
222 | ||
223 | /* | |
224 | * Close the device and return... | |
225 | */ | |
226 | ||
227 | close(fd); | |
228 | ||
229 | return (CUPS_BACKEND_OK); | |
230 | } | |
231 | ||
232 | ||
233 | /* | |
c07d5b2d | 234 | * End of "$Id: scsi-irix.c 177 2006-06-21 00:20:03Z jlovell $". |
ef416fc2 | 235 | */ |