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 /* 23*f928ce67Sceastha * 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 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include "stdio.h" 337c478bd9Sstevel@tonic-gate #include "termio.h" 347c478bd9Sstevel@tonic-gate #include "sys/types.h" 357c478bd9Sstevel@tonic-gate #include "errno.h" 367c478bd9Sstevel@tonic-gate #include "signal.h" 377c478bd9Sstevel@tonic-gate #include "sys/times.h" 387c478bd9Sstevel@tonic-gate #include "string.h" 397c478bd9Sstevel@tonic-gate #include "limits.h" 407c478bd9Sstevel@tonic-gate #include <sys/prnio.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #include "lp.h" 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #include <locale.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate /** 477c478bd9Sstevel@tonic-gate ** Begin Sun Additions for Parallel ports 487c478bd9Sstevel@tonic-gate **/ 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate extern char *_sys_errlist[]; 517c478bd9Sstevel@tonic-gate #include <string.h> 527c478bd9Sstevel@tonic-gate #include <stdarg.h> 537c478bd9Sstevel@tonic-gate #include <signal.h> 547c478bd9Sstevel@tonic-gate #include <unistd.h> 557c478bd9Sstevel@tonic-gate #include <sys/types.h> 567c478bd9Sstevel@tonic-gate #include <sys/ioccom.h> 577c478bd9Sstevel@tonic-gate #include <sys/ioctl.h> 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate #include <sys/bpp_io.h> 607c478bd9Sstevel@tonic-gate #include <sys/ecppsys.h> 617c478bd9Sstevel@tonic-gate #include <stropts.h> 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * the parameter structure for the parallel port 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate struct ppc_params_t { 677c478bd9Sstevel@tonic-gate int flags; /* same as above */ 687c478bd9Sstevel@tonic-gate int state; /* status of the printer interface */ 697c478bd9Sstevel@tonic-gate int strobe_w; /* strobe width, in uS */ 707c478bd9Sstevel@tonic-gate int data_setup; /* data setup time, in uS */ 717c478bd9Sstevel@tonic-gate int ack_timeout; /* ACK timeout, in secs */ 727c478bd9Sstevel@tonic-gate int error_timeout; /* PAPER OUT, etc... timeout, in secs */ 737c478bd9Sstevel@tonic-gate int busy_timeout; /* BUSY timeout, in seconds */ 747c478bd9Sstevel@tonic-gate }; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate static void printer_info(char *fmt, ...); 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* These are the routines avaliable to others for use */ 817c478bd9Sstevel@tonic-gate int is_a_parallel_bpp(int); 827c478bd9Sstevel@tonic-gate int bpp_state(int); 837c478bd9Sstevel@tonic-gate int parallel_comm(int, int()); 847c478bd9Sstevel@tonic-gate int get_ecpp_status(int fd); 857c478bd9Sstevel@tonic-gate int is_a_prnio(int); 867c478bd9Sstevel@tonic-gate int prnio_state(int); 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate #define PRINTER_ERROR_PAPER_OUT 1 897c478bd9Sstevel@tonic-gate #define PRINTER_ERROR_OFFLINE 2 907c478bd9Sstevel@tonic-gate #define PRINTER_ERROR_BUSY 3 917c478bd9Sstevel@tonic-gate #define PRINTER_ERROR_ERROR 4 927c478bd9Sstevel@tonic-gate #define PRINTER_ERROR_CABLE_POWER 5 937c478bd9Sstevel@tonic-gate #define PRINTER_ERROR_UNKNOWN 6 947c478bd9Sstevel@tonic-gate #define PRINTER_ERROR_TIMEOUT 7 957c478bd9Sstevel@tonic-gate #define PRINTER_IO_ERROR 129 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate /****************************************************************************/ 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /** 1017c478bd9Sstevel@tonic-gate * for BPP PARALLEL interfaces 1027c478bd9Sstevel@tonic-gate **/ 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate int is_a_parallel_bpp(int fd) 1057c478bd9Sstevel@tonic-gate { 1067c478bd9Sstevel@tonic-gate if (ioctl(fd, BPPIOC_TESTIO) == 0 || errno == EIO) 1077c478bd9Sstevel@tonic-gate return(1); 1087c478bd9Sstevel@tonic-gate return(0); 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate #if defined(DEBUG) && defined(NOTDEF) 1137c478bd9Sstevel@tonic-gate char *BppState(int state) 1147c478bd9Sstevel@tonic-gate { 1157c478bd9Sstevel@tonic-gate static char buf[BUFSIZ]; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate memset(buf, 0, sizeof(buf)); 1187c478bd9Sstevel@tonic-gate sprintf(buf, "State (0x%.4x) - (%s%s%s%s)\n", state, 1197c478bd9Sstevel@tonic-gate ((state & BPP_SLCT_ERR) ? "offline " : ""), 1207c478bd9Sstevel@tonic-gate ((state & BPP_BUSY_ERR) ? "busy " : ""), 1217c478bd9Sstevel@tonic-gate ((state & BPP_PE_ERR) ? "paper " : ""), 1227c478bd9Sstevel@tonic-gate ((state & BPP_ERR_ERR) ? "error " : "")); 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate return(buf); 1257c478bd9Sstevel@tonic-gate } 1267c478bd9Sstevel@tonic-gate #endif 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate int bpp_state(int fd) 1297c478bd9Sstevel@tonic-gate { 1307c478bd9Sstevel@tonic-gate if (ioctl(fd, BPPIOC_TESTIO)) { 1317c478bd9Sstevel@tonic-gate struct bpp_error_status bpp_stat; 1327c478bd9Sstevel@tonic-gate int state; 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate if (ioctl(fd, BPPIOC_GETERR, &bpp_stat) < 0) 1357c478bd9Sstevel@tonic-gate exit(PRINTER_IO_ERROR); 1367c478bd9Sstevel@tonic-gate state = bpp_stat.pin_status; 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate #if defined(DEBUG) && defined(NOTDEF) 1397c478bd9Sstevel@tonic-gate logit("%s", BppState(state)); 1407c478bd9Sstevel@tonic-gate #endif 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate if (state == (BPP_PE_ERR | BPP_ERR_ERR | BPP_SLCT_ERR)) { 1437c478bd9Sstevel@tonic-gate /* paper is out */ 1447c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_PAPER_OUT); 1457c478bd9Sstevel@tonic-gate } else if (state & BPP_BUSY_ERR) { 1467c478bd9Sstevel@tonic-gate /* printer is busy */ 1477c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_BUSY); 1487c478bd9Sstevel@tonic-gate } else if (state & BPP_SLCT_ERR) { 1497c478bd9Sstevel@tonic-gate /* printer is offline */ 1507c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_OFFLINE); 1517c478bd9Sstevel@tonic-gate } else if (state & BPP_ERR_ERR) { 1527c478bd9Sstevel@tonic-gate /* printer is errored */ 1537c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_ERROR); 1547c478bd9Sstevel@tonic-gate } else if (state == BPP_PE_ERR) { 1557c478bd9Sstevel@tonic-gate /* printer is off/unplugged */ 1567c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_CABLE_POWER); 1577c478bd9Sstevel@tonic-gate } else if (state) { 1587c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_UNKNOWN); 1597c478bd9Sstevel@tonic-gate } else 1607c478bd9Sstevel@tonic-gate return(0); 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate return(0); 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate /* 1667c478bd9Sstevel@tonic-gate * For ecpp parallel port 1677c478bd9Sstevel@tonic-gate */ 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate int 1707c478bd9Sstevel@tonic-gate get_ecpp_status(int fd) 1717c478bd9Sstevel@tonic-gate { 1727c478bd9Sstevel@tonic-gate int state; 1737c478bd9Sstevel@tonic-gate struct ecpp_transfer_parms transfer_parms; 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate if (ioctl(fd, ECPPIOC_GETPARMS, &transfer_parms) == -1) { 1777c478bd9Sstevel@tonic-gate return(-1); 1787c478bd9Sstevel@tonic-gate } 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate state = transfer_parms.mode; 1817c478bd9Sstevel@tonic-gate /* 1827c478bd9Sstevel@tonic-gate * We don't know what all printers will return in 1837c478bd9Sstevel@tonic-gate * nibble mode, therefore if we support nibble mode we will 1847c478bd9Sstevel@tonic-gate * force the printer to be in CENTRONICS mode. 1857c478bd9Sstevel@tonic-gate */ 1867c478bd9Sstevel@tonic-gate if (state != ECPP_CENTRONICS) { 1877c478bd9Sstevel@tonic-gate transfer_parms.mode = ECPP_CENTRONICS; 1887c478bd9Sstevel@tonic-gate if (ioctl(fd, ECPPIOC_SETPARMS, &transfer_parms) == -1) { 1897c478bd9Sstevel@tonic-gate return(-1); 1907c478bd9Sstevel@tonic-gate } else { 1917c478bd9Sstevel@tonic-gate state = ECPP_CENTRONICS; 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate } 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate return(state); 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate /** 2007c478bd9Sstevel@tonic-gate * For prnio(7I) - generic printer interface 2017c478bd9Sstevel@tonic-gate **/ 2027c478bd9Sstevel@tonic-gate int is_a_prnio(int fd) 2037c478bd9Sstevel@tonic-gate { 2047c478bd9Sstevel@tonic-gate uint_t cap; 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate /* check if device supports prnio */ 2077c478bd9Sstevel@tonic-gate if (ioctl(fd, PRNIOC_GET_IFCAP, &cap) == -1) { 2087c478bd9Sstevel@tonic-gate return (0); 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate /* we will use 1284 status if available */ 2117c478bd9Sstevel@tonic-gate if ((cap & PRN_1284_STATUS) == 0) { 2127c478bd9Sstevel@tonic-gate /* some devices may only support 1284 status in unidir. mode */ 2137c478bd9Sstevel@tonic-gate if (cap & PRN_BIDI) { 2147c478bd9Sstevel@tonic-gate cap &= ~PRN_BIDI; 2157c478bd9Sstevel@tonic-gate (void) ioctl(fd, PRNIOC_SET_IFCAP, &cap); 2167c478bd9Sstevel@tonic-gate } 2177c478bd9Sstevel@tonic-gate } 2187c478bd9Sstevel@tonic-gate return (1); 2197c478bd9Sstevel@tonic-gate } 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate int prnio_state(int fd) 2227c478bd9Sstevel@tonic-gate { 2237c478bd9Sstevel@tonic-gate uint_t status; 2247c478bd9Sstevel@tonic-gate uchar_t pins; 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate if ((ioctl(fd, PRNIOC_GET_STATUS, &status) == 0) && 2277c478bd9Sstevel@tonic-gate (status & PRN_READY)) { 2287c478bd9Sstevel@tonic-gate return(0); 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate if (ioctl(fd, PRNIOC_GET_1284_STATUS, &pins) != 0) { 2327c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_UNKNOWN); 2337c478bd9Sstevel@tonic-gate } 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate if ((pins & ~PRN_1284_BUSY) == PRN_1284_PE) { 2367c478bd9Sstevel@tonic-gate /* paper is out */ 2377c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_PAPER_OUT); 2387c478bd9Sstevel@tonic-gate } else if (pins == (PRN_1284_PE | PRN_1284_SELECT | 2397c478bd9Sstevel@tonic-gate PRN_1284_NOFAULT | PRN_1284_BUSY)) { 2407c478bd9Sstevel@tonic-gate /* printer is off/unplugged */ 2417c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_CABLE_POWER); 2427c478bd9Sstevel@tonic-gate } else if ((pins & PRN_1284_SELECT) == 0) { 2437c478bd9Sstevel@tonic-gate /* printer is offline */ 2447c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_OFFLINE); 2457c478bd9Sstevel@tonic-gate } else if ((pins & PRN_1284_NOFAULT) == 0) { 2467c478bd9Sstevel@tonic-gate /* printer is errored */ 2477c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_ERROR); 2487c478bd9Sstevel@tonic-gate } else if (pins & PRN_1284_PE) { 2497c478bd9Sstevel@tonic-gate /* paper is out */ 2507c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_PAPER_OUT); 2517c478bd9Sstevel@tonic-gate } else if (pins ^ (PRN_1284_SELECT | PRN_1284_NOFAULT)) { 2527c478bd9Sstevel@tonic-gate return(PRINTER_ERROR_UNKNOWN); 2537c478bd9Sstevel@tonic-gate } 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate return(0); 2567c478bd9Sstevel@tonic-gate } 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate /** 2597c478bd9Sstevel@tonic-gate * Common routines 2607c478bd9Sstevel@tonic-gate **/ 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate /*ARGSUSED0*/ 2637c478bd9Sstevel@tonic-gate static void 2647c478bd9Sstevel@tonic-gate ByeByeParallel(int sig) 2657c478bd9Sstevel@tonic-gate { 2667c478bd9Sstevel@tonic-gate /* try to shove out the EOT */ 2677c478bd9Sstevel@tonic-gate (void) write(1, "\004", 1); 2687c478bd9Sstevel@tonic-gate exit(0); 2697c478bd9Sstevel@tonic-gate } 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate /*ARGSUSED0*/ 2737c478bd9Sstevel@tonic-gate static void 2747c478bd9Sstevel@tonic-gate printer_info(char *fmt, ...) 2757c478bd9Sstevel@tonic-gate { 2767c478bd9Sstevel@tonic-gate char mesg[BUFSIZ]; 2777c478bd9Sstevel@tonic-gate va_list ap; 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate va_start(ap, fmt); 2807c478bd9Sstevel@tonic-gate vsprintf(mesg, fmt, ap); 2817c478bd9Sstevel@tonic-gate va_end(ap); 2827c478bd9Sstevel@tonic-gate /* 2837c478bd9Sstevel@tonic-gate fprintf(stderr, 2847c478bd9Sstevel@tonic-gate "%%%%[ PrinterError: %s; source: parallel ]%%%%\n", 2857c478bd9Sstevel@tonic-gate mesg); 2867c478bd9Sstevel@tonic-gate */ 2877c478bd9Sstevel@tonic-gate fprintf(stderr, "%s\n", mesg); 2887c478bd9Sstevel@tonic-gate fflush(stderr); 2897c478bd9Sstevel@tonic-gate fsync(2); 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate } 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate static void 2947c478bd9Sstevel@tonic-gate printer_error(int error) 2957c478bd9Sstevel@tonic-gate { 2967c478bd9Sstevel@tonic-gate switch (error) { 2977c478bd9Sstevel@tonic-gate case -1: 2987c478bd9Sstevel@tonic-gate printer_info("ioctl(): %s", _sys_errlist[errno]); 2997c478bd9Sstevel@tonic-gate break; 3007c478bd9Sstevel@tonic-gate case PRINTER_ERROR_PAPER_OUT: 3017c478bd9Sstevel@tonic-gate printer_info("out of paper"); 3027c478bd9Sstevel@tonic-gate break; 3037c478bd9Sstevel@tonic-gate case PRINTER_ERROR_OFFLINE: 3047c478bd9Sstevel@tonic-gate printer_info("offline"); 3057c478bd9Sstevel@tonic-gate break; 3067c478bd9Sstevel@tonic-gate case PRINTER_ERROR_BUSY: 3077c478bd9Sstevel@tonic-gate printer_info("busy"); 3087c478bd9Sstevel@tonic-gate break; 3097c478bd9Sstevel@tonic-gate case PRINTER_ERROR_ERROR: 3107c478bd9Sstevel@tonic-gate printer_info("printer error"); 3117c478bd9Sstevel@tonic-gate break; 3127c478bd9Sstevel@tonic-gate case PRINTER_ERROR_CABLE_POWER: 3137c478bd9Sstevel@tonic-gate printer_info("printer powered off or disconnected"); 3147c478bd9Sstevel@tonic-gate break; 3157c478bd9Sstevel@tonic-gate case PRINTER_ERROR_UNKNOWN: 3167c478bd9Sstevel@tonic-gate printer_info("unknown error"); 3177c478bd9Sstevel@tonic-gate break; 3187c478bd9Sstevel@tonic-gate case PRINTER_ERROR_TIMEOUT: 3197c478bd9Sstevel@tonic-gate printer_info("communications timeout"); 3207c478bd9Sstevel@tonic-gate break; 3217c478bd9Sstevel@tonic-gate default: 3227c478bd9Sstevel@tonic-gate printer_info("get_status() failed"); 3237c478bd9Sstevel@tonic-gate } 3247c478bd9Sstevel@tonic-gate } 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate 3277c478bd9Sstevel@tonic-gate static void 3287c478bd9Sstevel@tonic-gate wait_state(int fd, int get_state()) 3297c478bd9Sstevel@tonic-gate { 3307c478bd9Sstevel@tonic-gate int state; 3317c478bd9Sstevel@tonic-gate int was_faulted = 0; 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate while (state = get_state(fd)) { 3347c478bd9Sstevel@tonic-gate was_faulted=1; 3357c478bd9Sstevel@tonic-gate printer_error(state); 3367c478bd9Sstevel@tonic-gate sleep(15); 3377c478bd9Sstevel@tonic-gate } 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate if (was_faulted) { 3407c478bd9Sstevel@tonic-gate fprintf(stderr, "printer ok\n"); 3417c478bd9Sstevel@tonic-gate fflush(stderr); 3427c478bd9Sstevel@tonic-gate fsync(2); 3437c478bd9Sstevel@tonic-gate } 3447c478bd9Sstevel@tonic-gate } 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate /** 3477c478bd9Sstevel@tonic-gate ** end of Sun Additions for parallel port 3487c478bd9Sstevel@tonic-gate **/ 3497c478bd9Sstevel@tonic-gate #define IDENTICAL(A,B) (A.st_dev==B.st_dev && A.st_ino==B.st_ino) 3507c478bd9Sstevel@tonic-gate #define ISBLK(A) ((A.st_mode & S_IFMT) == S_IFBLK) 3517c478bd9Sstevel@tonic-gate #define ISCHR(A) ((A.st_mode & S_IFMT) == S_IFCHR) 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate #define E_SUCCESS 0 3547c478bd9Sstevel@tonic-gate #define E_BAD_INPUT 1 3557c478bd9Sstevel@tonic-gate #define E_BAD_OUTPUT 2 3567c478bd9Sstevel@tonic-gate #define E_BAD_TERM 3 3577c478bd9Sstevel@tonic-gate #define E_IDENTICAL 4 3587c478bd9Sstevel@tonic-gate #define E_WRITE_FAILED 5 3597c478bd9Sstevel@tonic-gate #define E_TIMEOUT 6 3607c478bd9Sstevel@tonic-gate #define E_HANGUP 7 3617c478bd9Sstevel@tonic-gate #define E_INTERRUPT 8 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate #define SAFETY_FACTOR 2.0 3647c478bd9Sstevel@tonic-gate #define R(F) (int)((F) + .5) 3657c478bd9Sstevel@tonic-gate #define DELAY(N,D) R(SAFETY_FACTOR * ((N) / (double)(D))) 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate extern int sys_nerr; 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate extern char *sys_errlist[], 3707c478bd9Sstevel@tonic-gate *getenv(); 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate extern int atoi(); 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate char buffer[BUFSIZ]; 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate void sighup(), 3777c478bd9Sstevel@tonic-gate sigint(), 3787c478bd9Sstevel@tonic-gate sigquit(), 3797c478bd9Sstevel@tonic-gate sigpipe(), 3807c478bd9Sstevel@tonic-gate sigalrm(), 3817c478bd9Sstevel@tonic-gate sigterm(); 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate #if defined(baudrate) 3847c478bd9Sstevel@tonic-gate # undef baudrate 3857c478bd9Sstevel@tonic-gate #endif 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate int baudrate(); 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate int nop(int fd) { return (0); } 3917c478bd9Sstevel@tonic-gate int bpp_state(int); 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate /** 3957c478bd9Sstevel@tonic-gate ** main() 3967c478bd9Sstevel@tonic-gate **/ 3977c478bd9Sstevel@tonic-gate 398*f928ce67Sceastha int 399*f928ce67Sceastha main(int argc, char *argv[]) 4007c478bd9Sstevel@tonic-gate { 401*f928ce67Sceastha int nin, 4027c478bd9Sstevel@tonic-gate nout, 4037c478bd9Sstevel@tonic-gate effective_rate, 4047c478bd9Sstevel@tonic-gate max_delay = 0, 4057c478bd9Sstevel@tonic-gate n; 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate int report_rate; 4087c478bd9Sstevel@tonic-gate 4097c478bd9Sstevel@tonic-gate short print_rate; 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate struct stat in, 4127c478bd9Sstevel@tonic-gate out; 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate struct tms tms; 4157c478bd9Sstevel@tonic-gate 4167c478bd9Sstevel@tonic-gate long epoch_start, 4177c478bd9Sstevel@tonic-gate epoch_end; 4187c478bd9Sstevel@tonic-gate 4197c478bd9Sstevel@tonic-gate char *TERM; 4207c478bd9Sstevel@tonic-gate 4217c478bd9Sstevel@tonic-gate int (*func)(int fd); 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate /* 4247c478bd9Sstevel@tonic-gate * The Spooler can hit us with SIGTERM for three reasons: 4257c478bd9Sstevel@tonic-gate * 4267c478bd9Sstevel@tonic-gate * - the user's job has been canceled 4277c478bd9Sstevel@tonic-gate * - the printer has been disabled while we were printing 4287c478bd9Sstevel@tonic-gate * - the Spooler heard that the printer has a fault, 4297c478bd9Sstevel@tonic-gate * and the fault recovery is wait or beginning 4307c478bd9Sstevel@tonic-gate * 4317c478bd9Sstevel@tonic-gate * We should exit cleanly for the first two cases, 4327c478bd9Sstevel@tonic-gate * but we have to be careful with the last. If it was THIS 4337c478bd9Sstevel@tonic-gate * PROGRAM that told the Spooler about the fault, we must 4347c478bd9Sstevel@tonic-gate * exit consistently. 4357c478bd9Sstevel@tonic-gate * 4367c478bd9Sstevel@tonic-gate * The method of avoiding any problem is to turn off the 4377c478bd9Sstevel@tonic-gate * trapping of SIGTERM before telling the Spooler about 4387c478bd9Sstevel@tonic-gate * the fault. 4397c478bd9Sstevel@tonic-gate * 4407c478bd9Sstevel@tonic-gate * Faults that we can detect: 4417c478bd9Sstevel@tonic-gate * - hangup (drop of carrier) 4427c478bd9Sstevel@tonic-gate * - interrupt (printer sent a break or quit character) 4437c478bd9Sstevel@tonic-gate * - SIGPIPE (output port is a FIFO, and was closed early) 4447c478bd9Sstevel@tonic-gate * - failed or incomplete write() 4457c478bd9Sstevel@tonic-gate * - excess delay in write() (handled with SIGALRM later) 4467c478bd9Sstevel@tonic-gate * 4477c478bd9Sstevel@tonic-gate * Pseudo-faults (errors in use): 4487c478bd9Sstevel@tonic-gate * - No input/output, or strange input/output 4497c478bd9Sstevel@tonic-gate * - Input/output identical 4507c478bd9Sstevel@tonic-gate * - No TERM defined or trouble reading Terminfo database 4517c478bd9Sstevel@tonic-gate */ 4527c478bd9Sstevel@tonic-gate signal (SIGTERM, sigterm); 4537c478bd9Sstevel@tonic-gate signal (SIGHUP, sighup); 4547c478bd9Sstevel@tonic-gate signal (SIGINT, sigint); 4557c478bd9Sstevel@tonic-gate signal (SIGQUIT, sigint); 4567c478bd9Sstevel@tonic-gate signal (SIGPIPE, sigpipe); 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate if (argc > 1 && STREQU(argv[1], "-r")) { 4607c478bd9Sstevel@tonic-gate report_rate = 1; 4617c478bd9Sstevel@tonic-gate argc--; 4627c478bd9Sstevel@tonic-gate argv++; 4637c478bd9Sstevel@tonic-gate } else 4647c478bd9Sstevel@tonic-gate report_rate = 0; 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 4677c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 4687c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 4697c478bd9Sstevel@tonic-gate #endif 4707c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 4717c478bd9Sstevel@tonic-gate 4727c478bd9Sstevel@tonic-gate /* 4737c478bd9Sstevel@tonic-gate * Stat the standard output to be sure it is defined. 4747c478bd9Sstevel@tonic-gate */ 4757c478bd9Sstevel@tonic-gate if (fstat(1, &out) < 0) { 4767c478bd9Sstevel@tonic-gate signal (SIGTERM, SIG_IGN); 4777c478bd9Sstevel@tonic-gate fprintf ( 4787c478bd9Sstevel@tonic-gate stderr, 4797c478bd9Sstevel@tonic-gate gettext("Can't stat output (%s);\nincorrect use of lp.cat!\n"), 4807c478bd9Sstevel@tonic-gate PERROR 4817c478bd9Sstevel@tonic-gate ); 4827c478bd9Sstevel@tonic-gate exit (E_BAD_OUTPUT); 4837c478bd9Sstevel@tonic-gate } 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate /* 4867c478bd9Sstevel@tonic-gate * Stat the standard input to be sure it is defined. 4877c478bd9Sstevel@tonic-gate */ 4887c478bd9Sstevel@tonic-gate if (fstat(0, &in) < 0) { 4897c478bd9Sstevel@tonic-gate signal (SIGTERM, SIG_IGN); 4907c478bd9Sstevel@tonic-gate fprintf ( 4917c478bd9Sstevel@tonic-gate stderr, 4927c478bd9Sstevel@tonic-gate gettext("Can't stat input (%s);\nincorrect use of lp.cat!\n"), 4937c478bd9Sstevel@tonic-gate PERROR 4947c478bd9Sstevel@tonic-gate ); 4957c478bd9Sstevel@tonic-gate exit (E_BAD_INPUT); 4967c478bd9Sstevel@tonic-gate } 4977c478bd9Sstevel@tonic-gate 4987c478bd9Sstevel@tonic-gate /* 4997c478bd9Sstevel@tonic-gate * If the standard output is not a character special file or a 5007c478bd9Sstevel@tonic-gate * block special file, make sure it is not identical to the 5017c478bd9Sstevel@tonic-gate * standard input. 5027c478bd9Sstevel@tonic-gate * 5037c478bd9Sstevel@tonic-gate * If we are an ecpp parallel port in centronics mode treat 5047c478bd9Sstevel@tonic-gate * ourselves as a bpp compatible device. 5057c478bd9Sstevel@tonic-gate */ 5067c478bd9Sstevel@tonic-gate 5077c478bd9Sstevel@tonic-gate if (is_a_prnio(1)) { 5087c478bd9Sstevel@tonic-gate func = prnio_state; 5097c478bd9Sstevel@tonic-gate } else if (is_a_parallel_bpp(1) || 5107c478bd9Sstevel@tonic-gate (get_ecpp_status(1) == ECPP_CENTRONICS)) { 5117c478bd9Sstevel@tonic-gate func = bpp_state; 5127c478bd9Sstevel@tonic-gate } else if (isatty(1)) { 5137c478bd9Sstevel@tonic-gate /* serial connection (probably) - continue as usual */ 5147c478bd9Sstevel@tonic-gate func = nop; 5157c478bd9Sstevel@tonic-gate } else { 5167c478bd9Sstevel@tonic-gate func = nop; 5177c478bd9Sstevel@tonic-gate } 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate if (!ISCHR(out) && !ISBLK(out) && IDENTICAL(out, in)) { 5207c478bd9Sstevel@tonic-gate signal (SIGTERM, SIG_IGN); 5217c478bd9Sstevel@tonic-gate fprintf ( 5227c478bd9Sstevel@tonic-gate stderr, 5237c478bd9Sstevel@tonic-gate gettext("Input and output are identical; incorrect use of lp.cat!\n") 5247c478bd9Sstevel@tonic-gate ); 5257c478bd9Sstevel@tonic-gate exit (E_IDENTICAL); 5267c478bd9Sstevel@tonic-gate } 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate /* 5297c478bd9Sstevel@tonic-gate * The effective data transfer rate is the lesser 5307c478bd9Sstevel@tonic-gate * of the transmission rate and print rate. If an 5317c478bd9Sstevel@tonic-gate * argument was passed to us, it should be a data 5327c478bd9Sstevel@tonic-gate * rate and it may be lower still. 5337c478bd9Sstevel@tonic-gate * Based on the effective data transfer rate, 5347c478bd9Sstevel@tonic-gate * we can predict the maximum delay we should experience. 5357c478bd9Sstevel@tonic-gate * But there are other factors that could introduce 5367c478bd9Sstevel@tonic-gate * delay, so let's be generous; after all, we'd rather 5377c478bd9Sstevel@tonic-gate * err in favor of waiting too long to detect a fault 5387c478bd9Sstevel@tonic-gate * than err too often on false alarms. 5397c478bd9Sstevel@tonic-gate */ 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate if ( 5427c478bd9Sstevel@tonic-gate !(TERM = getenv("TERM")) 5437c478bd9Sstevel@tonic-gate || !*TERM 5447c478bd9Sstevel@tonic-gate ) { 5457c478bd9Sstevel@tonic-gate signal (SIGTERM, SIG_IGN); 5467c478bd9Sstevel@tonic-gate fprintf ( 5477c478bd9Sstevel@tonic-gate stderr, 5487c478bd9Sstevel@tonic-gate gettext("No TERM variable defined! Trouble with the Spooler!\n") 5497c478bd9Sstevel@tonic-gate ); 5507c478bd9Sstevel@tonic-gate exit (E_BAD_TERM); 5517c478bd9Sstevel@tonic-gate } 5527c478bd9Sstevel@tonic-gate if ( 5537c478bd9Sstevel@tonic-gate !STREQU(TERM, NAME_UNKNOWN) 5547c478bd9Sstevel@tonic-gate && tidbit(TERM, "cps", &print_rate) == -1 5557c478bd9Sstevel@tonic-gate ) { 5567c478bd9Sstevel@tonic-gate signal (SIGTERM, SIG_IGN); 5577c478bd9Sstevel@tonic-gate fprintf ( 5587c478bd9Sstevel@tonic-gate stderr, 5597c478bd9Sstevel@tonic-gate gettext("Trouble identifying printer type \"%s\"; check the Terminfo database.\n"), 5607c478bd9Sstevel@tonic-gate TERM 5617c478bd9Sstevel@tonic-gate ); 5627c478bd9Sstevel@tonic-gate exit (E_BAD_TERM); 5637c478bd9Sstevel@tonic-gate } 5647c478bd9Sstevel@tonic-gate if (STREQU(TERM, NAME_UNKNOWN)) 5657c478bd9Sstevel@tonic-gate print_rate = -1; 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate effective_rate = baudrate() / 10; /* okay for most bauds */ 5687c478bd9Sstevel@tonic-gate if (print_rate != -1 && print_rate < effective_rate) 5697c478bd9Sstevel@tonic-gate effective_rate = print_rate; 5707c478bd9Sstevel@tonic-gate if (argc > 1 && (n = atoi(argv[1])) >= 0 && n < effective_rate) 5717c478bd9Sstevel@tonic-gate effective_rate = n; /* 0 means infinite delay */ 5727c478bd9Sstevel@tonic-gate if (effective_rate) 5737c478bd9Sstevel@tonic-gate max_delay = DELAY(BUFSIZ, effective_rate); 5747c478bd9Sstevel@tonic-gate 5757c478bd9Sstevel@tonic-gate /* 5767c478bd9Sstevel@tonic-gate * We'll use the "alarm()" system call to keep us from 5777c478bd9Sstevel@tonic-gate * waiting too long to write to a printer in trouble. 5787c478bd9Sstevel@tonic-gate */ 5797c478bd9Sstevel@tonic-gate if (max_delay) 5807c478bd9Sstevel@tonic-gate signal (SIGALRM, sigalrm); 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate /* 5837c478bd9Sstevel@tonic-gate * While not end of standard input, copy blocks to 5847c478bd9Sstevel@tonic-gate * standard output. 5857c478bd9Sstevel@tonic-gate */ 5867c478bd9Sstevel@tonic-gate while ((nin = read(0, buffer, BUFSIZ)) > 0) { 5877c478bd9Sstevel@tonic-gate char *ptr = buffer; 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate /* 5907c478bd9Sstevel@tonic-gate * We should be safe from incomplete writes to a full 5917c478bd9Sstevel@tonic-gate * pipe, as long as the size of the buffer we write is 5927c478bd9Sstevel@tonic-gate * a even divisor of the pipe buffer limit. As long as 5937c478bd9Sstevel@tonic-gate * we read from files or pipes (not communication devices) 5947c478bd9Sstevel@tonic-gate * this should be true for all but the last buffer. The 5957c478bd9Sstevel@tonic-gate * last will be smaller, and won't straddle the pipe max 5967c478bd9Sstevel@tonic-gate * limit (think about it). 5977c478bd9Sstevel@tonic-gate */ 5987c478bd9Sstevel@tonic-gate #if PIPE_BUF < BUFSIZ || (PIPE_MAX % BUFSIZ) 5997c478bd9Sstevel@tonic-gate this_wont_compile; 6007c478bd9Sstevel@tonic-gate #endif 6017c478bd9Sstevel@tonic-gate if (report_rate) 6027c478bd9Sstevel@tonic-gate epoch_start = times(&tms); 6037c478bd9Sstevel@tonic-gate do { 6047c478bd9Sstevel@tonic-gate wait_state(1, func); 6057c478bd9Sstevel@tonic-gate 6067c478bd9Sstevel@tonic-gate if (max_delay) 6077c478bd9Sstevel@tonic-gate alarm (max_delay); 6087c478bd9Sstevel@tonic-gate nout = write(1, ptr, nin); 6097c478bd9Sstevel@tonic-gate alarm(0); 6107c478bd9Sstevel@tonic-gate if (nout < 0) { 6117c478bd9Sstevel@tonic-gate fprintf ( 6127c478bd9Sstevel@tonic-gate stderr, 6137c478bd9Sstevel@tonic-gate gettext("Write failed (%s);\nperhaps the printer has gone off-line.\n"), 6147c478bd9Sstevel@tonic-gate PERROR 6157c478bd9Sstevel@tonic-gate ); 6167c478bd9Sstevel@tonic-gate fflush(stderr); 6177c478bd9Sstevel@tonic-gate if (errno != EINTR) 6187c478bd9Sstevel@tonic-gate /* I/O error on device, get lpcshed to retry */ 6197c478bd9Sstevel@tonic-gate exit(PRINTER_IO_ERROR); 6207c478bd9Sstevel@tonic-gate else /* wait for printer to come back online */ 6217c478bd9Sstevel@tonic-gate sleep(15); 6227c478bd9Sstevel@tonic-gate } else { 6237c478bd9Sstevel@tonic-gate nin -= nout; 6247c478bd9Sstevel@tonic-gate ptr += nout; 6257c478bd9Sstevel@tonic-gate } 6267c478bd9Sstevel@tonic-gate } while (nin > 0); 6277c478bd9Sstevel@tonic-gate 6287c478bd9Sstevel@tonic-gate if (max_delay) 6297c478bd9Sstevel@tonic-gate alarm (0); 6307c478bd9Sstevel@tonic-gate else if (report_rate) { 6317c478bd9Sstevel@tonic-gate epoch_end = times(&tms); 6327c478bd9Sstevel@tonic-gate if (epoch_end - epoch_start > 0) 6337c478bd9Sstevel@tonic-gate fprintf ( 6347c478bd9Sstevel@tonic-gate stderr, 6357c478bd9Sstevel@tonic-gate "%d CPS\n", 6367c478bd9Sstevel@tonic-gate R((100 * BUFSIZ) / (double)(epoch_end - epoch_start)) 6377c478bd9Sstevel@tonic-gate ); 6387c478bd9Sstevel@tonic-gate } 6397c478bd9Sstevel@tonic-gate 6407c478bd9Sstevel@tonic-gate } 6417c478bd9Sstevel@tonic-gate 642*f928ce67Sceastha return (E_SUCCESS); 6437c478bd9Sstevel@tonic-gate } 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate /** 6467c478bd9Sstevel@tonic-gate ** sighup() - CATCH A HANGUP (LOSS OF CARRIER) 6477c478bd9Sstevel@tonic-gate **/ 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate void sighup () 6507c478bd9Sstevel@tonic-gate { 6517c478bd9Sstevel@tonic-gate signal (SIGTERM, SIG_IGN); 6527c478bd9Sstevel@tonic-gate signal (SIGHUP, SIG_IGN); 6537c478bd9Sstevel@tonic-gate fprintf (stderr, gettext(HANGUP_FAULT_LPCAT)); 6547c478bd9Sstevel@tonic-gate exit (E_HANGUP); 6557c478bd9Sstevel@tonic-gate } 6567c478bd9Sstevel@tonic-gate 6577c478bd9Sstevel@tonic-gate /** 6587c478bd9Sstevel@tonic-gate ** sigint() - CATCH AN INTERRUPT 6597c478bd9Sstevel@tonic-gate **/ 6607c478bd9Sstevel@tonic-gate 6617c478bd9Sstevel@tonic-gate void sigint () 6627c478bd9Sstevel@tonic-gate { 6637c478bd9Sstevel@tonic-gate signal (SIGTERM, SIG_IGN); 6647c478bd9Sstevel@tonic-gate signal (SIGINT, SIG_IGN); 6657c478bd9Sstevel@tonic-gate fprintf (stderr, gettext(INTERRUPT_FAULT)); 6667c478bd9Sstevel@tonic-gate exit (E_INTERRUPT); 6677c478bd9Sstevel@tonic-gate } 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate /** 6707c478bd9Sstevel@tonic-gate ** sigpipe() - CATCH EARLY CLOSE OF PIPE 6717c478bd9Sstevel@tonic-gate **/ 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate void sigpipe () 6747c478bd9Sstevel@tonic-gate { 6757c478bd9Sstevel@tonic-gate signal (SIGTERM, SIG_IGN); 6767c478bd9Sstevel@tonic-gate signal (SIGPIPE, SIG_IGN); 6777c478bd9Sstevel@tonic-gate fprintf (stderr, gettext(PIPE_FAULT)); 6787c478bd9Sstevel@tonic-gate exit (E_INTERRUPT); 6797c478bd9Sstevel@tonic-gate } 6807c478bd9Sstevel@tonic-gate 6817c478bd9Sstevel@tonic-gate /** 6827c478bd9Sstevel@tonic-gate ** sigalrm() - CATCH AN ALARM 6837c478bd9Sstevel@tonic-gate **/ 6847c478bd9Sstevel@tonic-gate 6857c478bd9Sstevel@tonic-gate void sigalrm () 6867c478bd9Sstevel@tonic-gate { 6877c478bd9Sstevel@tonic-gate signal (SIGTERM, SIG_IGN); 6887c478bd9Sstevel@tonic-gate fprintf ( 6897c478bd9Sstevel@tonic-gate stderr, 6907c478bd9Sstevel@tonic-gate gettext("Excessive write delay; perhaps the printer has gone off-line.\n") 6917c478bd9Sstevel@tonic-gate ); 6927c478bd9Sstevel@tonic-gate exit (E_TIMEOUT); 6937c478bd9Sstevel@tonic-gate } 6947c478bd9Sstevel@tonic-gate 6957c478bd9Sstevel@tonic-gate /** 6967c478bd9Sstevel@tonic-gate ** sigterm() - CATCH A TERMINATION SIGNAL 6977c478bd9Sstevel@tonic-gate **/ 6987c478bd9Sstevel@tonic-gate 6997c478bd9Sstevel@tonic-gate void sigterm () 7007c478bd9Sstevel@tonic-gate { 7017c478bd9Sstevel@tonic-gate signal (SIGTERM, SIG_IGN); 7027c478bd9Sstevel@tonic-gate /* 7037c478bd9Sstevel@tonic-gate * try to flush the output queue in the case of ecpp port. 7047c478bd9Sstevel@tonic-gate * ignore the return code as this may not be the ecpp. 7057c478bd9Sstevel@tonic-gate */ 7067c478bd9Sstevel@tonic-gate ioctl(1, I_FLUSH, FLUSHW); 7077c478bd9Sstevel@tonic-gate exit (E_SUCCESS); 7087c478bd9Sstevel@tonic-gate } 7097c478bd9Sstevel@tonic-gate 7107c478bd9Sstevel@tonic-gate /** 7117c478bd9Sstevel@tonic-gate ** baudrate() - RETURN BAUD RATE OF OUTPUT LINE 7127c478bd9Sstevel@tonic-gate **/ 7137c478bd9Sstevel@tonic-gate 7147c478bd9Sstevel@tonic-gate static int baud_convert[] = 7157c478bd9Sstevel@tonic-gate { 7167c478bd9Sstevel@tonic-gate 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200, 7177c478bd9Sstevel@tonic-gate 1800, 2400, 4800, 9600, 19200, 38400, 57600, 7187c478bd9Sstevel@tonic-gate 76800, 115200, 153600, 230400, 307200, 460800 7197c478bd9Sstevel@tonic-gate }; 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate int baudrate () 7227c478bd9Sstevel@tonic-gate { 7237c478bd9Sstevel@tonic-gate struct termio tm; 7247c478bd9Sstevel@tonic-gate struct termios tms; 7257c478bd9Sstevel@tonic-gate int speed; 7267c478bd9Sstevel@tonic-gate 7277c478bd9Sstevel@tonic-gate if (ioctl(1, TCGETS, &tms) < 0) { 7287c478bd9Sstevel@tonic-gate if (ioctl(1, TCGETA, &tm) < 0) 7297c478bd9Sstevel@tonic-gate return (1200); 7307c478bd9Sstevel@tonic-gate else 7317c478bd9Sstevel@tonic-gate speed = tm.c_cflag&CBAUD; 7327c478bd9Sstevel@tonic-gate } else 7337c478bd9Sstevel@tonic-gate speed = cfgetospeed(&tms); 7347c478bd9Sstevel@tonic-gate 7357c478bd9Sstevel@tonic-gate return (speed ? baud_convert[speed] : 1200); 7367c478bd9Sstevel@tonic-gate } 737