General foo2zjs :  foo2zjs - foo2hp - foo2xqx - foo2lava - foo2qpdl - foo2oak
Support for linux printer drivers
The fastest message board... ever.
 
osx-hplj-hotplug stopped working
Posted by: candlerb ()
Date: June 10, 2020 09:42AM

Hello,

I've been using foo2zjs with HP 1020 for a while under macOS 10.14.6. Recently it stopped working - possibly with the latest macOS security update but I'm not sure.

The symptom is that osx-hplj-hotplug hangs:

$ osx-hplj-hotplug -D 99
LaserJet /usr/share/foo2zjs/firmware/sihp1020.dl Found!
HP LaserJet 1020
found interface: 7171
GetDeviceID: MFG:Hewlett-Packard;MDL:HP LaserJet 1020;CMD:ACL;CLS:PRINTER;DES:HP LaserJet 1020;
dealWithInterface: found 2 pipes
dealWithPipes: grabbing BULK OUT pipe index 1, num 1
dealWithPipes: grabbing BULK IN pipe index 2, num 1
transferData: calling CFRunLoopRun

That's it. I don't get the printer bursting into life as it normally does when firmware has been received.

I've compiled the latest foo2zjs tarball: compilation was successful but it hasn't made a difference. Obviously powered the printer off and on several times.

Looking at the code, I see:

debug(1, "transferData: calling CFRunLoopRun\n");
CFRunLoopRun();
debug(1, "transferData: returned from CFRunLoopRun\n");

which means it dives into the internals of CFRunLoopRun() but never comes back.

Any suggestions for what I could do to pin this down?

Many thanks,

Brian.

Options: ReplyQuote
Re: osx-hplj-hotplug stopped working
Posted by: candlerb ()
Date: June 10, 2020 10:23AM

Adding some debug has helped:

--- osx-hplj-hotplug.m.orig	2011-07-22 19:59:04.000000000 +0100
+++ osx-hplj-hotplug.m	2020-06-10 15:04:51.000000000 +0100
@@ -162,6 +162,10 @@
 	}
 	fclose(fp);
     }
+    else {
+        perror(mpd->hp->path);
+        return;
+    }
     debug(1, "transferData: calling CFRunLoopRun\n");
     CFRunLoopRun();
     debug(1, "transferData: returned from  CFRunLoopRun\n");


Gives me the following result:

LaserJet /usr/share/foo2zjs/firmware/sihp1020.dl Found!
HP LaserJet 1020
GetDeviceID: MFG:Hewlett-Packard;MDL:HP LaserJet 1020;CMD:ACL;CLS:PRINTER;DES:HP LaserJet 1020;
/usr/share/foo2zjs/firmware/sihp1020.dl: No such file or directory


The thing is, I see the firmware files under /usr/local/share/foo2zfs, not /usr/share

I had done:
make install PREFIX=/usr/local

SIP stops me doing the obvious workaround:
sudo ln -s /usr/local/share/foo2zjs /usr/share/foo2zjs

So in the end I just replaced /usr/share with /usr/local/share in osx-hplj-hotplug.m and recompiled, and at least that part now works.

I now have a different problem which I need to dig into:

D [10/Jun/2020:15:17:06 +0100] [Job 8] ================================================
D [10/Jun/2020:15:17:06 +0100] [Job 8] File: <STDIN>
D [10/Jun/2020:15:17:06 +0100] [Job 8] ================================================
D [10/Jun/2020:15:17:06 +0100] [Job 8] Filetype: PDF
D [10/Jun/2020:15:17:06 +0100] [Job 8] Neither PDF renderer command line nor Ghostscript-based renderer command line found
D [10/Jun/2020:15:17:06 +0100] [Job 8] Driver does not understand PDF input, converting to PostScript
D [10/Jun/2020:15:17:06 +0100] [Job 8] Storing temporary files in /private/var/spool/cups/tmp
D [10/Jun/2020:15:17:06 +0100] [Job 8] PID 63677 (/usr/libexec/cups/filter/cgpdftopdf) exited with no errors.
D [10/Jun/2020:15:17:06 +0100] [Job 8] Starting process \"pdf-to-ps\" (generation 1)
D [10/Jun/2020:15:17:06 +0100] [Job 8] Cannot process \"<STDIN>\": Unknown filetype.
D [10/Jun/2020:15:17:06 +0100] [Job 8] exec_command: gs -q -sstdout=%stderr -sDEVICE=ps2write -sOutputFile=- -dBATCH -dNOPAUSE -dPARANOIDSAFER -dNOINTERPOLATE /private/var/spool/cups/tmp/foomatic-qd7Li7 2>/dev/null || pdftops -level2 -origpagesizes /private/var/spool/cups/tmp/foomatic-qd7Li7 - 2>/dev/null
D [10/Jun/2020:15:17:06 +0100] [Job 8] usb: AppleLanguages=\"en-US\"
D [10/Jun/2020:15:17:06 +0100] [Job 8] STATE: +connecting-to-device
D [10/Jun/2020:15:17:06 +0100] [Job 8] Looking for \'Hewlett-Packard HP LaserJet 1020\'
D [10/Jun/2020:15:17:06 +0100] [Job 8] Opening connection
D [10/Jun/2020:15:17:06 +0100] [Job 8] pdf-to-ps exited with status 127
D [10/Jun/2020:15:17:06 +0100] [Job 8] Process is dying with \"Could not print file <STDIN>
D [10/Jun/2020:15:17:06 +0100] [Job 8] \", exit stat 2
D [10/Jun/2020:15:17:06 +0100] [Job 8] Cleaning up...
D [10/Jun/2020:15:17:06 +0100] [Job 8] PID 63678 (/usr/libexec/cups/filter/foomatic-rip) stopped with status 2.
D [10/Jun/2020:15:17:06 +0100] [Job 8] Hint: Try setting the LogLevel to "debug" to find out more.
D [10/Jun/2020:15:17:06 +0100] [Job 8] Directory “/System/Library/Printers/Libraries/USBGenericPrintingClass.plugin” permissions OK (040755/uid=0/gid=0).
D [10/Jun/2020:15:17:06 +0100] [Job 8] load_classdriver(/System/Library/Printers/Libraries/USBGenericPrintingClass.plugin) (kr:0x00000000)
D [10/Jun/2020:15:17:06 +0100] [Job 8] STATE: -connecting-to-device
D [10/Jun/2020:15:17:06 +0100] [Job 8] Sending data to printer.
D [10/Jun/2020:15:17:06 +0100] [Job 8] Sent 0 bytes...
D [10/Jun/2020:15:17:06 +0100] [Job 8] STATE: +cups-waiting-for-job-completed
D [10/Jun/2020:15:17:06 +0100] [Job 8] Waiting for read thread to exit...
D [10/Jun/2020:15:17:06 +0100] [Job 8] Read thread still active, aborting the pending read...
D [10/Jun/2020:15:17:06 +0100] [Job 8] Got USB return aborted during read
D [10/Jun/2020:15:17:06 +0100] [Job 8] PID 63679 (/usr/libexec/cups/backend/usb) exited with no errors.
D [10/Jun/2020:15:17:06 +0100] [Job 8] End of messages
D [10/Jun/2020:15:17:06 +0100] [Job 8] printer-state=3(idle)
D [10/Jun/2020:15:17:06 +0100] [Job 8] printer-state-message="Sending data to printer."
D [10/Jun/2020:15:17:06 +0100] [Job 8] printer-state-reasons=none

Regards,

Brian.

P.S. I remembered that a few weeks ago I had a corrupt APFS filesystem and had to reinstall macOS and restore from a Time Machine backup. It's probably that which caused foo2zjs to stop working; I just hadn't done any printing since then.

Options: ReplyQuote
Re: osx-hplj-hotplug stopped working
Posted by: candlerb ()
Date: June 10, 2020 11:56AM

After more debugging, this time in foomatic-rip: I find that when it opens the configuration file /usr/local/etc/foomatic/filter.conf it gets an EPERM. This looks like some sort of sandboxing problem.

filter.conf has an execpath setting:
execpath: /usr/local/bin:/usr/bin:/bin:/usr/sbin

but since the file can't be opened this is ignored; and getenv("PATH") shows
/usr/libexec/cups/filter:/usr/bin:/usr/sbin:/bin:/usr/bin

which means the problem is that things in /usr/local/bin can't be found.

Even if I manually code the exact path:

                  snprintf(pdf2ps_cmd, PATH_MAX,
                           "/usr/local/bin/pdftops '%s' '%s' '%s' '%s' '%s' '%s'",
                           job->id, job->user, job->title, "1", job->optstr->data,
                           filename);


I find that it can't be run:

D [10/Jun/2020:16:50:34 +0100] [Job 20] /bin/bash: /usr/local/bin/pdftops: Operation not permitted

It looks like I may have to disable SIP globally - or else copy the whole of ghostscript into a directory which CUPS has access to :-(

Options: ReplyQuote
Re: osx-hplj-hotplug stopped working
Posted by: rickrich ()
Date: June 10, 2020 04:43PM

$ head ChangeLog 
2020-06-10 Rick Richardson <rick.richardson@comcast.net>
        * osx-hotplug: Add PREFIX=/usr or PREFIX=/usr/local to cc rules


Options: ReplyQuote
Re: osx-hplj-hotplug stopped working
Posted by: candlerb ()
Date: June 21, 2020 05:58AM

That fixes the hotplug problem, thanks. (BTW, is there a git repo? It would be much easier to see what's changed between versions)

However, even though I've turned off SIP with csrutil, I still can't print.

CUPS logs are showing:

D [21/Jun/2020:10:38:34 +0100] [Job 24] ================================================
D [21/Jun/2020:10:38:34 +0100] [Job 24] File: <STDIN>
D [21/Jun/2020:10:38:34 +0100] [Job 24] ================================================
D [21/Jun/2020:10:38:34 +0100] [Job 24] Guessing file type of \"<STDIN>\" from 8191 bytes
D [21/Jun/2020:10:38:34 +0100] [Job 24] Filetype: PDF
D [21/Jun/2020:10:38:34 +0100] [Job 24] Neither PDF renderer command line nor Ghostscript-based renderer command line found
D [21/Jun/2020:10:38:34 +0100] [Job 24] Driver does not understand PDF input, converting to PostScript
D [21/Jun/2020:10:38:34 +0100] [Job 24] Storing temporary files in /private/var/spool/cups/tmp
D [21/Jun/2020:10:38:34 +0100] [Job 24] PATH: /usr/libexec/cups/filter:/usr/bin:/usr/sbin:/bin:/usr/bin
D [21/Jun/2020:10:38:34 +0100] [Job 24] pds2ps_cmd: /usr/local/bin/pdftops \'24\' \'brian\' ... snip ...
D [21/Jun/2020:10:38:34 +0100] [Job 24] Starting process \"pdf-to-ps\" (generation 1)
D [21/Jun/2020:10:38:34 +0100] [Job 24] Guessing file type of \"<STDIN>\" from 0 bytes
D [21/Jun/2020:10:38:34 +0100] [Job 24] Cannot process \"<STDIN>\": Unknown filetype.
D [21/Jun/2020:10:38:34 +0100] [Job 24] /bin/bash: /usr/local/bin/pdftops: Operation not permitted
D [21/Jun/2020:10:38:34 +0100] [Job 24] pdf-to-ps exited with status 126
D [21/Jun/2020:10:38:34 +0100] [Job 24] Process is dying with \"Could not print file <STDIN>
D [21/Jun/2020:10:38:34 +0100] [Job 24] \", exit stat 2
D [21/Jun/2020:10:38:34 +0100] [Job 24] Cleaning up...
D [21/Jun/2020:10:38:34 +0100] [Job 24] PID 52885 (/usr/libexec/cups/filter/foomatic-rip) stopped with status 2.

Note (1) PATH does not contain /usr/local/bin (suggests foomatic-rip isn't reading its config); and (2) "Operation not permitted" on running /usr/local/bin/pdftops.

Yet pdftops runs OK locally:

MacBook-Pro-4:foo2zjs $ csrutil status
System Integrity Protection status: disabled.
MacBook-Pro-4:foo2zjs $ /usr/local/bin/pdftops /dev/null
Syntax Error: Document stream is empty

and checking all the directory perms:

MacBook-Pro-4:foo2zjs $ ls -ld /usr
drwxr-xr-x@ 10 root  wheel  320 26 May 18:27 /usr
MacBook-Pro-4:foo2zjs $ ls -ld /usr/local
drwxr-xr-x  17 root  wheel  544 26 May 18:27 /usr/local
MacBook-Pro-4:foo2zjs $ ls -ld /usr/local/bin
drwxr-xr-x@ 854 brian  admin  27328 21 Jun 10:46 /usr/local/bin
MacBook-Pro-4:foo2zjs $ ls -ld /usr/local/bin/pdftops
lrwxr-xr-x  1 brian  admin  36  4 Nov  2018 /usr/local/bin/pdftops -> ../Cellar/poppler/0.71.0/bin/pdftops
MacBook-Pro-4:foo2zjs $ ls -ld /usr/local/Cellar
drwxrwxr-x@ 220 brian  admin  7040 10 Jun 14:12 /usr/local/Cellar
MacBook-Pro-4:foo2zjs $ ls -ld /usr/local/Cellar/poppler
drwxr-xr-x@ 5 brian  staff  160  4 Nov  2018 /usr/local/Cellar/poppler
MacBook-Pro-4:foo2zjs $ ls -ld /usr/local/Cellar/poppler/0.71.0/
drwxr-xr-x  13 brian  staff  416  4 Nov  2018 /usr/local/Cellar/poppler/0.71.0/
MacBook-Pro-4:foo2zjs $ ls -ld /usr/local/Cellar/poppler/0.71.0/pdftops
ls: /usr/local/Cellar/poppler/0.71.0/pdftops: No such file or directory
MacBook-Pro-4:foo2zjs $ ls -ld /usr/local/Cellar/poppler/0.71.0/bin
drwxr-xr-x  14 brian  staff  448 31 Oct  2018 /usr/local/Cellar/poppler/0.71.0/bin
MacBook-Pro-4:foo2zjs $ ls -ld /usr/local/Cellar/poppler/0.71.0/bin/pdftops
-r-xr-xr-x  1 brian  staff  26860  4 Nov  2018 /usr/local/Cellar/poppler/0.71.0/bin/pdftops

Options: ReplyQuote
Re: osx-hplj-hotplug stopped working
Posted by: candlerb ()
Date: June 21, 2020 06:17AM

I should add: those logs include some local logging hacks to foomatic-filters, plus explicit bypassing of the PATH to use hard-coded /usr/local/bin/xxx paths:

diff --exclude '*.Po' -uNr foomatic-filters-4.0-20160212.new/foomaticrip.c foomatic-filters-4.0-20160212/foomaticrip.c
--- foomatic-filters-4.0-20160212.new/foomaticrip.c     2018-11-07 14:28:48.000000000 +0000
+++ foomatic-filters-4.0-20160212/foomaticrip.c 2020-06-10 16:52:45.000000000 +0100
@@ -212,19 +212,26 @@
     char line[256];
     char *key, *value;

+    _log("config_from_file: %s\n", filename);
     fh = fopen(filename, "r");
-    if (fh == NULL)
+    if (fh == NULL) {
+        _log("config_from_file: error: %s\n", strerror(errno));
         return; /* no error here, only read config file if it is present */
+    }
+    _log("config_from_file: open OK\n");

     while (fgets(line, 256, fh) != NULL)
     {
+        _log("config_from_file: line <%s>\n", line);
         key = strtok(line, " :\t\r\n");
         if (key == NULL || key[0] == '#')
             continue;
         value = strtok(NULL, " \t\r\n#");
+        _log("<%s>=<%s>\n", key, value);
         config_set_option(key, value);
     }
     fclose(fh);
+    _log("config_from_file: complete");
 }

 const char * get_modern_shell()
@@ -995,6 +1002,7 @@

     n = fread(buf, 1, sizeof(buf) - 1, file);
     buf[n] = '\0';
+    _log("Guessing file type of \"%s\" from %d bytes\n", filename, n);
     type = guess_file_type(buf, n, &startpos);
     /* We do not use any JCL preceeded to the inputr data, as it is simply
        the PJL commands from the PPD file, and these commands we can also
@@ -1059,17 +1067,19 @@

                   We give priority to Ghostscript here and use Poppler if
                   Ghostscript is not available. */
-               /*if (spooler == SPOOLER_CUPS)
+               if (spooler == SPOOLER_CUPS)
                  snprintf(pdf2ps_cmd, PATH_MAX,
-                          "pdftops '%s' '%s' '%s' '%s' '%s' '%s'",
+                          "/usr/local/bin/pdftops '%s' '%s' '%s' '%s' '%s' '%s'",
                           job->id, job->user, job->title, "1", job->optstr->data,
                           filename);
-               else*/
+               else
                  snprintf(pdf2ps_cmd, PATH_MAX,
-                          "gs -q -sstdout=%%stderr -sDEVICE=ps2write -sOutputFile=- "
+                          "/usr/local/bin/gs -q -sstdout=%%stderr -sDEVICE=ps2write -sOutputFile=- "
                           "-dBATCH -dNOPAUSE -dPARANOIDSAFER -dNOINTERPOLATE %s 2>/dev/null || "
                           "pdftops -level2 -origpagesizes %s - 2>/dev/null",

                           filename, filename);
+                _log("PATH: %s\n", getenv("PATH"));
+                _log("pds2ps_cmd: %s\n", pdf2ps_cmd);

                 renderer_pid = start_system_process("pdf-to-ps", pdf2ps_cmd, &in, &out);

@@ -1226,6 +1236,11 @@
             _log("\'%s\'\n", argv);
         }
     }
+    //_log("Config read from: %s\n", CONFIG_PATH "/filter.conf");
+    //_log("PATH: %s\n", getenv("PATH"));
+    //config_from_file(CONFIG_PATH "/filter.conf");
+    //setenv("PATH", "/usr/libexec/cups/filter:/usr/bin:/usr/sbin:/bin:/usr/bin:/usr/local/bin", 1);
+    //_log("PATH: %s\n", getenv("PATH"));

     if (getenv("PPD")) {
         strncpy(job->ppdfile, getenv("PPD"), 256);

UPDATE: after some more googling, it seems that the CUPS _lp user is sandboxed separately from SIP.

https://apple.stackexchange.com/questions/153656/sandboxd-for-cups-backends-in-mac-os-x-yosemite

I made the change suggested there: add "Sandboxing Relaxed" to end of /etc/cups/cups-files.conf and then

sudo launchctl stop org.cups.cupsd

Now I get a different error in my logs:

D [21/Jun/2020:11:12:50 +0100] [Job 24] Starting process \"pdf-to-ps\" (generation 1)
D [21/Jun/2020:11:12:50 +0100] [Job 24] Guessing file type of \"<STDIN>\" from 0 bytes
D [21/Jun/2020:11:12:50 +0100] [Job 24] Cannot process \"<STDIN>\": Unknown filetype.
D [21/Jun/2020:11:12:50 +0100] [Job 24] usb: AppleLanguages=\"en-US\"
D [21/Jun/2020:11:12:50 +0100] [Job 24] STATE: +connecting-to-device
D [21/Jun/2020:11:12:50 +0100] [Job 24] Looking for \'Hewlett-Packard HP LaserJet 1020\'
D [21/Jun/2020:11:12:50 +0100] [Job 24] Opening connection
D [21/Jun/2020:11:12:50 +0100] [Job 24] Directory “/System/Library/Printers/Libraries/USBGenericPrintingClass.plugin” permissions OK (040755/uid=0/gid=0).
D [21/Jun/2020:11:12:50 +0100] [Job 24] load_classdriver(/System/Library/Printers/Libraries/USBGenericPrintingClass.plugin) (kr:0x00000000)
D [21/Jun/2020:11:12:50 +0100] [Job 24] STATE: -connecting-to-device
D [21/Jun/2020:11:12:50 +0100] [Job 24] Sending data to printer.
D [21/Jun/2020:11:12:50 +0100] [Job 24] Set job-printer-state-message to "Sending data to printer.", current level=INFO
D [21/Jun/2020:11:12:50 +0100] [Job 24] pdftops version 0.71.0
D [21/Jun/2020:11:12:50 +0100] [Job 24] Copyright 2005-2018 The Poppler Developers - http://poppler.freedesktop.org
D [21/Jun/2020:11:12:50 +0100] [Job 24] Copyright 1996-2011 Glyph & Cog, LLC
D [21/Jun/2020:11:12:50 +0100] [Job 24] Usage: pdftops [options] <PDF-file> [<PS-file>]
D [21/Jun/2020:11:12:50 +0100] [Job 24] -f <int>                       : first page to print
D [21/Jun/2020:11:12:50 +0100] [Job 24] -l <int>                       : last page to print
D [21/Jun/2020:11:12:50 +0100] [Job 24] -level1                        : generate Level 1 PostScript
D [21/Jun/2020:11:12:50 +0100] [Job 24] -level1sep                     : generate Level 1 separable PostScript
... etc

This is very good: it means it is running pdftops successfully, just giving unrecognised arguments. This is the sort of issue I should be able to debug from here.

I was almost on the point of setting up a sacrificial PC as Linux print server!

Options: ReplyQuote
Re: osx-hplj-hotplug stopped working
Posted by: candlerb ()
Date: June 21, 2020 07:08AM

I tried going back to original foomatic-rip but then found I had to reapply a bunch of patches which I'd previously made to get it to compile, and also stop it calling pdf2ps with the wrong arguments:

--- foomatic-filters-4.0-20160212.orig/configure	2016-02-12 19:36:48.000000000 +0000
+++ foomatic-filters-4.0-20160212/configure	2018-11-06 09:54:34.000000000 +0000
@@ -6149,7 +6149,9 @@
 fi

 if test x$enable_dbus = xyes; then
-	PKG_CHECK_MODULES(DBUS, dbus-1)
+	#PKG_CHECK_MODULES(DBUS, dbus-1)
+	echo Ooops
+	exit 9
 fi

 if test "${NOCONVERTERCHECK}" = "" -a "${A2PS}" = "" -a "${ENSCRIPT}" = "" -a "${MPAGE}" = "" -a "${PAPS}" = "" -a "${TEXTTOPS}" = "" ; then
diff -uNr foomatic-filters-4.0-20160212.orig/foomaticrip.c foomatic-filters-4.0-20160212/foomaticrip.c
--- foomatic-filters-4.0-20160212.orig/foomaticrip.c	2016-02-12 19:36:47.000000000 +0000
+++ foomatic-filters-4.0-20160212/foomaticrip.c	2018-11-07 14:28:48.000000000 +0000
@@ -1059,12 +1059,12 @@

 		   We give priority to Ghostscript here and use Poppler if
 		   Ghostscript is not available. */
-		if (spooler == SPOOLER_CUPS)
+		/*if (spooler == SPOOLER_CUPS)
 		  snprintf(pdf2ps_cmd, PATH_MAX,
 			   "pdftops '%s' '%s' '%s' '%s' '%s' '%s'",
 			   job->id, job->user, job->title, "1", job->optstr->data,
 			   filename);
-		else
+		else*/
 		  snprintf(pdf2ps_cmd, PATH_MAX,
 			   "gs -q -sstdout=%%stderr -sDEVICE=ps2write -sOutputFile=- "
 			   "-dBATCH -dNOPAUSE -dPARANOIDSAFER -dNOINTERPOLATE %s 2>/dev/null || "
diff -uNr foomatic-filters-4.0-20160212.orig/process.c foomatic-filters-4.0-20160212/process.c
--- foomatic-filters-4.0-20160212.orig/process.c	2016-02-12 19:36:47.000000000 +0000
+++ foomatic-filters-4.0-20160212/process.c	2018-11-07 14:05:55.000000000 +0000
@@ -28,6 +28,7 @@
 #include <sys/wait.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <signal.h>

 int kidgeneration = 0;

@@ -171,6 +172,7 @@

 int exec_command(FILE *in, FILE *out, void *cmd)
 {
+    _log("exec_command: %s\n", (const char *)cmd);
     if (in && dup2(fileno(in), fileno(stdin)) < 0)
         rip_die(EXIT_PRNERR_NORETRY_BAD_SETTINGS, "%s: Could not dup stdin\n", (const char *)cmd);
     if (out && dup2(fileno(out), fileno(stdout)) < 0)
diff -uNr foomatic-filters-4.0-20160212.orig/util.c foomatic-filters-4.0-20160212/util.c
--- foomatic-filters-4.0-20160212.orig/util.c	2016-02-12 19:36:47.000000000 +0000
+++ foomatic-filters-4.0-20160212/util.c	2018-11-06 10:01:12.000000000 +0000
@@ -164,6 +164,7 @@
 #endif

 #ifndef __OpenBSD__
+#ifndef __APPLE__
 size_t strlcpy(char *dest, const char *src, size_t size)
 {
     char *pdest = dest;
@@ -203,6 +204,7 @@

     return len + (psrc - src);
 }
+#endif /* ! __APPLE__ */
 #endif /* ! __OpenBSD__ */

 void strrepl(char *str, const char *chars, char repl)
diff -uNr foomatic-filters-4.0-20160212.orig/util.h foomatic-filters-4.0-20160212/util.h
--- foomatic-filters-4.0-20160212.orig/util.h	2016-02-12 19:36:47.000000000 +0000
+++ foomatic-filters-4.0-20160212/util.h	2018-11-06 09:58:35.000000000 +0000
@@ -70,8 +70,13 @@
 /* Copy at most size-1 characters from src to dest
    dest will always be \0 terminated (unless size == 0)
    returns strlen(src) */
+/* On macOS, setrlcpy and strlcat are macros */
+#ifndef strlcpy
 size_t strlcpy(char *dest, const char *src, size_t size);
+#endif
+#ifndef strlcat
 size_t strlcat(char *dest, const char *src, size_t size);
+#endif

 /* Replace all occurences of each of the characters in 'chars' by 'repl' */
 void strrepl(char *str, const char *chars, char repl);


Then build with `./configure --prefix=/usr/local --disable-dbus`

Now it's hanging at "Sending data to printer...": the gs process is present but doesn't appear to make any progress.

_lp               1256   0.0  0.1  4312376  19164   ??  S    12:00pm   0:00.31 gs -q -sstdout=%stderr -sDEVICE=ps2write -sOutputFile=- -dBATCH -dNOPAUSE -dPARANOIDSAFER -dNOINTERPOLATE /private/var/spool/cups/tmp/foomatic-0Npxdw
_lp               1255   0.0  0.0  4288076   1192   ??  S    12:00pm   0:00.01 /bin/bash -c gs -q -sstdout=%stderr -sDEVICE=ps2write -sOutputFile=- -dBATCH -dNOPAUSE -dPARANOIDSAFER -dNOINTERPOLATE /private/var/spool/cups/tmp/foomatic-0Npxdw 2>/dev/null || pdftops -level2 -origpagesizes /private/var/spool/cups/tmp/foomatic-0Npxdw - 2>/dev/null

If I run the command manually:

sudo -u _lp bash -c 'gs -q -sstdout=%stderr -sDEVICE=ps2write -sOutputFile=- -dBATCH -dNOPAUSE -dPARANOIDSAFER -dNOINTERPOLATE /private/var/spool/cups/tmp/foomatic-0Npxdw'

then I get a bunch of Postscript squirted to the screen. So it's something to do with the rest of the pipeline.

Continuing to dig...

Options: ReplyQuote
Re: osx-hplj-hotplug stopped working
Posted by: candlerb ()
Date: June 21, 2020 11:16AM

I managed to make it work at last.

The underlying problem is the somewhat dubious way that foomatic-filters keeps replacing stdin with a different fd (being the output of a child process). I believe there is some sort of race: I was finding that the output of gs was being read as zero bytes on stdin.

The proper fix is probably to spool the output from children to temporary files explicitly; *or* to replace our own stdin with the output pipe *before* exec'ing the child.

However I did a quick hack to foomaticrip.c and postscript.c, which works at least for postscript printing (I haven't tried any other sort of filtering). It allows passing stdin *or* some other open FD as a stream, and spools it into a temporary file just as stdin was doing originally.

Here's the full diff.

--- foomatic-filters-4.0-20160212.orig/configure	2016-02-12 19:36:48.000000000 +0000
+++ foomatic-filters-4.0-20160212/configure	2018-11-06 09:54:34.000000000 +0000
@@ -6149,7 +6149,9 @@
 fi

 if test x$enable_dbus = xyes; then
-	PKG_CHECK_MODULES(DBUS, dbus-1)
+	#PKG_CHECK_MODULES(DBUS, dbus-1)
+	echo Ooops
+	exit 9
 fi

 if test "${NOCONVERTERCHECK}" = "" -a "${A2PS}" = "" -a "${ENSCRIPT}" = "" -a "${MPAGE}" = "" -a "${PAPS}" = "" -a "${TEXTTOPS}" = "" ; then
diff -u foomatic-filters-4.0-20160212.orig/foomaticrip.c foomatic-filters-4.0-20160212/foomaticrip.c
--- foomatic-filters-4.0-20160212.orig/foomaticrip.c	2016-02-12 19:36:47.000000000 +0000
+++ foomatic-filters-4.0-20160212/foomaticrip.c	2020-06-21 13:09:20.000000000 +0100
@@ -969,6 +969,8 @@
     return UNKNOWN_FILE;
 }

+int _print_file(const char *filename, int convert, FILE *file, int streaming);
+
 /*
  * Prints 'filename'. If 'convert' is true, the file will be converted if it is
  * not postscript or pdf
@@ -976,22 +978,29 @@
 int print_file(const char *filename, int convert)
 {
     FILE *file;
-    char buf[8192];
-    int type;
-    int startpos;
-    size_t n;
-    FILE *fchandle = NULL;
-    int fcpid = 0, ret;
+    int ret;

     if (!strcasecmp(filename, "<STDIN>"))
-        file = stdin;
+        ret = _print_file(filename, convert, stdin, 1);
     else {
         file = fopen(filename, "r");
         if (!file) {
             _log("Could not open \"%s\" for reading\n", filename);
             return 0;
         }
+        ret = _print_file(filename, convert, file, 0);
     }
+    return ret;
+}
+
+int _print_file(const char *filename, int convert, FILE *file, int streaming)
+{
+    char buf[8192];
+    int type;
+    int startpos;
+    size_t n;
+    FILE *fchandle = NULL;
+    int fcpid = 0, ret;

     n = fread(buf, 1, sizeof(buf) - 1, file);
     buf[n] = '\0';
@@ -1003,7 +1012,7 @@
         jobhasjcl = 1;
         write_output(buf, startpos);
     }*/
-    if (file != stdin)
+    if (!streaming)
         rewind(file);

     if (convert) pdfconvertedtops = 0;
@@ -1024,8 +1033,8 @@

 		pdfconvertedtops = 1;

-		/* If reading from stdin, write everything into a temporary file */
-		if (file == stdin)
+		/* If reading from stdin or pipe, write everything into a temporary file */
+		if (streaming)
                 {
 		    int fd;
 		    FILE *tmpfile;
@@ -1037,7 +1046,7 @@
 		        return EXIT_PRNERR_NORETRY_BAD_SETTINGS;
 		    }
 		    tmpfile = fdopen(fd, "r+");
-		    copy_file(tmpfile, stdin, buf, n);
+		    copy_file(tmpfile, file, buf, n);
 		    fclose(tmpfile);

 		    filename = tmpfilename;
@@ -1059,12 +1068,12 @@

 		   We give priority to Ghostscript here and use Poppler if
 		   Ghostscript is not available. */
-		if (spooler == SPOOLER_CUPS)
+		/*if (spooler == SPOOLER_CUPS)
 		  snprintf(pdf2ps_cmd, PATH_MAX,
 			   "pdftops '%s' '%s' '%s' '%s' '%s' '%s'",
 			   job->id, job->user, job->title, "1", job->optstr->data,
 			   filename);
-		else
+		else*/
 		  snprintf(pdf2ps_cmd, PATH_MAX,
 			   "gs -q -sstdout=%%stderr -sDEVICE=ps2write -sOutputFile=- "
 			   "-dBATCH -dNOPAUSE -dPARANOIDSAFER -dNOINTERPOLATE %s 2>/dev/null || "
@@ -1073,25 +1082,22 @@

                 renderer_pid = start_system_process("pdf-to-ps", pdf2ps_cmd, &in, &out);

-                if (dup2(fileno(out), fileno(stdin)) < 0)
-                    rip_die(EXIT_PRNERR_NORETRY_BAD_SETTINGS,
-                            "Couldn't dup stdout of pdf-to-ps\n");
-
-                ret = print_file("<STDIN>", 0);
+                ret = _print_file("<PIPE>", 0, out, 1);

                 wait_for_process(renderer_pid);
+                fclose(out);
                 return ret;
             }

-            if (file == stdin)
-                return print_pdf(stdin, buf, n, filename, startpos);
+            if (streaming)
+                return print_pdf(file, buf, n, filename, startpos);
             else
                 return print_pdf(file, NULL, 0, filename, startpos);

         case PS_FILE:
             _log("Filetype: PostScript\n");
-            if (file == stdin)
-                return print_ps(stdin, buf, n, filename);
+            if (streaming)
+                return print_ps(file, buf, n, filename);
             else
                 return print_ps(file, NULL, 0, filename);

@@ -1105,10 +1111,7 @@
             get_fileconverter_handle(buf, &fchandle, &fcpid);

             /* Read further data from the file converter and not from STDIN */
-            if (dup2(fileno(fchandle), fileno(stdin)) < 0)
-                rip_die(EXIT_PRNERR_NORETRY_BAD_SETTINGS, "Couldn't dup fileconverterhandle\n");
-
-            ret = print_file("<STDIN>", 0);
+            ret = _print_file("<PIPE>", 0, fchandle, 1);

             if (close_fileconverter_handle(fchandle, fcpid) != EXIT_PRINTED)
                 rip_die(ret, "Error closing file converter\n");
diff -u foomatic-filters-4.0-20160212.orig/postscript.c foomatic-filters-4.0-20160212/postscript.c
--- foomatic-filters-4.0-20160212.orig/postscript.c	2016-02-12 19:36:47.000000000 +0000
+++ foomatic-filters-4.0-20160212/postscript.c	2020-06-21 13:16:45.000000000 +0100
@@ -189,13 +189,8 @@
 {
     stream_t stream;

-    if (file != stdin && (dup2(fileno(file), fileno(stdin)) < 0)) {
-        _log("Could not dup %s to stdin.\n", filename);
-        return 0;
-    }
-
     stream.pos = 0;
-    stream.file = stdin;
+    stream.file = file;
     stream.alreadyread = alreadyread;
     stream.len = len;
     _print_ps(&stream);
@@ -398,10 +393,7 @@
                             rip_die(EXIT_JOBERR, "File conversion filter probably crashed\n");

                         /* Read the further data from the file converter and not from STDIN */
-                        if (close(fileno(stdin)) == -1 && errno != ESPIPE)
-                            rip_die(EXIT_PRNERR_NORETRY_BAD_SETTINGS, "Couldn't close STDIN\n");
-                        if (dup2(fileno(stdin), fileno(fileconverter_handle)) == -1)
-                            rip_die(EXIT_PRNERR_NORETRY_BAD_SETTINGS, "Couldn't dup fileconverter_handle\n");
+                        stream->file = fileconverter_handle;
                     }
                 }
                 else {
@@ -1146,13 +1138,11 @@
                 else
                     rip_die(EXIT_JOBERR, "File conversion filter probably crashed\n");

-                /* Read the further data from the file converter and
-                not from STDIN */
-                if (close(fileno(stdin)) != 0)
+                /* Read the further data from the file converter */
+                if (close(fileno(stream->file)) != 0)
                     rip_die(EXIT_PRNERR_NORETRY_BAD_SETTINGS, "Couldn't close STDIN\n");

-                if (dup2(fileno(fileconverter_handle), fileno(stdin)) == -1)
-                    rip_die(EXIT_PRNERR_NORETRY_BAD_SETTINGS, "Couldn't dup fileconverterhandle\n");
+                stream->file = fileconverter_handle;

                 /* Now we have new (converted) stuff in STDIN, so
                 continue in the loop */
diff -u foomatic-filters-4.0-20160212.orig/process.c foomatic-filters-4.0-20160212/process.c
--- foomatic-filters-4.0-20160212.orig/process.c	2016-02-12 19:36:47.000000000 +0000
+++ foomatic-filters-4.0-20160212/process.c	2018-11-07 14:05:55.000000000 +0000
@@ -28,6 +28,7 @@
 #include <sys/wait.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <signal.h>

 int kidgeneration = 0;

@@ -171,6 +172,7 @@

 int exec_command(FILE *in, FILE *out, void *cmd)
 {
+    _log("exec_command: %s\n", (const char *)cmd);
     if (in && dup2(fileno(in), fileno(stdin)) < 0)
         rip_die(EXIT_PRNERR_NORETRY_BAD_SETTINGS, "%s: Could not dup stdin\n", (const char *)cmd);
     if (out && dup2(fileno(out), fileno(stdout)) < 0)
Common subdirectories: foomatic-filters-4.0-20160212.orig/test and foomatic-filters-4.0-20160212/test
diff -u foomatic-filters-4.0-20160212.orig/util.c foomatic-filters-4.0-20160212/util.c
--- foomatic-filters-4.0-20160212.orig/util.c	2016-02-12 19:36:47.000000000 +0000
+++ foomatic-filters-4.0-20160212/util.c	2018-11-06 10:01:12.000000000 +0000
@@ -164,6 +164,7 @@
 #endif

 #ifndef __OpenBSD__
+#ifndef __APPLE__
 size_t strlcpy(char *dest, const char *src, size_t size)
 {
     char *pdest = dest;
@@ -203,6 +204,7 @@

     return len + (psrc - src);
 }
+#endif /* ! __APPLE__ */
 #endif /* ! __OpenBSD__ */

 void strrepl(char *str, const char *chars, char repl)
diff -u foomatic-filters-4.0-20160212.orig/util.h foomatic-filters-4.0-20160212/util.h
--- foomatic-filters-4.0-20160212.orig/util.h	2016-02-12 19:36:47.000000000 +0000
+++ foomatic-filters-4.0-20160212/util.h	2018-11-06 09:58:35.000000000 +0000
@@ -70,8 +70,13 @@
 /* Copy at most size-1 characters from src to dest
    dest will always be \0 terminated (unless size == 0)
    returns strlen(src) */
+/* On macOS, setrlcpy and strlcat are macros */
+#ifndef strlcpy
 size_t strlcpy(char *dest, const char *src, size_t size);
+#endif
+#ifndef strlcat
 size_t strlcat(char *dest, const char *src, size_t size);
+#endif

 /* Replace all occurences of each of the characters in 'chars' by 'repl' */
 void strrepl(char *str, const char *chars, char repl);

Options: ReplyQuote
Re: osx-hplj-hotplug stopped working
Posted by: rickrich ()
Date: June 21, 2020 02:13PM

FYI: June 05, 2020 https://openprinting.github.io/cups-filters-1.27.5-released/

Includes foomatic-rip, etc.

Options: ReplyQuote


Sorry, only registered users may post in this forum.
This forum powered by Phorum.