From ronald-freebsd8@klop.yi.org  Wed Aug 15 18:06:27 2007
Return-Path: <ronald-freebsd8@klop.yi.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 07F7B16A418
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 15 Aug 2007 18:06:27 +0000 (UTC)
	(envelope-from ronald-freebsd8@klop.yi.org)
Received: from smtp-out2.tiscali.nl (smtp-out2.tiscali.nl [195.241.79.177])
	by mx1.freebsd.org (Postfix) with ESMTP id BDEC913C457
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 15 Aug 2007 18:06:26 +0000 (UTC)
	(envelope-from ronald-freebsd8@klop.yi.org)
Received: from [82.171.39.195] (helo=guido.klop.ws)
	by smtp-out2.tiscali.nl with smtp (Tiscali http://www.tiscali.nl)
	id 1ILN1Y-0002r9-Dh
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 15 Aug 2007 19:51:16 +0200
Received: (qmail 50828 invoked from network); 15 Aug 2007 17:51:11 -0000
Received: from localhost (HELO guido.klop.ws) (127.0.0.1)
  by localhost with SMTP; 15 Aug 2007 17:51:11 -0000
Message-Id: <1187200271.50815@guido.klop.ws>
Date: Wed, 15 Aug 2007 19:51:11 +0200
From: "Ronald Klop" <ronald-freebsd8@klop.yi.org>
To: "FreeBSD gnats submit" <FreeBSD-gnats-submit@freebsd.org>
Cc: ronald-freebsd8@klop.yi.org
Subject: jdk1.6.0: Runtime.exec(...) fails always
X-Send-Pr-Version: gtk-send-pr 0.4.8 
X-GNATS-Notify:

>Number:         115557
>Category:       java
>Synopsis:       jdk1.6.0: Runtime.exec(...) fails always
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    glewis
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Aug 15 18:10:00 GMT 2007
>Closed-Date:    Tue Aug 28 15:30:02 GMT 2007
>Last-Modified:  Tue Aug 28 15:40:01 GMT 2007
>Originator:     Ronald Klop
>Release:        FreeBSD 6.2-STABLE i386
>Organization:
>Environment:


System: FreeBSD 6.2-STABLE #29: Sat Jul 14 14:44:18 CEST 2007
    root@guido.klop.ws:/usr/obj/usr/src/sys/GUIDO



>Description:


When I run this programm, I always get exitCode == 255.
$ java -version
java version "1.6.0_01-p1"
Java(TM) SE Runtime Environment (build 1.6.0_01-p1-root_12_aug_2007_22_50-b00)
Java HotSpot(TM) Client VM (build 1.6.0_01-p1-root_12_aug_2007_22_50-b00, mixed mode)
$ uname -a
FreeBSD ronald.office.base.nl 6.2-STABLE FreeBSD 6.2-STABLE #74: Sat Jul 14 13:11:40 CEST 2007     root@ronald.office.base.nl:/usr/obj/usr/src/sys/RONALD  i386
 
I found it with other code, but this is my small testcase to reproduce it.



>How-To-Repeat:


Compile and run this java programm.

import java.io.IOException;
 
final class ExecTest {
 
    public static void main(String[] args) throws IOException, InterruptedException {
        Runtime rt = Runtime.getRuntime();
        Process p = rt.exec("/bin/ls");
        int exitCode = p.waitFor();
        System.out.println("ExitCode: " + exitCode);
    }
 
}



>Fix:





>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-java->glewis 
Responsible-Changed-By: glewis 
Responsible-Changed-When: Wed Aug 15 20:34:45 UTC 2007 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=115557 

From: Michiel Boland <michiel@boland.org>
To: Ronald Klop <ronald-freebsd8@klop.yi.org>
Cc: bug-followup@FreeBSD.org, freebsd-java@FreeBSD.org
Subject: Re: java/115557: jdk1.6.0: Runtime.exec(...) fails always
Date: Mon, 27 Aug 2007 21:50:40 +0200 (MEST)

 In jdk 1.6 there is some magic performed via file descriptor 3 in 
 j2se/src/solaris/native/java/lang/UNIXProcess_md.c that was not in jdk15. 
 The problem is that the closeDescriptors() function in the patchset was 
 not updated to take this into account.
 
 diff -ur bsd-jdk16-patches-1.orig/jdk16.patches bsd-jdk16-patches-1/jdk16.patches
 --- bsd-jdk16-patches-1.orig/jdk16.patches	2007-07-24 09:05:48.000000000 +0200
 +++ bsd-jdk16-patches-1/jdk16.patches	2007-08-27 20:44:20.000000000 +0200
 @@ -80764,7 +80764,7 @@
   +static int
   +closeDescriptors(void)
   +{
 -+	return _thread_sys_closefrom(3);
 ++	return _thread_sys_closefrom(FAIL_FILENO + 1);
   +}
   +
   +#elif defined(_ALLBSD_SOURCE)
 @@ -80782,7 +80782,7 @@
   +    /*
   +     * BSDNOTE: There's no known way to find list of all open file descriptors
   +     * associated with process in FreeBSD.  Therefore we have to pass from
 -+     * fd == 3 to maximum fd per process number.  It's possible to retrive
 ++     * fd == FAIL_FILENO + 1 to maximum fd per process number.  It's possible to retrive
   +     * max number of fd's with three ways: sysctl(kern.maxfilesperproc),
   +     * getrlimit(RLIMIT_NOFILE) and getdtablesize().  In current implementation
   +     * getdtablesize() returns MIN() of first two ways.
 @@ -80797,7 +80797,7 @@
   +    max_fd = getdtablesize();
   +    ebadf = 0;
   +
 -+    for (i = 3; i < max_fd; i++) {
 ++    for (i = FAIL_FILENO + 1; i < max_fd; i++) {
   +	if (close(i) < 0) { ebadf++; } else { ebadf = 0; }
   +	/*
   +         * GUESS_FINISHED subsequent calls to close() returned EBADF, assume
State-Changed-From-To: open->closed 
State-Changed-By: glewis 
State-Changed-When: Tue Aug 28 15:29:30 UTC 2007 
State-Changed-Why:  
Thanks, Michiel!  I've committed your patch. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=115557 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: java/115557: commit references a PR
Date: Tue, 28 Aug 2007 15:24:37 +0000 (UTC)

 glewis      2007-08-28 15:24:32 UTC
 
   FreeBSD ports repository
 
   Modified files:
     java/jdk16           Makefile 
   Added files:
     java/jdk16/files     patch-j2se-lang-UNIXProcess_md.c 
   Log:
   . Sync the BSD specific code with the changes between 1.5 and 1.6 and
     start closing file descriptors at FAIL_FILENO + 1 rather than 3.  This
     fixes the problem with determining the exit code for exec()'ed processes.
   
   PR:             115557
   Submitted by:   Michiel Boland <michiel@boland.org>
   
   Revision  Changes    Path
   1.144     +1 -1      ports/java/jdk16/Makefile
   1.1       +31 -0     ports/java/jdk16/files/patch-j2se-lang-UNIXProcess_md.c (new)
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
