Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Oct 2000 17:04:40 -0700 (PDT)
From:      Ed Alley <alley1@llnl.gov>
To:        freebsd-questions@freebsd.org
Cc:        Ed Alley <wea@trevarno.llnl.gov>
Subject:   FreeBSD hangs when running ghostscripe as a print filter.
Message-ID:  <Pine.BSF.4.10.10010271656010.395-300000@trevarno.llnl.gov>

next in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]

Hello:
	My name is Ed Alley. I am running FreeBSD 3.3 on my home
computer. I have sent you two attachments: my printcap file
and a simplified version of the printer filter that I am running.

Whenever I output a large Postscript file, it appears that
Ghostscript takes all of the CPU ticks; it holds on and won't
release the CPU. While I wait for it to finish, my X-window
pointer freezes and sometimes the system freezes permanently;
I have even had it panic on me with a page fault.

Do you have any idea what is going on? I should note that
the very same setup with Linux runs OK. (:-<)

	I am anxious to hear from you on this one; I have
been battling this one for months.

		Ed Alley
		wea@llnl.gov


[-- Attachment #2 --]
#
# Copyright (c) 1983 Regents of the University of California.
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that this notice is preserved and that due credit is given
# to the University of California at Berkeley. The name of the University
# may not be used to endorse or promote products derived from this
# software without specific prior written permission. This software
# is provided ``as is'' without express or implied warranty.
#
#	@(#)etc.printcap	5.2 (Berkeley) 5/5/88
#
lp|HP Laserjet 5P entry:\
        :lp=/dev/lpt0:\
        :sd=/var/spool/output/lp1:\
        :lf=/var/log/lpd_errs:\
        :lo=/var/spool/output/lp1/lock:\
        :if=/usr/local/libexec/lpr/lp.if:\
        :af=/var/account/lp1.acct:\
        :pc#100:pl#66:pw#80:\
        :mx#0:sh:sf

[-- Attachment #3 --]
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

/*
This printer filter turns my printer into a Postscript printer.
It does this by looking for the beginning string sequence "%!"
in stdin then rewinding by doing lseek to the beginning. If it
finds the test string it pipes stdin into ghostscript otherwise
it pipes stdin into cat.
*/

int write_b (int,char*,int);

main()
{
  char cc[3];
  int c;
  int fds[2];

  if ((c = getchar()) == EOF) exit (1);
  cc[0] = c;

  if ((c = getchar()) == EOF) exit (1);
  cc[1] = c;
  cc[2] = '\0';
  
  if (strcmp( "%!", cc) == 0) {  /* Check for Postscript */
    pipe (fds);
    switch (fork()) { /* We have Postscript so send it through gs */
    case -1:
      printf("Can't fork; quitting!\n");
      exit (1);
    case 0:
      dup2(fds[1],1);
      dup2(fds[1],2);
      close(fds[0]);
      close(fds[1]);
      write(1,cc,2);
      while ((c = getchar()) != EOF) /* Send it down the pipe to gs */
        write_b(1,(char*)&c,1);
      write_b(1,(char*)NULL, -1);
      exit(0);
    default:
      dup2(fds[0],0);
      close(fds[0]);
      close(fds[1]);
      execl("/usr/local/bin/gs", "gs", "-q", "-dNOPAUSE", "-dSAFER",
            "-sPAPERSIZE=note", "-sDEVICE=ljet4", "-sOutputFile=-",
             "-", (char*)NULL);
      printf("Can't exec gs; quitting!\n");
      exit(1);
    }
  } else if (cc[0] == '\033') { /* Check for PCL */
    write(1,cc,2);
    while ((c = getchar()) != EOF) /* It's PCL so send it along */
      write_b(1,(char*)&c,1);
    write_b(1,(char*)NULL,-1);
    exit(0);
  } else {                       /* Treat as pure text */
    write(1,"\033%-12345X@PJL\n",14); /* Wrap it in PCL commands */
    write(1,"@PJL ENTER LANGUAGE = PCL\n",26);
    write(1,"\033E\033&k2G",7);
    write(1,cc,2);
    while ((c = getchar()) != EOF)
      write_b(1,(char*)&c,1);
    write_b(1,(char*)NULL,-1);
    write(1,"\033E\033%-12345X",11);
    exit(0);
  }
}

/* Buffers characters before writing, then writes buffer. */

int write_b (int fd, char *cc, int n)
{
# define BUFSIZE 1024

static char *buff = NULL;
static int count = 0;

  if (n > 0) {

    if (buff == NULL) {
      if ((buff = (char*)malloc(sizeof(char)*BUFSIZE)) == NULL)
        return -1;
    }

    buff[count++] = *cc;

    if (count >= BUFSIZE) {
      write(fd, buff, BUFSIZE);
      count = 0;
    }

  } else {

    if (count > 0)
      write (fd, buff, count);

    if (buff != NULL) free (buff);
    buff = NULL;
  }

  return 0;
}

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.10010271656010.395-300000>