usr.sbin/lpr/lpd/printjob.c
/*
 * Acquire line printer or remote connection.
 */
Acquire line printer or remote connection.
Acquire line printer or remote connection .
static void
openpr()
{
	register int i;
	char *cp;
	if (!remote && *LP) {
		if (cp = index(LP, '@'))
			opennet(cp);
		else
			opentty();
	} else if (remote) {
		openrem();
	} else {
		syslog(LOG_ERR, "%s: no line printer device or host name",
			printer);
		exit(1);
	}
	if (!remote && OF) {
		int p[2];
		pipe(p);
		if ((ofilter = dofork(DOABORT)) == 0) {	
			dup2(p[0], 0);		
			dup2(pfd, 1);		
			closelog();
			for (i = 3; i < NOFILE; i++)
				(void) close(i);
			if ((cp = rindex(OF, '/')) == NULL)
				cp = OF;
			else
				cp++;
			execl(OF, cp, width, length, 0);
			syslog(LOG_ERR, "%s: %s: %m", printer, OF);
			exit(1);
		}
		(void) close(p[0]);		
		ofd = p[1];			
	} else {
		ofd = pfd;
		ofilter = 0;
	}
}
static void openpr ( ) { register int i ; char * cp ; if ( ! remote && * LP ) { if ( cp = index ( LP , ' ' ) ) opennet ( cp ) ; else opentty ( ) ; } else if ( remote ) { openrem ( ) ; } else { syslog ( LOG_ERR , " " , printer ) ; exit ( 1 ) ; } if ( ! remote && OF ) { int p [ 2 ] ; pipe ( p ) ; if ( ( ofilter = dofork ( DOABORT ) ) == 0 ) { dup2 ( p [ 0 ] , 0 ) ; dup2 ( pfd , 1 ) ; closelog ( ) ; for ( i = 3 ; i < NOFILE ; i ++ ) ( void ) close ( i ) ; if ( ( cp = rindex ( OF , ' ' ) ) == NULL ) cp = OF ; else cp ++ ; execl ( OF , cp , width , length , 0 ) ; syslog ( LOG_ERR , " " , printer , OF ) ; exit ( 1 ) ; } ( void ) close ( p [ 0 ] ) ; ofd = p [ 1 ] ; } else { ofd = pfd ; ofilter = 0 ; } }
Acquire line printer or remote connection.
Acquire line printer or remote connection .
/*
	 * Start up an output filter, if needed.
	 */ /* child */ /* pipe is std in */ /* printer is std out */ /* close input side */ /* use pipe for output */