]> git.ipfire.org Git - thirdparty/cups.git/blame - backend/scsi-irix.c
Revamp child signal handling to remove all processing from the handler
[thirdparty/cups.git] / backend / scsi-irix.c
CommitLineData
62810009 1/*
19a373c4 2 * "$Id: scsi-irix.c,v 1.3 2003/01/15 20:41:37 mike Exp $"
62810009 3 *
4 * IRIX SCSI printer support for the Common UNIX Printing System (CUPS).
5 *
997fbfa7 6 * Copyright 2003 by Easy Software Products, all rights reserved.
62810009 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
65void
66list_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
76int /* O - Print status */
77print_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 */
19a373c4 86 char scsi_cmd[6]; /* SCSI command data */
62810009 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 (1);
100 }
101
102 /*
103 * Open the SCSI device file...
104 */
105
106 do
107 {
108 if ((scsi_fd = open(resource, O_RDWR | O_EXCL)) == -1)
109 {
110 if (errno != EAGAIN && errno != EBUSY)
111 {
112 fprintf(stderr, "ERROR: Unable to open SCSI device \"%s\" - %s\n",
113 resource, strerror(errno));
114 return (1);
115 }
116 else
117 {
118 fprintf(stderr, "INFO: SCSI device \"%s\" busy; retrying...\n",
119 resource);
120 sleep(30);
121 }
122 }
123 }
124 while (scsi_fd == -1);
125
126 /*
127 * Now that we are "connected" to the port, ignore SIGTERM so that we
128 * can finish out any page data the driver sends (e.g. to eject the
129 * current page... Only ignore SIGTERM if we are printing data from
130 * stdin (otherwise you can't cancel raw jobs...)
131 */
132
133 if (fd != 0)
134 {
135#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
136 sigset(SIGTERM, SIG_IGN);
137#elif defined(HAVE_SIGACTION)
138 memset(&action, 0, sizeof(action));
139
140 sigemptyset(&action.sa_mask);
141 action.sa_handler = SIG_IGN;
142 sigaction(SIGTERM, &action, NULL);
143#else
144 signal(SIGTERM, SIG_IGN);
145#endif /* HAVE_SIGSET */
146 }
147
148 /*
149 * Copy the print file to the device...
150 */
151
152 while (copies > 0)
153 {
154 if (fd != 0)
155 lseek(fd, 0, SEEK_SET);
156
157 while ((bytes = read(fd, buffer, sizeof(buffer))) > 0)
158 {
159 memset(&scsi_req, 0, sizeof(scsi_req));
160
161 scsi_req.ds_flags = DSRQ_WRITE;
162 scsi_req.ds_time = 60 * 1000;
163 scsi_req.ds_cmdbuf = scsi_cmd;
164 scsi_req.ds_cmdlen = 6;
165 scsi_req.ds_databuf = buffer;
166 scsi_req.ds_datalen = bytes;
167
168 scsi_cmd[0] = 0x0a; /* Group 0 print command */
169 scsi_cmd[1] = 0x00;
170 scsi_cmd[2] = bytes / 65536;
171 scsi_cmd[3] = bytes / 256;
172 scsi_cmd[4] = bytes;
173 scsi_cmd[5] = 0x00;
174
175 for (try = 0; try < 10; try ++)
176 if (ioctl(scsi_fd, DS_ENTER, &scsi_req) < 0 ||
177 scsi_req.ds_status != 0)
178 {
179 fprintf(stderr, "WARNING: SCSI command timed out (%d); retrying...\n",
180 scsi_req.ds_status);
181 sleep(try + 1);
182 }
183 else
184 break;
185
186 if (try >= 10)
187 {
188 fprintf(stderr, "ERROR: Unable to send print data (%d)\n",
189 scsi_req.ds_status);
190 close(scsi_fd);
191 return (1);
192 }
193 }
194
195 copies --;
196 }
197
198 /*
199 * Close the device and return...
200 */
201
202 close(fd);
203
204 return (0);
205}
206
207
208/*
19a373c4 209 * End of "$Id: scsi-irix.c,v 1.3 2003/01/15 20:41:37 mike Exp $".
62810009 210 */