17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
23ace1a5f1Sdp * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate extern char *postbegin;
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include <stdio.h>
307c478bd9Sstevel@tonic-gate #include <errno.h>
317c478bd9Sstevel@tonic-gate #include <string.h>
327c478bd9Sstevel@tonic-gate #include <stdarg.h>
337c478bd9Sstevel@tonic-gate #include <signal.h>
347c478bd9Sstevel@tonic-gate #include <unistd.h>
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate #include <sys/ioccom.h>
377c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate #include <sys/bpp_io.h>
407c478bd9Sstevel@tonic-gate #include <sys/ecppsys.h>
417c478bd9Sstevel@tonic-gate #include <sys/prnio.h>
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate #define PRINTER_IO_ERROR 129
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate * the parameter structure for the parallel port
477c478bd9Sstevel@tonic-gate */
487c478bd9Sstevel@tonic-gate struct ppc_params_t {
497c478bd9Sstevel@tonic-gate int flags; /* same as above */
507c478bd9Sstevel@tonic-gate int state; /* status of the printer interface */
517c478bd9Sstevel@tonic-gate int strobe_w; /* strobe width, in uS */
527c478bd9Sstevel@tonic-gate int data_setup; /* data setup time, in uS */
537c478bd9Sstevel@tonic-gate int ack_timeout; /* ACK timeout, in secs */
547c478bd9Sstevel@tonic-gate int error_timeout; /* PAPER OUT, etc... timeout, in secs */
557c478bd9Sstevel@tonic-gate int busy_timeout; /* BUSY timeout, in seconds */
567c478bd9Sstevel@tonic-gate };
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate extern char *block;
617c478bd9Sstevel@tonic-gate extern int head, tail;
627c478bd9Sstevel@tonic-gate extern int readblock(int);
637c478bd9Sstevel@tonic-gate extern FILE *fp_log;
647c478bd9Sstevel@tonic-gate static void printer_info(char *fmt, ...);
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate /* These are the routines avaliable to others for use */
677c478bd9Sstevel@tonic-gate int is_a_parallel_bpp(int);
687c478bd9Sstevel@tonic-gate int bpp_state(int);
697c478bd9Sstevel@tonic-gate int parallel_comm(int, int());
707c478bd9Sstevel@tonic-gate int get_ecpp_status(int);
717c478bd9Sstevel@tonic-gate int is_a_prnio(int);
727c478bd9Sstevel@tonic-gate int prnio_state(int);
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate #define PRINTER_ERROR_PAPER_OUT 1
757c478bd9Sstevel@tonic-gate #define PRINTER_ERROR_OFFLINE 2
767c478bd9Sstevel@tonic-gate #define PRINTER_ERROR_BUSY 3
777c478bd9Sstevel@tonic-gate #define PRINTER_ERROR_ERROR 4
787c478bd9Sstevel@tonic-gate #define PRINTER_ERROR_CABLE_POWER 5
797c478bd9Sstevel@tonic-gate #define PRINTER_ERROR_UNKNOWN 6
807c478bd9Sstevel@tonic-gate #define PRINTER_ERROR_TIMEOUT 7
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate /****************************************************************************/
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate /**
857c478bd9Sstevel@tonic-gate * for BPP PARALLEL interfaces
867c478bd9Sstevel@tonic-gate **/
877c478bd9Sstevel@tonic-gate
is_a_parallel_bpp(int fd)887c478bd9Sstevel@tonic-gate int is_a_parallel_bpp(int fd)
897c478bd9Sstevel@tonic-gate {
907c478bd9Sstevel@tonic-gate if (ioctl(fd, BPPIOC_TESTIO) == 0 || errno == EIO)
917c478bd9Sstevel@tonic-gate return(1);
927c478bd9Sstevel@tonic-gate return(0);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate #if defined(DEBUG) && defined(NOTDEF)
BppState(int state)977c478bd9Sstevel@tonic-gate char *BppState(int state)
987c478bd9Sstevel@tonic-gate {
997c478bd9Sstevel@tonic-gate static char buf[BUFSIZ];
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate memset(buf, 0, sizeof(buf));
102*bbf21555SRichard Lowe sprintf(buf, "State (0x%.4x) - (%s%s%s%s)\n", state,
1037c478bd9Sstevel@tonic-gate ((state & BPP_SLCT_ERR) ? "offline " : ""),
1047c478bd9Sstevel@tonic-gate ((state & BPP_BUSY_ERR) ? "busy " : ""),
1057c478bd9Sstevel@tonic-gate ((state & BPP_PE_ERR) ? "paper " : ""),
1067c478bd9Sstevel@tonic-gate ((state & BPP_ERR_ERR) ? "error " : ""));
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate return(buf);
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate #endif
1117c478bd9Sstevel@tonic-gate
bpp_state(int fd)1127c478bd9Sstevel@tonic-gate int bpp_state(int fd)
1137c478bd9Sstevel@tonic-gate {
1147c478bd9Sstevel@tonic-gate if (ioctl(fd, BPPIOC_TESTIO)) {
1157c478bd9Sstevel@tonic-gate struct bpp_error_status bpp_stat;
1167c478bd9Sstevel@tonic-gate int state;
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate if (ioctl(fd, BPPIOC_GETERR, &bpp_stat) < 0)
1197c478bd9Sstevel@tonic-gate exit(PRINTER_IO_ERROR);
1207c478bd9Sstevel@tonic-gate state = bpp_stat.pin_status;
1217c478bd9Sstevel@tonic-gate
122*bbf21555SRichard Lowe #if defined(DEBUG) && defined(NOTDEF)
1237c478bd9Sstevel@tonic-gate logit("%s", BppState(state));
1247c478bd9Sstevel@tonic-gate #endif
125*bbf21555SRichard Lowe
1267c478bd9Sstevel@tonic-gate if (state == (BPP_PE_ERR | BPP_ERR_ERR | BPP_SLCT_ERR)) {
1277c478bd9Sstevel@tonic-gate /* paper is out */
1287c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_PAPER_OUT);
1297c478bd9Sstevel@tonic-gate } else if (state & BPP_BUSY_ERR) {
1307c478bd9Sstevel@tonic-gate /* printer is busy */
1317c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_BUSY);
1327c478bd9Sstevel@tonic-gate } else if (state & BPP_SLCT_ERR) {
1337c478bd9Sstevel@tonic-gate /* printer is offline */
1347c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_OFFLINE);
1357c478bd9Sstevel@tonic-gate } else if (state & BPP_ERR_ERR) {
1367c478bd9Sstevel@tonic-gate /* printer is errored */
1377c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_ERROR);
1387c478bd9Sstevel@tonic-gate } else if (state == BPP_PE_ERR) {
1397c478bd9Sstevel@tonic-gate /* printer is off/unplugged */
1407c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_CABLE_POWER);
1417c478bd9Sstevel@tonic-gate } else if (state) {
1427c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_UNKNOWN);
1437c478bd9Sstevel@tonic-gate } else
1447c478bd9Sstevel@tonic-gate return(0);
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate return(0);
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate
149*bbf21555SRichard Lowe int
get_ecpp_status(int fd)1507c478bd9Sstevel@tonic-gate get_ecpp_status(int fd)
1517c478bd9Sstevel@tonic-gate {
1527c478bd9Sstevel@tonic-gate int state;
1537c478bd9Sstevel@tonic-gate struct ecpp_transfer_parms transfer_parms;
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate if (ioctl(fd, ECPPIOC_GETPARMS, &transfer_parms) == -1) {
1577c478bd9Sstevel@tonic-gate return(-1);
1587c478bd9Sstevel@tonic-gate }
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate state = transfer_parms.mode;
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate * We don't know what all printers will return in
1637c478bd9Sstevel@tonic-gate * nibble mode, therefore if we support nibble mode we will
1647c478bd9Sstevel@tonic-gate * force the printer to be in CENTRONICS mode.
1657c478bd9Sstevel@tonic-gate */
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate if (state != ECPP_CENTRONICS) {
1687c478bd9Sstevel@tonic-gate transfer_parms.mode = ECPP_CENTRONICS;
1697c478bd9Sstevel@tonic-gate if (ioctl(fd, ECPPIOC_SETPARMS, &transfer_parms) == -1) {
1707c478bd9Sstevel@tonic-gate return(-1);
1717c478bd9Sstevel@tonic-gate } else {
1727c478bd9Sstevel@tonic-gate state = ECPP_CENTRONICS;
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate return(state);
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate /**
180*bbf21555SRichard Lowe * For prnio(4I) - generic printer interface
1817c478bd9Sstevel@tonic-gate **/
is_a_prnio(int fd)1827c478bd9Sstevel@tonic-gate int is_a_prnio(int fd)
1837c478bd9Sstevel@tonic-gate {
1847c478bd9Sstevel@tonic-gate uint_t cap;
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate /* check if device supports prnio */
1877c478bd9Sstevel@tonic-gate if (ioctl(fd, PRNIOC_GET_IFCAP, &cap) == -1) {
1887c478bd9Sstevel@tonic-gate return (0);
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate /* we will use 1284 status if available */
1917c478bd9Sstevel@tonic-gate if ((cap & PRN_1284_STATUS) == 0) {
1927c478bd9Sstevel@tonic-gate /* some devices may only support 1284 status in unidir. mode */
1937c478bd9Sstevel@tonic-gate if (cap & PRN_BIDI) {
1947c478bd9Sstevel@tonic-gate cap &= ~PRN_BIDI;
1957c478bd9Sstevel@tonic-gate (void) ioctl(fd, PRNIOC_SET_IFCAP, &cap);
1967c478bd9Sstevel@tonic-gate }
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate return (1);
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate
prnio_state(int fd)2017c478bd9Sstevel@tonic-gate int prnio_state(int fd)
2027c478bd9Sstevel@tonic-gate {
2037c478bd9Sstevel@tonic-gate uint_t status;
2047c478bd9Sstevel@tonic-gate uchar_t pins;
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate if ((ioctl(fd, PRNIOC_GET_STATUS, &status) == 0) &&
2077c478bd9Sstevel@tonic-gate (status & PRN_READY)) {
2087c478bd9Sstevel@tonic-gate return(0);
2097c478bd9Sstevel@tonic-gate }
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate if (ioctl(fd, PRNIOC_GET_1284_STATUS, &pins) != 0) {
2127c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_UNKNOWN);
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate if ((pins & ~PRN_1284_BUSY) == PRN_1284_PE) {
2167c478bd9Sstevel@tonic-gate /* paper is out */
2177c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_PAPER_OUT);
2187c478bd9Sstevel@tonic-gate } else if (pins == (PRN_1284_PE | PRN_1284_SELECT |
2197c478bd9Sstevel@tonic-gate PRN_1284_NOFAULT | PRN_1284_BUSY)) {
2207c478bd9Sstevel@tonic-gate /* printer is off/unplugged */
2217c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_CABLE_POWER);
2227c478bd9Sstevel@tonic-gate } else if ((pins & PRN_1284_SELECT) == 0) {
2237c478bd9Sstevel@tonic-gate /* printer is offline */
2247c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_OFFLINE);
2257c478bd9Sstevel@tonic-gate } else if ((pins & PRN_1284_NOFAULT) == 0) {
2267c478bd9Sstevel@tonic-gate /* printer is errored */
2277c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_ERROR);
2287c478bd9Sstevel@tonic-gate } else if (pins & PRN_1284_PE) {
2297c478bd9Sstevel@tonic-gate /* paper is out */
2307c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_PAPER_OUT);
2317c478bd9Sstevel@tonic-gate } else if (pins ^ (PRN_1284_SELECT | PRN_1284_NOFAULT)) {
2327c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_UNKNOWN);
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate return(0);
2357c478bd9Sstevel@tonic-gate }
236*bbf21555SRichard Lowe
2377c478bd9Sstevel@tonic-gate /**
2387c478bd9Sstevel@tonic-gate * Common routines
2397c478bd9Sstevel@tonic-gate **/
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate /*ARGSUSED0*/
2427c478bd9Sstevel@tonic-gate static void
ByeByeParallel(int sig)2437c478bd9Sstevel@tonic-gate ByeByeParallel(int sig)
2447c478bd9Sstevel@tonic-gate {
2457c478bd9Sstevel@tonic-gate /* try to shove out the EOT */
2467c478bd9Sstevel@tonic-gate (void) write(1, "\004", 1);
2477c478bd9Sstevel@tonic-gate exit(0);
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate
2517c478bd9Sstevel@tonic-gate /*ARGSUSED0*/
2527c478bd9Sstevel@tonic-gate static void
printer_info(char * fmt,...)2537c478bd9Sstevel@tonic-gate printer_info(char *fmt, ...)
2547c478bd9Sstevel@tonic-gate {
2557c478bd9Sstevel@tonic-gate char mesg[BUFSIZ];
2567c478bd9Sstevel@tonic-gate va_list ap;
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate va_start(ap, fmt);
2597c478bd9Sstevel@tonic-gate vsprintf(mesg, fmt, ap);
2607c478bd9Sstevel@tonic-gate va_end(ap);
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate fprintf(stderr,
2637c478bd9Sstevel@tonic-gate "%%%%[ PrinterError: %s; source: parallel ]%%%%\n",
2647c478bd9Sstevel@tonic-gate mesg);
2657c478bd9Sstevel@tonic-gate fflush(stderr);
2667c478bd9Sstevel@tonic-gate fsync(2);
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate if (fp_log != stderr) {
2697c478bd9Sstevel@tonic-gate fprintf(fp_log,
2707c478bd9Sstevel@tonic-gate "%%%%[ PrinterError: %s; source: parallel ]%%%%\n",
2717c478bd9Sstevel@tonic-gate mesg);
2727c478bd9Sstevel@tonic-gate fflush(fp_log);
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate static void
printer_error(int error)2777c478bd9Sstevel@tonic-gate printer_error(int error)
2787c478bd9Sstevel@tonic-gate {
2797c478bd9Sstevel@tonic-gate switch (error) {
2807c478bd9Sstevel@tonic-gate case -1:
281ace1a5f1Sdp printer_info("ioctl(): %s", strerror(errno));
2827c478bd9Sstevel@tonic-gate break;
2837c478bd9Sstevel@tonic-gate case PRINTER_ERROR_PAPER_OUT:
2847c478bd9Sstevel@tonic-gate printer_info("out of paper");
2857c478bd9Sstevel@tonic-gate break;
2867c478bd9Sstevel@tonic-gate case PRINTER_ERROR_OFFLINE:
2877c478bd9Sstevel@tonic-gate printer_info("offline");
2887c478bd9Sstevel@tonic-gate break;
2897c478bd9Sstevel@tonic-gate case PRINTER_ERROR_BUSY:
2907c478bd9Sstevel@tonic-gate printer_info("busy");
2917c478bd9Sstevel@tonic-gate break;
2927c478bd9Sstevel@tonic-gate case PRINTER_ERROR_ERROR:
2937c478bd9Sstevel@tonic-gate printer_info("printer error");
2947c478bd9Sstevel@tonic-gate break;
2957c478bd9Sstevel@tonic-gate case PRINTER_ERROR_CABLE_POWER:
2967c478bd9Sstevel@tonic-gate printer_info("printer powered off or disconnected");
2977c478bd9Sstevel@tonic-gate break;
2987c478bd9Sstevel@tonic-gate case PRINTER_ERROR_UNKNOWN:
2997c478bd9Sstevel@tonic-gate printer_info("unknown error");
3007c478bd9Sstevel@tonic-gate break;
3017c478bd9Sstevel@tonic-gate case PRINTER_ERROR_TIMEOUT:
3027c478bd9Sstevel@tonic-gate printer_info("communications timeout");
3037c478bd9Sstevel@tonic-gate break;
3047c478bd9Sstevel@tonic-gate default:
3057c478bd9Sstevel@tonic-gate printer_info("get_status() failed");
3067c478bd9Sstevel@tonic-gate }
3077c478bd9Sstevel@tonic-gate }
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate static void
wait_state(int fd,int get_state ())3117c478bd9Sstevel@tonic-gate wait_state(int fd, int get_state())
3127c478bd9Sstevel@tonic-gate {
3137c478bd9Sstevel@tonic-gate int state;
3147c478bd9Sstevel@tonic-gate int was_faulted = 0;
3157c478bd9Sstevel@tonic-gate
3167c478bd9Sstevel@tonic-gate while (state = get_state(fd)) {
3177c478bd9Sstevel@tonic-gate was_faulted=1;
3187c478bd9Sstevel@tonic-gate printer_error(state);
3197c478bd9Sstevel@tonic-gate sleep(15);
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate if (was_faulted) {
3237c478bd9Sstevel@tonic-gate fprintf(stderr, "%%%%[ status: idle ]%%%%\n");
3247c478bd9Sstevel@tonic-gate fflush(stderr);
3257c478bd9Sstevel@tonic-gate fsync(2);
3267c478bd9Sstevel@tonic-gate if (fp_log != stderr) {
3277c478bd9Sstevel@tonic-gate fprintf(fp_log, "%%%%[ status: idle ]%%%%\n");
3287c478bd9Sstevel@tonic-gate fflush(fp_log);
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate }
3327c478bd9Sstevel@tonic-gate
3337c478bd9Sstevel@tonic-gate
3347c478bd9Sstevel@tonic-gate int
parallel_comm(int fd,int get_state ())3357c478bd9Sstevel@tonic-gate parallel_comm(int fd, int get_state())
3367c478bd9Sstevel@tonic-gate {
3377c478bd9Sstevel@tonic-gate int actual; /* number of bytes successfully written */
3387c478bd9Sstevel@tonic-gate int count = 0;
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate (void) signal(SIGTERM, ByeByeParallel);
3417c478bd9Sstevel@tonic-gate (void) signal(SIGQUIT, ByeByeParallel);
3427c478bd9Sstevel@tonic-gate (void) signal(SIGHUP, ByeByeParallel);
3437c478bd9Sstevel@tonic-gate (void) signal(SIGINT, ByeByeParallel);
3447c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, SIG_IGN);
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate /* is the device ready? */
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate /* bracket job with EOT */
3497c478bd9Sstevel@tonic-gate wait_state(fd, get_state);
3507c478bd9Sstevel@tonic-gate (void) write(fd, "\004", 1);
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gate /* write(fd, postbegin, strlen(postbegin)); */
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate while (readblock(fileno(stdin)) > 0) {
3557c478bd9Sstevel@tonic-gate wait_state(fd, get_state);
3567c478bd9Sstevel@tonic-gate alarm(120);
3577c478bd9Sstevel@tonic-gate if ((actual = write(fd, block + head, tail - head)) == -1) {
3587c478bd9Sstevel@tonic-gate alarm(0);
3597c478bd9Sstevel@tonic-gate if (errno == EINTR) {
3607c478bd9Sstevel@tonic-gate printer_error(PRINTER_ERROR_TIMEOUT);
3617c478bd9Sstevel@tonic-gate sleep(30);
3627c478bd9Sstevel@tonic-gate continue;
3637c478bd9Sstevel@tonic-gate } else {
3647c478bd9Sstevel@tonic-gate printer_info("I/O Error during write(): %s",
3657c478bd9Sstevel@tonic-gate strerror(errno));
3667c478bd9Sstevel@tonic-gate exit(2);
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate alarm(0);
3707c478bd9Sstevel@tonic-gate if (actual >= 0)
3717c478bd9Sstevel@tonic-gate head += actual;
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate #if defined(DEBUG) && defined(NOTDEF)
3747c478bd9Sstevel@tonic-gate logit("Writing (%d) at 0x%x actual: %d, %s\n", count++, head,
375ace1a5f1Sdp actual, (actual < 1 ? strerror(errno) : ""));
3767c478bd9Sstevel@tonic-gate #endif
3777c478bd9Sstevel@tonic-gate }
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate /* write the final EOT */
3807c478bd9Sstevel@tonic-gate wait_state(fd, get_state);
3817c478bd9Sstevel@tonic-gate (void) write(fd, "\004", 1);
3827c478bd9Sstevel@tonic-gate
3837c478bd9Sstevel@tonic-gate return (0);
3847c478bd9Sstevel@tonic-gate }
385