xref: /titanic_51/usr/src/cmd/lp/cmd/lpadmin/do_align.c (revision 437427fb0e9def2a846945f03aca7152a1438123)
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
5*437427fbSps29005  * Common Development and Distribution License (the "License").
6*437427fbSps29005  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
227c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
26*437427fbSps29005  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
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 <errno.h>
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <signal.h>
367c478bd9Sstevel@tonic-gate #include <setjmp.h>
377c478bd9Sstevel@tonic-gate #include <string.h>
387c478bd9Sstevel@tonic-gate #include <stdlib.h>
397c478bd9Sstevel@tonic-gate #include <libintl.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include "lp.h"
427c478bd9Sstevel@tonic-gate #include "msgs.h"
437c478bd9Sstevel@tonic-gate #include "printers.h"
447c478bd9Sstevel@tonic-gate #include "requests.h"
457c478bd9Sstevel@tonic-gate #include "form.h"
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #define	WHO_AM_I	I_AM_LPADMIN
487c478bd9Sstevel@tonic-gate #include "oam.h"
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #include "lpadmin.h"
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate extern void		mount_unmount();
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate extern short		printer_status;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate extern char		*cur_pwheel,
587c478bd9Sstevel@tonic-gate 			*disable_reason,
597c478bd9Sstevel@tonic-gate 			*reject_reason;
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate extern FORM		formbuf;
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate static int		again();
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate static void		disable(),
667c478bd9Sstevel@tonic-gate 			enable(),
677c478bd9Sstevel@tonic-gate 			accept(),
687c478bd9Sstevel@tonic-gate 			reject(),
697c478bd9Sstevel@tonic-gate 			cancel(),
707c478bd9Sstevel@tonic-gate 			sigpipe(),
717c478bd9Sstevel@tonic-gate 			sigother();
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate static jmp_buf		cleanup_env,
747c478bd9Sstevel@tonic-gate 			pipe_env;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate /**
777c478bd9Sstevel@tonic-gate  ** do_align() - SET UP PRINTER TO PRINT ALIGNMENT PATTERNS
787c478bd9Sstevel@tonic-gate  **/
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate int			do_align (printer, form, pwheel)
817c478bd9Sstevel@tonic-gate 	char			*printer,
827c478bd9Sstevel@tonic-gate 				*form,
837c478bd9Sstevel@tonic-gate 				*pwheel;
847c478bd9Sstevel@tonic-gate {
857c478bd9Sstevel@tonic-gate 	short			status;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	char			*req_id		= 0,
887c478bd9Sstevel@tonic-gate 				*file_prefix,
897c478bd9Sstevel@tonic-gate 				*rfile,
907c478bd9Sstevel@tonic-gate 				*fifo,
917c478bd9Sstevel@tonic-gate 				buffer[MSGMAX];
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	long			printer_chk;
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	int			try;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	FILE			*align_fp,
987c478bd9Sstevel@tonic-gate 				*fifo_fp;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	REQUEST			req;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	void			(*old_sighup)(),
1037c478bd9Sstevel@tonic-gate 				(*old_sigint)(),
1047c478bd9Sstevel@tonic-gate 				(*old_sigquit)(),
1057c478bd9Sstevel@tonic-gate 				(*old_sigterm)();
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 	/*
1097c478bd9Sstevel@tonic-gate 	 * Having reached this point means we've already fetched
1107c478bd9Sstevel@tonic-gate 	 * the form definition. Now get the alignment pattern.
1117c478bd9Sstevel@tonic-gate 	 */
1127c478bd9Sstevel@tonic-gate 	if (getform(form, (FORM *)0, (FALERT *)0, &align_fp) == -1) {
1137c478bd9Sstevel@tonic-gate 		LP_ERRMSG2 (ERROR, E_LP_GETFORM, form, PERROR);
1147c478bd9Sstevel@tonic-gate 		done (1);
1157c478bd9Sstevel@tonic-gate 	}
1167c478bd9Sstevel@tonic-gate 	if (!align_fp) {
1177c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (WARNING, E_ADM_NOALIGN, form);
1187c478bd9Sstevel@tonic-gate 		return (0);
1197c478bd9Sstevel@tonic-gate 	}
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	/*
1227c478bd9Sstevel@tonic-gate 	 * Having reached this far also means we've already obtained
1237c478bd9Sstevel@tonic-gate 	 * the printer status from the Spooler. We'll be changing the
1247c478bd9Sstevel@tonic-gate 	 * status of the printer and queue and will have to restore
1257c478bd9Sstevel@tonic-gate 	 * the disable/reject reasons.
1267c478bd9Sstevel@tonic-gate 	 * NOTE: We can't restore the dates!
1277c478bd9Sstevel@tonic-gate 	 */
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	/*
1317c478bd9Sstevel@tonic-gate 	 * Construct a request to print a ``file'' for copy. The
1327c478bd9Sstevel@tonic-gate 	 * equivalent "lp" command (with a filename) would be:
1337c478bd9Sstevel@tonic-gate 	 *
1347c478bd9Sstevel@tonic-gate 	 * lp -p printer -H immediate -f form -T type -S charset -c -P 1-N
1357c478bd9Sstevel@tonic-gate 	 *
1367c478bd9Sstevel@tonic-gate 	 * "type", "charset", and "N" are derived from the form def'n.
1377c478bd9Sstevel@tonic-gate 	 * This command would make us next to print ONCE THE FORM IS
1387c478bd9Sstevel@tonic-gate 	 * MOUNTED.
1397c478bd9Sstevel@tonic-gate 	 *
1407c478bd9Sstevel@tonic-gate 	 * NOTE: Don't bother with the -S charset if it isn't mandatory,
1417c478bd9Sstevel@tonic-gate 	 * so we won't get a rejection. Also, we use either the print
1427c478bd9Sstevel@tonic-gate 	 * wheel given in the -S option or, lacking that, the currently
1437c478bd9Sstevel@tonic-gate 	 * mounted print wheel. (The former WILL be mounted.) This also
1447c478bd9Sstevel@tonic-gate 	 * avoids a rejection by the Spooler.
1457c478bd9Sstevel@tonic-gate 	 */
1467c478bd9Sstevel@tonic-gate 	req.copies	= 1;
1477c478bd9Sstevel@tonic-gate 	req.destination	= printer;
1487c478bd9Sstevel@tonic-gate /*	req.file_list	= 0;	This is done later. */
1497c478bd9Sstevel@tonic-gate 	req.form	= form;
1507c478bd9Sstevel@tonic-gate 	req.actions	= ACT_IMMEDIATE | ACT_FAST;
1517c478bd9Sstevel@tonic-gate 	req.alert	= 0;
1527c478bd9Sstevel@tonic-gate 	req.options	= "nobanner";
1537c478bd9Sstevel@tonic-gate 	req.priority	= 20;	/* it doesn't matter */
1547c478bd9Sstevel@tonic-gate 	sprintf ((req.pages = "1-999999")+2, "%d", formbuf.np);
1557c478bd9Sstevel@tonic-gate 	req.charset	= NAME_ANY;	/* Don't restrict the request */
1567c478bd9Sstevel@tonic-gate 	req.modes	= 0;
1577c478bd9Sstevel@tonic-gate 	req.title	= "Aligning Form";
1587c478bd9Sstevel@tonic-gate 	req.input_type	= formbuf.conttype;
1597c478bd9Sstevel@tonic-gate 	req.user	= getname();
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	/*
1637c478bd9Sstevel@tonic-gate 	 * The following code is sensitive to interrupts: We must
1647c478bd9Sstevel@tonic-gate 	 * catch interrupts so to restore the printer to its original
1657c478bd9Sstevel@tonic-gate 	 * state, but if we get interrupted while receiving a message
1667c478bd9Sstevel@tonic-gate 	 * from the Spooler, we can't issue additional messages because
1677c478bd9Sstevel@tonic-gate 	 * the old responses still in the response queue will confuse us.
1687c478bd9Sstevel@tonic-gate 	 * Thus while sending/receiving a message we ignore signals.
1697c478bd9Sstevel@tonic-gate 	 */
1707c478bd9Sstevel@tonic-gate 	if (setjmp(cleanup_env) != 0)
1717c478bd9Sstevel@tonic-gate 		done (1);
1727c478bd9Sstevel@tonic-gate 	trap_signals (); /* make sure we've done this once */
1737c478bd9Sstevel@tonic-gate 	old_sighup = signal(SIGHUP, sigother);
1747c478bd9Sstevel@tonic-gate 	old_sigint = signal(SIGINT, sigother);
1757c478bd9Sstevel@tonic-gate 	old_sigquit = signal(SIGQUIT, sigother);
1767c478bd9Sstevel@tonic-gate 	old_sigterm = signal(SIGTERM, sigother);
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 	/*
1797c478bd9Sstevel@tonic-gate 	 * We'll try the following twice, first with the page list
1807c478bd9Sstevel@tonic-gate 	 * set as above. If the request gets refused because there's
1817c478bd9Sstevel@tonic-gate 	 * no filter to convert the content, we'll try again without
1827c478bd9Sstevel@tonic-gate 	 * the page list. I don't think the number-of-pages-in-a-form
1837c478bd9Sstevel@tonic-gate 	 * feature is likely to be used much, so why hassle the
1847c478bd9Sstevel@tonic-gate 	 * administrator?
1857c478bd9Sstevel@tonic-gate #if	defined(WARN_OF_TOO_MANY_LINES)
1867c478bd9Sstevel@tonic-gate 	 * However, do warn him or her.
1877c478bd9Sstevel@tonic-gate #endif
1887c478bd9Sstevel@tonic-gate 	 */
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	try = 0;
1917c478bd9Sstevel@tonic-gate Again:	try++;
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	/*
1947c478bd9Sstevel@tonic-gate 	 * Have the Spooler allocate a request file and another file
1957c478bd9Sstevel@tonic-gate 	 * for our use. We'll delete the other file and recreate it
1967c478bd9Sstevel@tonic-gate 	 * as a FIFO. We can do this because "lpadmin" can only be run
1977c478bd9Sstevel@tonic-gate 	 * (successfully) by an administrator. This is the key to what
1987c478bd9Sstevel@tonic-gate 	 * we're doing! We are submitting a named pipe (FIFO) for
1997c478bd9Sstevel@tonic-gate 	 * printing, which gives us a connection to the printer
2007c478bd9Sstevel@tonic-gate 	 * through any filters needed!
2017c478bd9Sstevel@tonic-gate 	 */
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	BEGIN_CRITICAL
2047c478bd9Sstevel@tonic-gate 		send_message (S_ALLOC_FILES, 2);
2057c478bd9Sstevel@tonic-gate 		if (mrecv(buffer, MSGMAX) != R_ALLOC_FILES) {
2067c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_LP_MRECV);
2077c478bd9Sstevel@tonic-gate 			done (1);
2087c478bd9Sstevel@tonic-gate 		}
2097c478bd9Sstevel@tonic-gate 	END_CRITICAL
2107c478bd9Sstevel@tonic-gate 	(void)getmessage (buffer, R_ALLOC_FILES, &status, &file_prefix);
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	switch (status) {
2137c478bd9Sstevel@tonic-gate 	case MOK:
2147c478bd9Sstevel@tonic-gate 		break;
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	case MNOMEM:
2177c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_LP_MNOMEM);
2187c478bd9Sstevel@tonic-gate 		done (1);
2197c478bd9Sstevel@tonic-gate 	}
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	if (!(rfile = malloc((unsigned int)strlen(file_prefix) + 2 + 1))) {
2227c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_LP_MALLOC);
2237c478bd9Sstevel@tonic-gate 		done (1);
2247c478bd9Sstevel@tonic-gate 	}
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 	sprintf (rfile, "%s-1", file_prefix);
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 	if (!(fifo = makepath(Lp_Temp, rfile, (char *)0))) {
2297c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_LP_MALLOC);
2307c478bd9Sstevel@tonic-gate 		done (1);
2317c478bd9Sstevel@tonic-gate 	}
2327c478bd9Sstevel@tonic-gate 	req.file_list = 0;
2337c478bd9Sstevel@tonic-gate 	addlist (&req.file_list, fifo);
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 	if (
2367c478bd9Sstevel@tonic-gate 		Unlink(fifo) == -1
2377c478bd9Sstevel@tonic-gate 	     || Mknod(fifo, S_IFIFO | 0600, 0) == -1
2387c478bd9Sstevel@tonic-gate 	) {
2397c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_ADM_NFIFO, PERROR);
2407c478bd9Sstevel@tonic-gate 		done (1);
2417c478bd9Sstevel@tonic-gate 	}
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	/*
2447c478bd9Sstevel@tonic-gate 	 * In quick succession,
2457c478bd9Sstevel@tonic-gate 	 *
2467c478bd9Sstevel@tonic-gate 	 *	- mount the form,
2477c478bd9Sstevel@tonic-gate 	 *	- disable the printer,
2487c478bd9Sstevel@tonic-gate 	 *	- make the Spooler accept requests (if need be),
2497c478bd9Sstevel@tonic-gate 	 *	- submit the request,
2507c478bd9Sstevel@tonic-gate 	 *	- make the Spooler reject requests (if need be).
2517c478bd9Sstevel@tonic-gate 	 *
2527c478bd9Sstevel@tonic-gate 	 * We want to minimize the window when another request can
2537c478bd9Sstevel@tonic-gate 	 * be submitted ahead of ours. Though this window is small,
2547c478bd9Sstevel@tonic-gate 	 * it is a flaw in our design. Disabling the printer will
2557c478bd9Sstevel@tonic-gate 	 * help, because it will stop any request that is printing
2567c478bd9Sstevel@tonic-gate 	 * (if the form is already mounted) and will prevent any other
2577c478bd9Sstevel@tonic-gate 	 * request from printing. (We disable the printer AFTER trying
2587c478bd9Sstevel@tonic-gate 	 * to mount the form, because we don't disable a printer for a
2597c478bd9Sstevel@tonic-gate 	 * regular mount, and we'd like to make this mount APPEAR to
2607c478bd9Sstevel@tonic-gate 	 * be as similar as possible.)
2617c478bd9Sstevel@tonic-gate 	 */
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	if (try == 1) {
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate 		mount_unmount (S_MOUNT, printer, NB(form), NB(pwheel));
2667c478bd9Sstevel@tonic-gate 		/* This will die if the mount fails, leaving */
2677c478bd9Sstevel@tonic-gate 		/* the Spooler to clean up our files.        */
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 		if (!(printer_status & PS_DISABLED))
2707c478bd9Sstevel@tonic-gate 			disable (printer, CUZ_MOUNTING, 0);
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 		if (printer_status & PS_REJECTED)
2737c478bd9Sstevel@tonic-gate 			accept (printer);
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 		if (setjmp(cleanup_env) != 0) {
2767c478bd9Sstevel@tonic-gate 			if (printer_status & PS_DISABLED)
2777c478bd9Sstevel@tonic-gate 				disable (printer, disable_reason, 1);
2787c478bd9Sstevel@tonic-gate 			if (printer_status & PS_REJECTED)
2797c478bd9Sstevel@tonic-gate 				reject (printer, reject_reason);
2807c478bd9Sstevel@tonic-gate 			if (req_id && *req_id)
2817c478bd9Sstevel@tonic-gate 				cancel (req_id);
2827c478bd9Sstevel@tonic-gate 			done (1);
2837c478bd9Sstevel@tonic-gate 		}
2847c478bd9Sstevel@tonic-gate 	}
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	sprintf (rfile, "%s-0", file_prefix);
2877c478bd9Sstevel@tonic-gate 	if (putrequest(rfile, &req) == -1) {
2887c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_LP_PUTREQUEST, PERROR);
2897c478bd9Sstevel@tonic-gate 		goto Done;
2907c478bd9Sstevel@tonic-gate 	}
2917c478bd9Sstevel@tonic-gate 	BEGIN_CRITICAL
2927c478bd9Sstevel@tonic-gate 		send_message (S_PRINT_REQUEST, rfile);
2937c478bd9Sstevel@tonic-gate 		if (mrecv(buffer, MSGMAX) != R_PRINT_REQUEST) {
2947c478bd9Sstevel@tonic-gate 			LP_ERRMSG (ERROR, E_LP_MRECV);
2957c478bd9Sstevel@tonic-gate 			done (1);
2967c478bd9Sstevel@tonic-gate 		}
2977c478bd9Sstevel@tonic-gate 	END_CRITICAL
2987c478bd9Sstevel@tonic-gate 	(void)getmessage (buffer, R_PRINT_REQUEST, &status, &req_id, &printer_chk);
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 	switch (status) {
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	case MNOFILTER:
3037c478bd9Sstevel@tonic-gate 		if (try == 1) {
3047c478bd9Sstevel@tonic-gate 			req.pages = 0;
3057c478bd9Sstevel@tonic-gate 			goto Again;
3067c478bd9Sstevel@tonic-gate 		}
3077c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_ADM_NFILTER);
3087c478bd9Sstevel@tonic-gate 		goto Done;
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	case MOK:
3117c478bd9Sstevel@tonic-gate #if	defined(WARN_OF_TOO_MANY_LINES)
3127c478bd9Sstevel@tonic-gate 		if (!req.pages)
3137c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (WARNING, E_ADM_NPAGES, formbuf.np);
3147c478bd9Sstevel@tonic-gate #endif
3157c478bd9Sstevel@tonic-gate 		break;
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 	case MERRDEST:
3187c478bd9Sstevel@tonic-gate 		accept (printer); /* someone snuck a reject in! */
3197c478bd9Sstevel@tonic-gate 		goto Again;
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	case MNOMEM:
3227c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_LP_MNOMEM);
3237c478bd9Sstevel@tonic-gate 		goto Done;
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 	case MNODEST:
3267c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_LP_PGONE, printer);
3277c478bd9Sstevel@tonic-gate 		goto Done;
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 	case MNOOPEN:	/* not quite, but close */
3307c478bd9Sstevel@tonic-gate 		LP_ERRMSG (ERROR, E_ADM_ERRDEST);
3317c478bd9Sstevel@tonic-gate 		goto Done;
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	case MDENYDEST:
3347c478bd9Sstevel@tonic-gate 		if (printer_chk) {
3357c478bd9Sstevel@tonic-gate 			char			reason[1024],
3367c478bd9Sstevel@tonic-gate 						*cp	= reason;
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 			if (printer_chk & PCK_TYPE)
3397c478bd9Sstevel@tonic-gate 				cp += sprintf(cp, "printer type, ");
3407c478bd9Sstevel@tonic-gate 			if (printer_chk & PCK_CHARSET)
3417c478bd9Sstevel@tonic-gate 				cp += sprintf(cp, "character set, ");
3427c478bd9Sstevel@tonic-gate 			if (printer_chk & PCK_CPI)
3437c478bd9Sstevel@tonic-gate 				cp += sprintf(cp, "character pitch, ");
3447c478bd9Sstevel@tonic-gate 			if (printer_chk & PCK_LPI)
3457c478bd9Sstevel@tonic-gate 				cp += sprintf(cp, "line pitch, ");
3467c478bd9Sstevel@tonic-gate 			if (printer_chk & PCK_WIDTH)
3477c478bd9Sstevel@tonic-gate 				cp += sprintf(cp, "page width, ");
3487c478bd9Sstevel@tonic-gate 			if (printer_chk & PCK_LENGTH)
3497c478bd9Sstevel@tonic-gate 				cp += sprintf(cp, "page length, ");
3507c478bd9Sstevel@tonic-gate 			if (printer_chk & PCK_BANNER)
3517c478bd9Sstevel@tonic-gate 				cp += sprintf(cp, "nobanner, ");
3527c478bd9Sstevel@tonic-gate 			cp[-2] = 0;
3537c478bd9Sstevel@tonic-gate 			LP_ERRMSG1 (ERROR, E_LP_PTRCHK, reason);
3547c478bd9Sstevel@tonic-gate 			goto Done;
3557c478bd9Sstevel@tonic-gate 		}
3567c478bd9Sstevel@tonic-gate 		/*fall through*/
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate 	case MUNKNOWN:
3597c478bd9Sstevel@tonic-gate 	case MNOMEDIA:
3607c478bd9Sstevel@tonic-gate 	case MDENYMEDIA:
3617c478bd9Sstevel@tonic-gate 	case MNOMOUNT:
3627c478bd9Sstevel@tonic-gate 	case MNOSPACE:
3637c478bd9Sstevel@tonic-gate 	case MNOPERM:
3647c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, status);
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate Done:		if (!(printer_status & PS_DISABLED))
3677c478bd9Sstevel@tonic-gate 			enable (printer);
3687c478bd9Sstevel@tonic-gate 		if (printer_status & PS_REJECTED)
3697c478bd9Sstevel@tonic-gate 			reject (printer, reject_reason);
3707c478bd9Sstevel@tonic-gate 		done (1);
3717c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
3727c478bd9Sstevel@tonic-gate 	}
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 	if (printer_status & PS_REJECTED)
3757c478bd9Sstevel@tonic-gate 		reject (printer, reject_reason);
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate 	/*
3787c478bd9Sstevel@tonic-gate 	 * Enable printing, to start the interface program going.
3797c478bd9Sstevel@tonic-gate 	 * Because of our precautions above, our request SHOULD be
3807c478bd9Sstevel@tonic-gate 	 * the one that prints!
3817c478bd9Sstevel@tonic-gate  	 */
3827c478bd9Sstevel@tonic-gate 	enable (printer);
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 	/*
3857c478bd9Sstevel@tonic-gate 	 * Open the FIFO. One problem: This will hang until the
3867c478bd9Sstevel@tonic-gate 	 * interface program opens the other end!!
3877c478bd9Sstevel@tonic-gate 	 */
3887c478bd9Sstevel@tonic-gate 	if (!(fifo_fp = fopen(fifo, "w"))) {
3897c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_ADM_NFIFO, PERROR);
3907c478bd9Sstevel@tonic-gate 		done (1);
3917c478bd9Sstevel@tonic-gate 	}
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate 	/*
3947c478bd9Sstevel@tonic-gate 	 * Loop, dumping the ENTIRE alignment pattern to the FIFO
3957c478bd9Sstevel@tonic-gate 	 * each time. SIGPIPE probably means the printer faulted.
3967c478bd9Sstevel@tonic-gate 	 */
3977c478bd9Sstevel@tonic-gate 	if (setjmp(pipe_env) == 0) {
3987c478bd9Sstevel@tonic-gate 		/*
3997c478bd9Sstevel@tonic-gate 		 * Don't send a form feed after the last copy, since
4007c478bd9Sstevel@tonic-gate 		 * the interface program does that. To implement this,
4017c478bd9Sstevel@tonic-gate 		 * we send the form feed BEFORE the alignment pattern;
4027c478bd9Sstevel@tonic-gate 		 * this way we can simply not send it the first time.
4037c478bd9Sstevel@tonic-gate 		 */
4047c478bd9Sstevel@tonic-gate 		char *			ff		= 0;
4057c478bd9Sstevel@tonic-gate 		char *			ff_before	= 0;
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate 		/*
4087c478bd9Sstevel@tonic-gate 		 * If we'll be inserting page breaks between alignment
4097c478bd9Sstevel@tonic-gate 		 * patterns, look up the control sequence for this.
4107c478bd9Sstevel@tonic-gate 		 *
4117c478bd9Sstevel@tonic-gate 		 * MORE: We currently don't have the smarts to figure out
4127c478bd9Sstevel@tonic-gate 		 * WHICH printer type the Spooler will pick; we would need
4137c478bd9Sstevel@tonic-gate 		 * to steal some of its code for that (see pickfilter.c)
4147c478bd9Sstevel@tonic-gate 		 * The best we do so far is use the alignment pattern's
4157c478bd9Sstevel@tonic-gate 		 * content type, if known.
4167c478bd9Sstevel@tonic-gate 		 */
4177c478bd9Sstevel@tonic-gate 		if (filebreak) {
4187c478bd9Sstevel@tonic-gate 			if (
4197c478bd9Sstevel@tonic-gate 				formbuf.conttype
4207c478bd9Sstevel@tonic-gate 			     && searchlist_with_terminfo(
4217c478bd9Sstevel@tonic-gate 					formbuf.conttype,
4227c478bd9Sstevel@tonic-gate 					T  /* having "filebreak" => OK */
4237c478bd9Sstevel@tonic-gate 				)
4247c478bd9Sstevel@tonic-gate 			)
4257c478bd9Sstevel@tonic-gate 				tidbit (formbuf.conttype, "ff", &ff);
4267c478bd9Sstevel@tonic-gate 			else
4277c478bd9Sstevel@tonic-gate 				tidbit (*T, "ff", &ff);
4287c478bd9Sstevel@tonic-gate 		}
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 		signal (SIGPIPE, sigpipe);
4317c478bd9Sstevel@tonic-gate 		do {
4327c478bd9Sstevel@tonic-gate 			register int		n;
4337c478bd9Sstevel@tonic-gate 			char			buf[BUFSIZ];
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate 			if (ff_before && *ff_before)
4367c478bd9Sstevel@tonic-gate 				fputs (ff_before, fifo_fp);
4377c478bd9Sstevel@tonic-gate 			ff_before = ff;
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate 			rewind (align_fp);
4407c478bd9Sstevel@tonic-gate 			while ((n = fread(buf, 1, BUFSIZ, align_fp)) > 0)
4417c478bd9Sstevel@tonic-gate 				fwrite (buf, 1, n, fifo_fp);
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 			fflush (fifo_fp);
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate 		} while (again());
4467c478bd9Sstevel@tonic-gate 		fclose (align_fp);
4477c478bd9Sstevel@tonic-gate 		signal (SIGPIPE, SIG_DFL);
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate 	} else {
4507c478bd9Sstevel@tonic-gate 		cancel (req_id);
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate #define P(X)	printf (X)
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate P("We were interrupted while printing the alignment pattern;\n");
4557c478bd9Sstevel@tonic-gate P("check the printer. The form is mounted, so you will have to\n");
4567c478bd9Sstevel@tonic-gate P("unmount it if you need to print more alignment patterns later.\n");
4577c478bd9Sstevel@tonic-gate 	}
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate 	/*
4607c478bd9Sstevel@tonic-gate 	 * Disable the printer, if needed, and close the FIFO.
4617c478bd9Sstevel@tonic-gate 	 * Use the wait version of the disable, so our request isn't
4627c478bd9Sstevel@tonic-gate 	 * stopped, and do it before closing the FIFO, so another request
4637c478bd9Sstevel@tonic-gate 	 * can't start printing if it isn't supposed to.
4647c478bd9Sstevel@tonic-gate 	 */
4657c478bd9Sstevel@tonic-gate 	if (printer_status & PS_DISABLED)
4667c478bd9Sstevel@tonic-gate 		disable (printer, disable_reason, 1);
4677c478bd9Sstevel@tonic-gate 	fclose (fifo_fp);
4687c478bd9Sstevel@tonic-gate 
4697c478bd9Sstevel@tonic-gate 	signal (SIGHUP, old_sighup);
4707c478bd9Sstevel@tonic-gate 	signal (SIGINT, old_sigint);
4717c478bd9Sstevel@tonic-gate 	signal (SIGQUIT, old_sigquit);
4727c478bd9Sstevel@tonic-gate 	signal (SIGTERM, old_sigterm);
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate 	return (1);
4757c478bd9Sstevel@tonic-gate }
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate /**
4787c478bd9Sstevel@tonic-gate  ** accept() - MAKE PRINTER ACCEPT REQUESTS
4797c478bd9Sstevel@tonic-gate  **/
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate static void		accept (printer)
4827c478bd9Sstevel@tonic-gate 	char			*printer;
4837c478bd9Sstevel@tonic-gate {
4847c478bd9Sstevel@tonic-gate 	int			rc;
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate 	BEGIN_CRITICAL
4877c478bd9Sstevel@tonic-gate 		send_message (S_ACCEPT_DEST, printer);
4887c478bd9Sstevel@tonic-gate 		rc = output(R_ACCEPT_DEST);
4897c478bd9Sstevel@tonic-gate 	END_CRITICAL
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate 	switch (rc) {
4927c478bd9Sstevel@tonic-gate 	case MOK:
4937c478bd9Sstevel@tonic-gate 	case MERRDEST:	/* someone may have snuck in an accept */
4947c478bd9Sstevel@tonic-gate 		break;
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate 	case MNODEST:	/* make up your mind, Spooler! */
4977c478bd9Sstevel@tonic-gate 	case MNOPERM:	/* taken care of up front */
4987c478bd9Sstevel@tonic-gate 	default:
4997c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
5007c478bd9Sstevel@tonic-gate 		done (1);
5017c478bd9Sstevel@tonic-gate 	}
5027c478bd9Sstevel@tonic-gate 	return;
5037c478bd9Sstevel@tonic-gate }
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate /**
5067c478bd9Sstevel@tonic-gate  ** reject() - MAKE PRINTER REJECT REQUESTS
5077c478bd9Sstevel@tonic-gate  **/
5087c478bd9Sstevel@tonic-gate 
5097c478bd9Sstevel@tonic-gate static void		reject (printer, reason)
5107c478bd9Sstevel@tonic-gate 	char			*printer,
5117c478bd9Sstevel@tonic-gate 				*reason;
5127c478bd9Sstevel@tonic-gate {
5137c478bd9Sstevel@tonic-gate 	int			rc;
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate 	BEGIN_CRITICAL
5167c478bd9Sstevel@tonic-gate 		send_message (S_REJECT_DEST, printer, reason);
5177c478bd9Sstevel@tonic-gate 		rc = output(R_REJECT_DEST);
5187c478bd9Sstevel@tonic-gate 	END_CRITICAL
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate 	switch (rc) {
5217c478bd9Sstevel@tonic-gate 
5227c478bd9Sstevel@tonic-gate 	case MOK:
5237c478bd9Sstevel@tonic-gate 	case MERRDEST:	/* someone may have snuck in a reject */
5247c478bd9Sstevel@tonic-gate 		break;
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 	case MNODEST:	/* make up your mind, Spooler! */
5277c478bd9Sstevel@tonic-gate 	case MNOPERM:	/* taken care of up front */
5287c478bd9Sstevel@tonic-gate 	default:
5297c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
5307c478bd9Sstevel@tonic-gate 		done (1);
5317c478bd9Sstevel@tonic-gate 	}
5327c478bd9Sstevel@tonic-gate 	return;
5337c478bd9Sstevel@tonic-gate }
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate /**
5367c478bd9Sstevel@tonic-gate  ** enable() - ENABLE THE PRINTER
5377c478bd9Sstevel@tonic-gate  **/
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate static void		enable (printer)
5407c478bd9Sstevel@tonic-gate 	char			*printer;
5417c478bd9Sstevel@tonic-gate {
5427c478bd9Sstevel@tonic-gate 	int			rc;
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate 	BEGIN_CRITICAL
5457c478bd9Sstevel@tonic-gate 		send_message (S_ENABLE_DEST, printer);
5467c478bd9Sstevel@tonic-gate 		rc = output(R_ENABLE_DEST);
5477c478bd9Sstevel@tonic-gate 	END_CRITICAL
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 	switch (rc) {
5507c478bd9Sstevel@tonic-gate 	case MOK:
5517c478bd9Sstevel@tonic-gate 	case MERRDEST:	/* someone may have snuck in an enable */
5527c478bd9Sstevel@tonic-gate 		break;
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate 	case MNODEST:	/* make up your mind, Spooler! */
5557c478bd9Sstevel@tonic-gate 	case MNOPERM:	/* taken care of up front */
5567c478bd9Sstevel@tonic-gate 	default:
5577c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
5587c478bd9Sstevel@tonic-gate 		done (1);
5597c478bd9Sstevel@tonic-gate 	}
5607c478bd9Sstevel@tonic-gate 	return;
5617c478bd9Sstevel@tonic-gate }
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate /**
5647c478bd9Sstevel@tonic-gate  ** disable() - DISABLE THE PRINTER
5657c478bd9Sstevel@tonic-gate  **/
5667c478bd9Sstevel@tonic-gate 
5677c478bd9Sstevel@tonic-gate static void		disable (printer, reason, when)
5687c478bd9Sstevel@tonic-gate 	char			*printer,
5697c478bd9Sstevel@tonic-gate 				*reason;
5707c478bd9Sstevel@tonic-gate 	int			when;
5717c478bd9Sstevel@tonic-gate {
5727c478bd9Sstevel@tonic-gate 	int			rc;
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate 	BEGIN_CRITICAL
5757c478bd9Sstevel@tonic-gate 		send_message (S_DISABLE_DEST, printer, reason, when);
5767c478bd9Sstevel@tonic-gate 		rc = output(R_DISABLE_DEST);
5777c478bd9Sstevel@tonic-gate 	END_CRITICAL
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate 	switch (rc) {
5807c478bd9Sstevel@tonic-gate 	case MOK:
5817c478bd9Sstevel@tonic-gate 	case MERRDEST:	/* someone may have snuck in a disable */
5827c478bd9Sstevel@tonic-gate 		break;
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate 	case MNODEST:	/* make up your mind, Spooler! */
5857c478bd9Sstevel@tonic-gate 	case MNOPERM:	/* taken care of up front */
5867c478bd9Sstevel@tonic-gate 	default:
5877c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
5887c478bd9Sstevel@tonic-gate 		done (1);
5897c478bd9Sstevel@tonic-gate 	}
5907c478bd9Sstevel@tonic-gate 	return;
5917c478bd9Sstevel@tonic-gate }
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate /**
5947c478bd9Sstevel@tonic-gate  ** cancel() - MAKE PRINTER ACCEPT REQUESTS
5957c478bd9Sstevel@tonic-gate  **/
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate static void		cancel (req_id)
5987c478bd9Sstevel@tonic-gate 	char			*req_id;
5997c478bd9Sstevel@tonic-gate {
6007c478bd9Sstevel@tonic-gate 	int			rc;
6017c478bd9Sstevel@tonic-gate 
6027c478bd9Sstevel@tonic-gate 	BEGIN_CRITICAL
6037c478bd9Sstevel@tonic-gate 		send_message (S_CANCEL_REQUEST, req_id);
6047c478bd9Sstevel@tonic-gate 		rc = output(R_CANCEL_REQUEST);
6057c478bd9Sstevel@tonic-gate 	END_CRITICAL
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate 	switch (rc) {
6087c478bd9Sstevel@tonic-gate 	case MOK:
6097c478bd9Sstevel@tonic-gate 	case MUNKNOWN:
6107c478bd9Sstevel@tonic-gate 	case M2LATE:
6117c478bd9Sstevel@tonic-gate 		break;
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate 	case MNOPERM:
6147c478bd9Sstevel@tonic-gate 	default:
6157c478bd9Sstevel@tonic-gate 		LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, rc);
6167c478bd9Sstevel@tonic-gate 		done (1);
6177c478bd9Sstevel@tonic-gate 	}
6187c478bd9Sstevel@tonic-gate 	return;
6197c478bd9Sstevel@tonic-gate }
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate /**
6227c478bd9Sstevel@tonic-gate  ** again()
6237c478bd9Sstevel@tonic-gate  **/
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate static int		again ()
6267c478bd9Sstevel@tonic-gate {
6277c478bd9Sstevel@tonic-gate 	char			answer[BUFSIZ];
6287c478bd9Sstevel@tonic-gate 
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate 	for (;;) {
6317c478bd9Sstevel@tonic-gate 
6327c478bd9Sstevel@tonic-gate 		printf (
6337c478bd9Sstevel@tonic-gate 		gettext("Press return to print an alignment pattern [q to quit]: ")
6347c478bd9Sstevel@tonic-gate 		);
6357c478bd9Sstevel@tonic-gate 
636*437427fbSps29005 		if (!fgets(answer, sizeof (answer), stdin))
637*437427fbSps29005 			return (0);
638*437427fbSps29005 
639*437427fbSps29005 		answer[strlen(answer) -1] = '\0';
640*437427fbSps29005 
6417c478bd9Sstevel@tonic-gate 		if (
642*437427fbSps29005 		        STREQU(answer, "q")
6437c478bd9Sstevel@tonic-gate 		     || STREQU(answer, "n")
6447c478bd9Sstevel@tonic-gate 		     || STREQU(answer, "no")
6457c478bd9Sstevel@tonic-gate 		)
6467c478bd9Sstevel@tonic-gate 			return (0);
6477c478bd9Sstevel@tonic-gate 
6487c478bd9Sstevel@tonic-gate 		else if (
6497c478bd9Sstevel@tonic-gate 			!*answer
6507c478bd9Sstevel@tonic-gate 		     || STREQU(answer, "y")
6517c478bd9Sstevel@tonic-gate 		     || STREQU(answer, "yes")
6527c478bd9Sstevel@tonic-gate 		)
6537c478bd9Sstevel@tonic-gate 			return (1);
6547c478bd9Sstevel@tonic-gate 
6557c478bd9Sstevel@tonic-gate 		printf (gettext("Sorry?\n"));
6567c478bd9Sstevel@tonic-gate 	}
6577c478bd9Sstevel@tonic-gate }
6587c478bd9Sstevel@tonic-gate 
6597c478bd9Sstevel@tonic-gate /**
6607c478bd9Sstevel@tonic-gate  ** sigpipe()
6617c478bd9Sstevel@tonic-gate  ** sigother()
6627c478bd9Sstevel@tonic-gate  **/
6637c478bd9Sstevel@tonic-gate 
6647c478bd9Sstevel@tonic-gate static void		sigpipe ()
6657c478bd9Sstevel@tonic-gate {
6667c478bd9Sstevel@tonic-gate 	signal (SIGPIPE, SIG_IGN);
6677c478bd9Sstevel@tonic-gate 	longjmp (pipe_env, 1);
6687c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
6697c478bd9Sstevel@tonic-gate }
6707c478bd9Sstevel@tonic-gate 
6717c478bd9Sstevel@tonic-gate static void		sigother (sig)
6727c478bd9Sstevel@tonic-gate 	int			sig;
6737c478bd9Sstevel@tonic-gate {
6747c478bd9Sstevel@tonic-gate 	signal (sig, SIG_IGN);
6757c478bd9Sstevel@tonic-gate 	longjmp (cleanup_env, 1);
6767c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
6777c478bd9Sstevel@tonic-gate }
678