Bug 790859 - org.rhq.enterprise.client.ClientMain (remoting-cli) hangs if executed as a service or in the background
org.rhq.enterprise.client.ClientMain (remoting-cli) hangs if executed as a se...
Product: RHQ Project
Classification: Other
Component: CLI (Show other bugs)
Unspecified Unspecified
high Severity high (vote)
: ---
: RHQ 4.3.0
Assigned To: Lukas Krejci
Mike Foley
: NeedsTestCase
Depends On: 787322
Blocks: jon310-sprint11/rhq44-sprint11
  Show dependency treegraph
Reported: 2012-02-15 10:09 EST by Lukas Krejci
Modified: 2013-09-01 06:06 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 787322
Last Closed: 2013-09-01 06:06:18 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Lukas Krejci 2012-02-15 10:09:14 EST
+++ This bug was initially created as a clone of Bug #787322 +++

Description of problem:
CLI can not support non-interactive mode even when a script file or command is provided on the command-line. For example, if system attempts to execute a Remote CLI script as another user or attempts to execute a script as a forked or background process, the CLI script is not executed and the Java process hangs.

This is due to no stdin console. Even when non-interactive options are passed to the CLI, it still insists on an input device (terminal) being attached to the executing process.

Specifically, this is caused by the incorrect initialization of the ClientMain class. During initialization, command-line parameters are parsed and a decision is made to use interaction or non-interactive mode, however, regardless of the command-line arguments and decision, the initializer of ClientMain still sets up the interactive components of jline. Specifically, jline.ConsoleReader having a requirement to read from FileDescriptor.in which is not attached to an actual tty/stty when the JVM is executed as a service (su someuser -c '...') or in the background (java ... .ClientMain &).

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Execute CLI using -f argument with anything in it:
   ./rhq-cli.sh -u rhqadmin -p rhqadmin -s localhost -t 7080 -f does/not/matter &
Actual results:
JVM hangs and background process is 'stopped'

Expected results:
JVM should exit with error indicating file could not be found

--- Additional comment from loleary@redhat.com on 2012-02-03 19:11:06 EST ---

Thread dump from running process reveals the hung stack:

"main" prio=10 tid=0x00007f7354008800 nid=0x7270 runnable [0x00007f73591f3000]
   java.lang.Thread.State: RUNNABLE
	at java.io.FileInputStream.readBytes(Native Method)
	at java.io.FileInputStream.read(FileInputStream.java:236)
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
	- locked <0x00000000fe0a3968> (a java.io.BufferedInputStream)
	at jline.UnixTerminal.exec(UnixTerminal.java:303)
	at jline.UnixTerminal.exec(UnixTerminal.java:282)
	at jline.UnixTerminal.stty(UnixTerminal.java:273)
	at jline.UnixTerminal.initializeTerminal(UnixTerminal.java:89)
	at jline.Terminal.setupTerminal(Terminal.java:75)
	- locked <0x00000000ee250af8> (a java.lang.Class for jline.Terminal)
	at jline.Terminal.getTerminal(Terminal.java:26)
	at jline.ConsoleReader.<init>(ConsoleReader.java:191)
	at jline.ConsoleReader.<init>(ConsoleReader.java:186)
	at jline.ConsoleReader.<init>(ConsoleReader.java:174)
	at org.rhq.enterprise.client.ClientMain.<init>(ClientMain.java:149)
	at org.rhq.enterprise.client.ClientMain.main(ClientMain.java:103)

--- Additional comment from ccrouch@redhat.com on 2012-02-15 08:07:37 EST ---

Lukas, can you investigate this.
Comment 1 Lukas Krejci 2012-02-15 12:19:13 EST
master: http://git.fedorahosted.org/git/?p=rhq/rhq.git;a=commitdiff;h=11d405fe3de2c55d8d525d5fc736825e0dc8a67c
Author: Lukas Krejci <lkrejci@redhat.com>
Date:   Wed Feb 15 18:16:36 2012 +0100

    [BZ 790859] - Do not expect standard input when the CLI runs in non-interactive mode.
    * restore the printing out of the CLI version on startup
    * specifying only the "-v" option will yet again just print the version and exit
    * specifying an invalid port will cause the CLI to fail startup
Comment 2 Heiko W. Rupp 2013-09-01 06:06:18 EDT
Bulk closing of items that are on_qa and in old RHQ releases, which are out for a long time and where the issue has not been re-opened since.

Note You need to log in before you can comment on or make changes to this bug.