----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files.  Don't make us guess your problem!!!
----------------------------------------------------------------

Hello,

I am trying to use a Runtime.exec() call from within a servlet, and it
promptly dies with a "500 - internal server error" message. It seems to die
right where it calls Runtime.exec(). 

Naturally, any suggestions are appreciated.

   Thanks,
   Tim
   


First, the rough details:
 ===========================================================================

  JServ:  Apache JServ 1.1b3 - 25 October 1999
  Apache: 1.3
  JVM:    JDK 1.1.8 IBM build l118-19991013 (JIT disabled)
  OS:     Linux x86 (Debian "potato")  kernel 2.2.10

 ===========================================================================
Next, the error log:

SIGSEGV received at bebff908 in 
/usr/lib/ibm-java/jdk118/lib/linux/native_threads/libjava.so. Processing terminated
java full version "JDK 1.1.8 IBM build l118-19991013 (JIT disabled)"
args: /usr/lib/ibm-java/jdk118/bin/linux/native_threads/java -nojit 
org/apache/jserv/JServ /etc/jserv/jserv.properties

Operating Environment
---------------------
Host            : goibniu.(none)
OS Level        : 2.2.10.#9 Wed Aug 11 13:09:41 CDT 1999
glibc Version   : 2.1.2
No. of Procs    : 1
Memory Info:
        total:    used:    free:  shared: buffers:  cached:
Mem:  64700416 63762432   937984 22634496  1339392 15028224
Swap: 57798656 17817600 39981056
MemTotal:     63184 kB
MemFree:        916 kB
MemShared:    22104 kB
Buffers:       1308 kB
Cached:       14676 kB
SwapTotal:    56444 kB
SwapFree:     39044 kB

Application Environment
-----------------------
Signal Handlers -
        SIGQUIT         : ignored
        SIGILL          : sysThreadIDump (libjava.so)
        SIGABRT         : sysThreadIDump (libjava.so)
        SIGFPE          : sysThreadIDump (libjava.so)
        SIGBUS          : sysThreadIDump (libjava.so)
        SIGSEGV         : sysThreadIDump (libjava.so)
        SIGPIPE         : ignored
        SIGUSR1         : doSuspendLoop (libjava.so)

Environment Variables -
        PWD=/
        HOSTNAME=goibniu
        LD_LIBRARY_PATH=/usr/lib/ibm-java/jdk118/lib/linux/native_threads:
        
CLASSPATH=/usr/lib/jdk1.1/lib/classes.zip:/usr/share/java/ApacheJServ.jar:/usr/share/java/servlet-2.0.jar:/usr/share/java/gnujsp.jar:/usr/lib/ibm-java/jdk118/classes:/usr/lib/ibm-java/jdk118/lib/classes.jar:/usr/lib/ibm-java/jdk118/lib/rt.jar:/usr/lib/ibm-java/jdk118/lib/i18n.jar:/usr/lib/ibm-java/jdk118/lib/classes.zip
        MACHTYPE=i486-pc-linux-gnu
        JAVA_HOME=/usr/lib/ibm-java/jdk118
        SHLVL=0
        SHELL=/bin/sh
        HOSTTYPE=i486
        OSTYPE=linux-gnu
        TERM=dumb
        PATH=/bin:/usr/bin:/usr/local/bin


Current Thread Details
----------------------
    "Thread-12" (TID:0x401f5fd0, sys_thread_t:0x815af70)
    Native Thread State: ThreadID: 00001c08 Reuse: 1 DAEMON  RUNNING
    Native Stack Data  : base: bebffd00 pointer bebc0954 used(258988) free(-11180)
        ----- Monitors held -----
        ----- Native stack -----
        Java_java_lang_UNIXProcess_forkAndExec_stub
        invokeNativeMethod
        invokeLazyNativeMethod
        __irem_trap5
        ------ Java stack ------        () prio=5 *current thread*
        java.lang.UNIXProcess.<init>(UNIXProcess.java)
----------------------------------------------------------------------


Total Thread Count:     9
Active Thread Count:    9
JNI Thread Count:       0

Full thread dump:
    "process reaper" (TID:0x401f5f98, sys_thread_t:0x8182610)
    Native Thread State: ThreadID: 00002009 Reuse: 1 DAEMON  SUSPENDED
    Native Stack Data  : base: be9ffd00 pointer be9ff8fc used(1028) free(246780)
        ----- Monitors held -----
        ----- Native stack -----
        __pthread_mutex_unlock
        pthread_cond_wait
        sysThread_shell
        pthread_detach
        __clone
        ------ Java stack ------        () prio=5
----------------------------------------------------------------------

    "Thread-12" (TID:0x401f5fd0, sys_thread_t:0x815af70)
    Native Thread State: ThreadID: 00001c08 Reuse: 1 DAEMON  RUNNING
    Native Stack Data  : base: bebffd00 pointer bebc0948 used(259000) free(-11192)
        ----- Monitors held -----
        ----- Native stack -----
        Java_java_lang_UNIXProcess_forkAndExec_stub
        invokeNativeMethod
        invokeLazyNativeMethod
        __irem_trap5
        ------ Java stack ------        () prio=5 *current thread*
        java.lang.UNIXProcess.<init>(UNIXProcess.java)
----------------------------------------------------------------------

    "Thread-10" (TID:0x401f6048, sys_thread_t:0x812bcb8)
    Native Thread State: ThreadID: 00001807 Reuse: 6 DAEMON  SUSPENDED
    Native Stack Data  : base: bedffd00 pointer bedfd78c used(9588) free(238220)
        ----- Monitors held -----
        ----- Native stack -----
        pthread_cond_wait
        java_lang_Runtime_execInternal
        Java_java_lang_Runtime_execInternal_stub
        invokeNativeMethod
        invokeLazyNativeMethod
        __irem_trap5
        ------ Java stack ------        () prio=5
        java.lang.Runtime.exec(Runtime.java)
        java.lang.Runtime.exec(Runtime.java)
        test002.doGet(test002.java:30)
        javax.servlet.http.HttpServlet.service(HttpServlet.java)
        javax.servlet.http.HttpServlet.service(HttpServlet.java)
        org.apache.jserv.JServConnection.processRequest(JServConnection.java:314)
        org.apache.jserv.JServConnection.run(JServConnection.java:188)
        java.lang.Thread.run(Thread.java)
----------------------------------------------------------------------

    "Thread-4" (TID:0x401f6198, sys_thread_t:0x814ffc0)
    Native Thread State: ThreadID: 00001406 Reuse: 1 DAEMON  MONITOR WAIT
    Native Stack Data  : base: befffd00 pointer befff9e0 used(800) free(247008)
        ----- Monitors held -----
        ----- Native stack -----
        sysMonitorWait
        sysThreadSleep
        threadSleep
        java_lang_Thread_sleep
        Java_java_lang_Thread_sleep_stub
        invokeNativeMethod
        __irem_trap5
        ------ Java stack ------        () prio=5
        org.apache.jserv.JServServletManager.run(JServServletManager.java:998)
        java.lang.Thread.run(Thread.java)
----------------------------------------------------------------------

    "Thread-3" (TID:0x401f61d0, sys_thread_t:0x814add8)
    Native Thread State: ThreadID: 00001005 Reuse: 1 DAEMON  MONITOR WAIT
    Native Stack Data  : base: bf1ffd00 pointer bf1ff9c4 used(828) free(246980)
        ----- Monitors held -----
        ----- Native stack -----
        sysMonitorWait
        sysThreadSleep
        threadSleep
        java_lang_Thread_sleep
        Java_java_lang_Thread_sleep_stub
        invokeNativeMethod
        invokeLazyNativeMethod
        __irem_trap5
        ------ Java stack ------        () prio=5
        org.apache.jserv.JServServletManager.run(JServServletManager.java:998)
        java.lang.Thread.run(Thread.java)
----------------------------------------------------------------------

    "Thread-2" (TID:0x401f6208, sys_thread_t:0x812c3e0)
    Native Thread State: ThreadID: 00000c04 Reuse: 1 DAEMON  MONITOR WAIT
    Native Stack Data  : base: bf3ffd00 pointer bf3ffa3c used(708) free(247100)
        ----- Monitors held -----
        ----- Native stack -----
        sysMonitorWait
        monitorWait - waiting on org.apache.java.util.SimpleQueue@401fb658
        java_lang_Object_wait
        Java_java_lang_Object_wait_stub
        invokeNativeMethod
        __irem_trap5
        ------ Java stack ------        () prio=1
        java.lang.Object.wait(Object.java)
        org.apache.java.util.SimpleQueue.waitObject(SimpleQueue.java:117)
        org.apache.java.io.LogWriter$Agent.run(LogWriter.java:427)
----------------------------------------------------------------------

    "Async Garbage Collector" (TID:0x401f6280, sys_thread_t:0x80a04b8)
    Native Thread State: ThreadID: 00000803 Reuse: 1 DAEMON  SUSPENDED
    Native Stack Data  : base: bf5ffd00 pointer bf5ffa30 used(720) free(247088)
        ----- Monitors held -----
        ----- Native stack -----
        sysMonitorWait
        sysThreadSleep
        threadSleep
        SetOrigArgs
        sysThread_shell
        pthread_detach
        __clone
        ------ Java stack ------        () prio=1
----------------------------------------------------------------------

    "Finalizer thread" (TID:0x401f62b8, sys_thread_t:0x80a0238)
    Native Thread State: ThreadID: 00000402 Reuse: 1 DAEMON  MONITOR WAIT
    Native Stack Data  : base: bf7ffd00 pointer bf7ffb68 used(408) free(247400)
        ----- Monitors held -----
        ----- Native stack -----
        sysMonitorWait - waiting on Finalize me queue lock
        finalizeOnExit
        sysThread_shell
        pthread_detach
        __clone
        ------ Java stack ------        () prio=1
----------------------------------------------------------------------

    "main" (TID:0x401f62f0, sys_thread_t:0x804a7a0)
    Native Thread State: ThreadID: 00000400 Reuse: 1 USER PRIMORDIAL SUSPENDED
    Native Stack Data  : base: bffffaa0 pointer bffff60c used(1172) free(246636)
        ----- Monitors held -----
        java.net.PlainSocketImpl@4025a5a8
        ----- Native stack -----
        sysAcceptFD - FD: 13
        java_net_PlainSocketImpl_socketAccept
        Java_java_net_PlainSocketImpl_socketAccept_stub
        __irem_trap5
        ------ Java stack ------        () prio=5
        java.net.PlainSocketImpl.accept(PlainSocketImpl.java:379)
        java.net.ServerSocket.implAccept(ServerSocket.java:198)
        java.net.ServerSocket.accept(ServerSocket.java:181)
        
org.apache.java.net.AuthenticatedServerSocket.accept(AuthenticatedServerSocket.java:159)
        org.apache.jserv.JServ.main(JServ.java:174)
----------------------------------------------------------------------


System Monitor Status
---------------------
    Verifier lock:     unowned.
    Thread queue lock:     unowned.
    Name and type hash table lock:     unowned.
    String intern lock:     unowned.
    JNI pinning lock:     unowned.
    JNI global reference lock:     unowned.
    Zip lock:     unowned.
    BinClass lock:     unowned.
    Class loading lock:     unowned.
    Java stack lock:     unowned.
    Code rewrite lock:     unowned.
    Heap Lock:     unowned.
    Has finalization queue lock:     unowned.
    Finalize me queue lock:     unowned.
    Integer lock access-lock:     unowned.
    Monitor cache lock:     unowned.
    Monitor registry:     unowned.

Object Monitor Status
---------------------
org.apache.java.util.SimpleQueue@401fb658: unowned
                "Thread-2" (0x401f6208) waiting
java.net.PlainSocketImpl@4025a5a8: owner: "main"
org.apache.java.util.SimpleQueue@401fb658: unowned
                "Thread-2" (0x401f6208) waiting
java.net.PlainSocketImpl@4025a5a8: owner: "main"
OK
[Wed Nov 17 15:23:59 1999] [error] [client 127.0.0.1] Premature end of script headers: 
/devel/test002
[Wed Nov 17 15:23:59 1999] [emerg] JServ: ajp12[1]: cannot scan servlet headers  (500)
[Wed Nov 17 15:23:59 1999] [error] JServ: an error returned handling request via 
protocol "ajpv12"

 ===========================================================================
Next, my JServ config:

###############################################################################
#                     Apache JServ Configuration File                         #
###############################################################################

# Whether Apache must start Apache JServ or not (On=Manual Off=Autostart)
# Syntax: ApJServManual [on/off]
# Default: "Off"
ApJServManual Off

# Properties filename for Apache JServ in Automatic Mode. 
# In manual mode this directive is ignored
# Syntax: ApJServProperties [filename]
# Default: "./conf/jserv.properties"
ApJServProperties /etc/jserv/jserv.properties

# Log file for this module operation relative to Apache root directory.
# Set the name of the trace/log file.  To avoid possible confusion about
# the location of this file, an absolute pathname is recommended.
# 
# This log file is different than the log file that is in the
# jserv.properties file. This is the log file for the C portion of Apache
# JServ.
# 
# On Unix, this file must have write permissions by the owner of the JVM
# process. In other words, if you are running Apache JServ in manual mode
# and Apache is running as user nobody, then the file must have its
# permissions set so that that user can write to it.
# Syntax: ApJServLogFile [filename] 
# Default: "./logs/mod_jserv.log"
# Note: when set to "DISABLED", the log will be redirected to Apache error log
# Debian note: DO NOT SET THIS OPTION HERE - use /etc/apache/httpd.conf!
#ApJServLogFile DISABLED

# Log Level for this module
# Syntax: ApJServLogLevel [debug|info|notice|warn|error|crit|alert|emerg]
# Default: info    (unless compiled w/ JSERV_DEBUG, in which case it's debug)
ApJServLogLevel notice

# Protocol used by this host to connect to Apache JServ
# (see documentation for more details on available protocols)
# Syntax: ApJServDefaultProtocol [name]
# Default: "ajpv12"
ApJServDefaultProtocol ajpv12

# Default host on which Apache JServ is running
# Syntax: ApJServDefaultHost [hostname]
# Default: "localhost"
#ApJServDefaultHost java.apache.org

# Default port that Apache JServ is listening to
# Syntax: ApJServDefaultPort [number]
# Default: protocol-dependant (for ajpv12 protocol this is "8007")
ApJServDefaultPort 8007

# The amount of time to give to the JVM to start up as well
# as the amount of time to wait to ping the JVM to see if it
# is alive. Slow or heavily loaded machines might want to 
# increase this value.
# Default: 10 seconds
# ApJServVMTimeout 10

# Passes parameter and value to specified protocol.
# Syntax: ApJServProtocolParameter [name] [parameter] [value]
# Default: NONE
# Note: Currently no protocols handle this. Introduced for future protocols.

# Apache JServ secret key file relative to Apache root directory.
# Syntax: ApJServSecretKey [filename]
# Default: "./conf/jserv.secret.key"
# Warning: if authentication is DISABLED, everyone on this machine (not just
# this module) may connect to your servlet engine and execute servlet 
# bypassing web server restrictions. See the documentation for more information
ApJServSecretKey /etc/jserv/jserv.secret.key

# Mount point for Servlet zones
# (see documentation for more information on servlet zones)
# Syntax: ApJServMount [name] [jserv-url]
# Default: NONE
# Note: [name] is the name of the Apache URI path to mount jserv-url on
#       [jserv-url] is something like "protocol://host:port/zone"
#  If protocol, host or port are not specified, the values from 
#  "ApJServDefaultProtocol", "ApJServDefaultHost" or "ApJServDefaultPort" 
#  will be used. 
#  If zone is not specified, the zone name will be the first subdirectory of
#  the called servlet.
# Example: "ApJServMount /servlets /myServlets"
#  if user requests "http://host/servlets/TestServlet"
#  the servlet "TestServlet" in zone "myServlets" on default host
#  thru default protocol on defaul port will be requested
# Example: "ApJServMount /servlets ajpv12://localhost:8007"
#  if user requests "http://host/servlets/myServlets/TestServlet"
#  the servlet "TestServlet" in zone "myServlets" will be requested
# Example: "ApJServMount /servlets ajpv12://jserv.mydomain.com:15643/myServlets"
#  if user requests "http://host/servlets/TestServlet" the servlet 
#  "TestServlet" in zone "myServlets" on host "jserv.mydomain.com" using 
#  "ajpv12" protocol on port "15643" will be executed
ApJServMount /servlets /root
ApJServMount /servlet /root
ApJServMount /devel /devel
ApJServMount /coolservlets /devel

# Whether <VirtualHost> inherits base host mount points or not
# Syntax: ApJServMountCopy [on/off]
# Default: "On"
# Note: This directive is meaninful only when virtual hosts are being used
ApJServMountCopy on

# Executes a servlet passing filename with proper extension in PATH_TRANSLATED 
# property of servlet request.
# Syntax: ApJServAction [extension] [servlet-uri]
# Defaults: NONE
# Notes: This is used for external tools.
ApJServAction .jsp /servlets/org.gjt.jsp.JspServlet
#ApJServAction .gsp /servlets/com.bitmechanic.gsp.GspServlet
ApJServAction .jhtml /servlets/org.apache.servlet.ssi.SSI
#ApJServAction .xml /servlets/org.apache.cocoon.Cocoon

# Enable the Apache JServ status handler with the URL of 
# "http://servername/jserv/" (note the trailing slash!)
# Change the "deny" directive to restrict access to this status page.
<Location /jserv/>
  SetHandler jserv-status
  
  order deny,allow
  deny from all
  allow from all
</Location>

############################## W A R N I N G ##################################
# Remember to disable or otherwise protect the execution of the Apache JServ  #
# Status Handler (see right above) on a production environment since this may #
# give untrusted users the ability to obtain restricted information on your   #
# servlets and their initialization arguments such as JDBC passwords and      #
# other important information. The Apache JServ Status Handler should be      #
# accessible only by system administrators.                                   #
###############################################################################


 ===========================================================================

Finally, the offending code in question:

// package servlets;

/**
*
* @author
* @version
*/

import java.io.*;
import java.util.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import javax.servlet.*;
import javax.servlet.http.*;

public class test002 extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws 
ServletException, IOException
{
  res.setContentType("text/html");
  PrintWriter out = res.getWriter();
  out.println("<HTML>");
  out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>");
  out.println("<BODY>");
  out.println("Now trying to run an external process:<br>");
  String command = "/bin/uname";
  Runtime runtime = Runtime.getRuntime();
  Process proc = null;
  try
  {
    proc = runtime.exec(command);
    proc.waitFor();
    BufferedReader in = new BufferedReader(new 
InputStreamReader(proc.getInputStream()));
    String line = null;
    while ((line = in.readLine()) != null)
    {
      out.println(line + "<BR>");
    }

  }
  catch (Exception e)
  {
    out.println("Problem!!");
  }

  out.println(command);
  out.println("</BODY></HTML>");
}
}

 ===========================================================================


-- 
A language that doesn't have everything is actually easier to program
in than some that do.
                -- Dennis M. Ritchie


--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to