Bug 178856 - java/openjdk6, java/openjdk7: Java fails to print when lpr is removed from base system
java/openjdk6, java/openjdk7: Java fails to print when lpr is removed from ba...
Status: Closed FIXED
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s)
Latest
Any Any
: Normal Affects Only Me
Assigned To: Jung-uk Kim
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-05-23 09:30 UTC by bugReporter
Modified: 2014-05-21 21:17 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bugReporter 2013-05-23 09:30:00 UTC
Due to the use of cups, lpr is removed (WITHOUT_LPR=YES in make.config).
When printing, Java recognises the printer but tries to execute /usr/bin/lpr
which does not exist.

Fix: 

create a symbolic link:
ln -s /usr/local/bin/lpr /usr/bin/lpr

or teach jre to search for /usr/local/bin/lpr if /usr/bin/lpr does not
exist or vice versa
How-To-Repeat: build FreeBSD without lpr
remove unnecessary binaries
install cups and define printer
try to print from java
Comment 1 Mark Linimon freebsd_committer 2013-05-24 14:29:10 UTC
State Changed
From-To: open->feedback

to which JRE port does this apply?
Comment 2 linimon 2013-05-26 01:11:44 UTC
----- Forwarded message from "Dr. A. Haakh" <bugReporter@Haakh.de> -----

Date: Fri, 24 May 2013 15:51:11 +0200
From: "Dr. A. Haakh" <bugReporter@Haakh.de>
To: linimon@FreeBSD.org
Subject: Re: ports/178856: Java fails to print when lpr is removed from base system
User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:20.0) Gecko/20100101 Firefox/20.0 SeaMonkey/2.17

Both openjdk6 and openjdk7 current versions.

See sources of openjdk6:
            execCmd[n++] = "/usr/bin/lpr";
in work/jdk/src/share/classes/sun/print/PSPrinterJob.java

and
            execCmd[n++] = "/usr/bin/lpr";
in work/jdk/src/solaris/classes/sun/print/UnixPrintJob.java

openjdk7 should look similar.

----- End forwarded message -----
Comment 3 Mark Linimon freebsd_committer 2013-05-26 01:11:49 UTC
State Changed
From-To: feedback->open

Annotate which ports this PR applies to.
Comment 4 Jung-uk Kim freebsd_committer 2014-05-21 17:35:21 UTC
Responsible Changed
From-To: freebsd-java->jkim

I'll take it.
Comment 5 dfilter freebsd_committer 2014-05-21 20:57:15 UTC
Author: jkim
Date: Wed May 21 19:57:11 2014
New Revision: 354759
URL: http://svnweb.freebsd.org/changeset/ports/354759
QAT: https://qat.redports.org/buildarchive/r354759/

Log:
  Fix printing services.  When CUPS is used, ${LOCALBASE}/bin/lpr must be used
  to print a generated PostScript file.  When lpd(8) is used, lpr(1) from base
  must be used.  Also, status command for lpc(8) requires a printer name.  If
  no argument is specified, i.e., "/usr/sbin/lpc status", then it displays the
  command usage, i.e., "usage: status  {all | printer ...}".  Unfortunately,
  "usage" is interpreted as a printer name because ":" is included.  Add "all"
  and adjust an expression for grep(1).
  
  PR:		ports/178856

Modified:
  head/java/openjdk6-jre/Makefile
  head/java/openjdk6/Makefile
  head/java/openjdk6/files/patch-set

Modified: head/java/openjdk6-jre/Makefile
==============================================================================
--- head/java/openjdk6-jre/Makefile	Wed May 21 18:49:16 2014	(r354758)
+++ head/java/openjdk6-jre/Makefile	Wed May 21 19:57:11 2014	(r354759)
@@ -1,6 +1,6 @@
 # $FreeBSD$
 
-PORTREVISION=	1
+PORTREVISION=	2
 CATEGORIES=	java devel
 PKGNAMESUFFIX=	-jre
 

Modified: head/java/openjdk6/Makefile
==============================================================================
--- head/java/openjdk6/Makefile	Wed May 21 18:49:16 2014	(r354758)
+++ head/java/openjdk6/Makefile	Wed May 21 19:57:11 2014	(r354759)
@@ -3,7 +3,7 @@
 
 PORTNAME=	openjdk6
 PORTVERSION=	b31
-PORTREVISION?=	2
+PORTREVISION?=	3
 PORTEPOCH=	1
 CATEGORIES=	java devel
 MASTER_SITES=	${MASTER_SITE_APACHE:S,%SUBDIR%/,ant/binaries/:ant,} \
@@ -245,7 +245,8 @@ post-patch:
 	    ${WRKSRC}/jdk/make/tools/freetypecheck/Makefile
 	@${REINPLACE_CMD} -e "s|%%LOCALBASE%%|${LOCALBASE}|" \
 	    ${WRKSRC}/hotspot/src/os/bsd/vm/os_bsd.cpp \
-	    ${WRKSRC}/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java
+	    ${WRKSRC}/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java \
+	    ${WRKSRC}/jdk/src/share/classes/sun/print/PSPrinterJob.java
 .if ${PORT_OPTIONS:MPOLICY}
 	@${REINPLACE_CMD} -e 's|%%POLICY%%|unlimited|' \
 	    ${WRKSRC}/jdk/make/javax/crypto/Makefile

Modified: head/java/openjdk6/files/patch-set
==============================================================================
--- head/java/openjdk6/files/patch-set	Wed May 21 18:49:16 2014	(r354758)
+++ head/java/openjdk6/files/patch-set	Wed May 21 19:57:11 2014	(r354759)
@@ -5272,17 +5272,42 @@
 +}
 --- jdk/src/share/classes/sun/print/PSPrinterJob.java
 +++ jdk/src/share/classes/sun/print/PSPrinterJob.java
-@@ -1531,7 +1531,9 @@
+@@ -1531,9 +1531,33 @@
              pFlags |= NOSHEET;
              ncomps+=1;
          }
 -       if (System.getProperty("os.name").equals("Linux")) {
 +
 +       String osname = System.getProperty("os.name");
-+       if (osname.equals("Linux") || osname.equals("FreeBSD") || osname.equals("NetBSD") || osname.equals("OpenBSD") || osname.equals("Darwin")) {
++       if (osname.equals("Linux") || osname.endsWith("BSD") || osname.contains("OS X")) {
++            String lprPath = "/usr/bin/lpr";
++            if (osname.endsWith("BSD")) {
++                final PrintService pservice = getPrintService();
++                Boolean isIPPPrinter =
++                    (Boolean)java.security.AccessController.doPrivileged(
++                    new java.security.PrivilegedAction() {
++                        public Object run() {
++                            try {
++                                Class psClass =
++                                    Class.forName("sun.print.IPPPrintService");
++                                if (psClass.isInstance(pservice)) {
++                                    return Boolean.TRUE;
++                                }
++                            } catch (Throwable t) {
++                            }
++                            return Boolean.FALSE;
++                        }
++                    });
++                if (isIPPPrinter) {
++                    lprPath = "%%LOCALBASE%%/bin/lpr";
++                }
++            }
              execCmd = new String[ncomps];
-             execCmd[n++] = "/usr/bin/lpr";
+-            execCmd[n++] = "/usr/bin/lpr";
++            execCmd[n++] = lprPath;
              if ((pFlags & PRINTER) != 0) {
+                 execCmd[n++] = new String("-P" + printer);
+             }
 --- jdk/src/share/classes/sun/security/jgss/GSSManagerImpl.java
 +++ jdk/src/share/classes/sun/security/jgss/GSSManagerImpl.java
 @@ -49,8 +49,12 @@
@@ -9279,19 +9304,43 @@
 +}
 --- jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
 +++ jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
-@@ -119,7 +119,11 @@
+@@ -119,7 +119,9 @@
      }
  
      static boolean isBSD() {
 -        return osname.equals("Linux");
-+	return (osname.equals("Linux") ||
-+		osname.equals("FreeBSD") ||
-+		osname.equals("Darwin") ||
-+		osname.equals("NetBSD") ||
-+		osname.equals("OpenBSD"));
++        return (osname.equals("Linux") ||
++                osname.endsWith("BSD") ||
++                osname.contains("OS X"));
      }
  
      static final int UNINITIALIZED = -1;
+@@ -129,13 +131,13 @@
+     static int cmdIndex = UNINITIALIZED;
+ 
+     String[] lpcFirstCom = {
+-        "/usr/sbin/lpc status | grep : | sed -ne '1,1 s/://p'",
++        "/usr/sbin/lpc status all | grep ':$' | sed -ne '1,1 s/://p'",
+         "/usr/sbin/lpc status | grep -E '^[ 0-9a-zA-Z_-]*@' | awk -F'@' '{print $1}'"
+     };
+ 
+     String[] lpcAllCom = {
+-        "/usr/sbin/lpc status | grep : | sed -e 's/://'",
+-        "/usr/sbin/lpc -a status | grep -E '^[ 0-9a-zA-Z_-]*@' | awk -F'@' '{print $1}' | sort"
++        "/usr/sbin/lpc status all | grep ':$' | sed -e 's/://'",
++        "/usr/sbin/lpc status all | grep -E '^[ 0-9a-zA-Z_-]*@' | awk -F'@' '{print $1}' | sort"
+     };
+ 
+     String[] lpcNameCom = {
+@@ -145,7 +147,7 @@
+ 
+ 
+     static int getBSDCommandIndex() {
+-        String command  = "/usr/sbin/lpc status";
++        String command  = "/usr/sbin/lpc status all";
+         String[] names = execCmd(command);
+ 
+         if ((names == null) || (names.length == 0)) {
 --- jdk/src/solaris/classes/sun/tools/attach/BsdVirtualMachine.java
 +++ jdk/src/solaris/classes/sun/tools/attach/BsdVirtualMachine.java
 @@ -38,9 +38,6 @@
_______________________________________________
svn-ports-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-ports-all
To unsubscribe, send any mail to "svn-ports-all-unsubscribe@freebsd.org"
Comment 6 dfilter freebsd_committer 2014-05-21 21:03:19 UTC
Author: jkim
Date: Wed May 21 20:03:14 2014
New Revision: 354761
URL: http://svnweb.freebsd.org/changeset/ports/354761
QAT: https://qat.redports.org/buildarchive/r354761/

Log:
  - Fix printing services.  When CUPS is used, ${LOCALBASE}/bin/lpr must be
  used to print a generated PostScript file.  When lpd(8) is used, lpr(1) from
  base must be used.  Also, status command for lpc(8) requires a printer name.
  If no argument is specified, i.e., "/usr/sbin/lpc status", then it displays
  the command usage, i.e., "usage: status  {all | printer ...}".
  Unfortunately, "usage" is interpreted as a printer name because ":" is
  included.  Add "all" and adjust an expression for grep(1). [1]
  - Use /proc/curproc/file to find its executable path if available.  It fixes
  java/icedtea-web, for example. [2]
  
  PR:		ports/178856 [1]
  PR:		java/189905 [2]

Added:
  head/java/openjdk7/files/patch-src-share-classes-sun-print-PSPrinterJob.java   (contents, props changed)
  head/java/openjdk7/files/patch-src-solaris-bin-java_md_solinux.c   (contents, props changed)
  head/java/openjdk7/files/patch-src-solaris-classes-sun-print-UnixPrintServiceLookup.java   (contents, props changed)
Modified:
  head/java/openjdk7/Makefile

Modified: head/java/openjdk7/Makefile
==============================================================================
--- head/java/openjdk7/Makefile	Wed May 21 19:58:46 2014	(r354760)
+++ head/java/openjdk7/Makefile	Wed May 21 20:03:14 2014	(r354761)
@@ -3,7 +3,7 @@
 
 PORTNAME=	openjdk
 PORTVERSION=	${JDK_MAJOR_VERSION}.${PORT_MINOR_VERSION}.${PORT_BUILD_NUMBER}
-PORTREVISION=	4
+PORTREVISION=	5
 PORTEPOCH=	1
 CATEGORIES=	java devel
 MASTER_SITES=	http://download.java.net/openjdk/jdk${JDK_MAJOR_VERSION}u${JDK_MINOR_VERSION}/promoted/b${JDK_BUILD_NUMBER}/ \
@@ -130,7 +130,8 @@ MAKE_ENV+=	EXTRA_CFLAGS=-DLIBICONV_PLUG
 
 post-patch:
 	@${REINPLACE_CMD} "s|%%LOCALBASE%%|${LOCALBASE}|" \
-		${WRKSRC}/hotspot/src/os/bsd/vm/os_bsd.cpp
+		${WRKSRC}/hotspot/src/os/bsd/vm/os_bsd.cpp \
+		${WRKSRC}/jdk/src/share/classes/sun/print/PSPrinterJob.java
 .if empty(ICONV_LIB)
 	@${REINPLACE_CMD} 's| -liconv||' \
 		${WRKSRC}/Makefile \

Added: head/java/openjdk7/files/patch-src-share-classes-sun-print-PSPrinterJob.java
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/java/openjdk7/files/patch-src-share-classes-sun-print-PSPrinterJob.java	Wed May 21 20:03:14 2014	(r354761)
@@ -0,0 +1,36 @@
+--- jdk/src/share/classes/sun/print/PSPrinterJob.java
++++ jdk/src/share/classes/sun/print/PSPrinterJob.java
+@@ -1568,9 +1568,31 @@
+         }
+ 
+        String osname = System.getProperty("os.name");
+-       if (osname.equals("Linux") || osname.equals("FreeBSD") || osname.equals("NetBSD") || osname.equals("OpenBSD") || osname.equals("OS X")) {
++       if (osname.equals("Linux") || osname.endsWith("BSD") || osname.contains("OS X")) {
++            String lprPath = "/usr/bin/lpr";
++            if (osname.endsWith("BSD")) {
++                final PrintService pservice = getPrintService();
++                Boolean isIPPPrinter =
++                    (Boolean)java.security.AccessController.doPrivileged(
++                    new java.security.PrivilegedAction() {
++                        public Object run() {
++                            try {
++                                Class psClass =
++                                    Class.forName("sun.print.IPPPrintService");
++                                if (psClass.isInstance(pservice)) {
++                                    return Boolean.TRUE;
++                                }
++                            } catch (Throwable t) {
++                            }
++                            return Boolean.FALSE;
++                        }
++                    });
++                if (isIPPPrinter) {
++                    lprPath = "%%LOCALBASE%%/bin/lpr";
++                }
++            }
+             execCmd = new String[ncomps];
+-            execCmd[n++] = "/usr/bin/lpr";
++            execCmd[n++] = lprPath;
+             if ((pFlags & PRINTER) != 0) {
+                 execCmd[n++] = "-P" + printer;
+             }

Added: head/java/openjdk7/files/patch-src-solaris-bin-java_md_solinux.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/java/openjdk7/files/patch-src-solaris-bin-java_md_solinux.c	Wed May 21 20:03:14 2014	(r354761)
@@ -0,0 +1,38 @@
+--- jdk/src/solaris/bin/java_md_solinux.c
++++ jdk/src/solaris/bin/java_md_solinux.c
+@@ -899,8 +899,9 @@
+  * onwards the filename returned in DL_info structure from dladdr is
+  * an absolute pathname so technically realpath isn't required.
+  * On Linux we read the executable name from /proc/self/exe.
+- * As a fallback, and for platforms other than Solaris and Linux,
+- * we use FindExecName to compute the executable name.
++ * On FreeBSD we read the executable name from /proc/curproc/file.
++ * As a fallback, and for platforms other than Solaris, Linux, and
++ * FreeBSD, we use FindExecName to compute the executable name.
+  */
+ const char*
+ SetExecname(char **argv)
+@@ -927,9 +928,13 @@
+             }
+         }
+     }
+-#elif defined(__linux__)
++#elif defined(__linux__) || defined(__FreeBSD__)
+     {
++#if defined(__FreeBSD__)
++        const char* self = "/proc/curproc/file";
++#else
+         const char* self = "/proc/self/exe";
++#endif
+         char buf[PATH_MAX+1];
+         int len = readlink(self, buf, PATH_MAX);
+         if (len >= 0) {
+@@ -937,7 +942,7 @@
+             exec_path = JLI_StringDup(buf);
+         }
+     }
+-#else /* !__solaris__ && !__linux__ */
++#else /* !__solaris__ && !__linux__ && !__FreeBSD__ */
+     {
+         /* Not implemented */
+     }

Added: head/java/openjdk7/files/patch-src-solaris-classes-sun-print-UnixPrintServiceLookup.java
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/java/openjdk7/files/patch-src-solaris-classes-sun-print-UnixPrintServiceLookup.java	Wed May 21 20:03:14 2014	(r354761)
@@ -0,0 +1,17 @@
+--- jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
++++ jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
+@@ -140,12 +140,12 @@
+     static int cmdIndex = UNINITIALIZED;
+ 
+     String[] lpcFirstCom = {
+-        "/usr/sbin/lpc status | grep : | sed -ne '1,1 s/://p'",
++        "/usr/sbin/lpc status all | grep ':$' | sed -ne '1,1 s/://p'",
+         "/usr/sbin/lpc status | grep -E '^[ 0-9a-zA-Z_-]*@' | awk -F'@' '{print $1}'"
+     };
+ 
+     String[] lpcAllCom = {
+-        "/usr/sbin/lpc status all | grep : | sed -e 's/://'",
++        "/usr/sbin/lpc status all | grep ':$' | sed -e 's/://'",
+         "/usr/sbin/lpc status all | grep -E '^[ 0-9a-zA-Z_-]*@' | awk -F'@' '{print $1}' | sort"
+     };
+ 
_______________________________________________
svn-ports-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-ports-all
To unsubscribe, send any mail to "svn-ports-all-unsubscribe@freebsd.org"
Comment 7 Jung-uk Kim freebsd_committer 2014-05-21 21:14:58 UTC
State Changed
From-To: open->closed

It should be fixed with r354759 (java/openjdk6) and 
r354761 (java/openjdk7).  Sorry for the delay.