Skip to content

Commit

Permalink
Merge pull request #2150 from zowe/daemon-stderr-v3
Browse files Browse the repository at this point in the history
Display daemon messages on standard error
  • Loading branch information
gejohnston authored May 23, 2024
2 parents 136d110 + 80fe511 commit dbbd3ce
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 53 deletions.
6 changes: 5 additions & 1 deletion packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

All notable changes to the Zowe CLI package will be documented in this file.

## Recent Changes

- LTS Breaking: Send all Zowe Daemon informational messages, progress messages, and error messages to standard error instead of standard output [#1451](https://github.com/zowe/zowe-cli/issues/1451)

## `8.0.0-next.202405202020`

- BugFix: Fixed a bug where a data set search would not return a search term if it was at the beginning of a line. [#2147](https://github.com/zowe/zowe-cli/pull/2147)

## `8.0.0-next.202405101931`

- Enhancement: Added the ability to search for a string in a data set or PDS member matching a pattern with the `zowe zos-files search data-sets` comamnd.[#2095](https://github.com/zowe/zowe-cli/issues/2095)
- Enhancement: Added the ability to search for a string in a data set or PDS member matching a pattern with the `zowe zos-files search data-sets` command.[#2095](https://github.com/zowe/zowe-cli/issues/2095)

## `8.0.0-next.202405061946`

Expand Down
2 changes: 1 addition & 1 deletion zowex/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion zowex/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zowe"
version = "1.2.2"
version = "1.2.3"
authors = ["Zowe Project"]
edition = "2018"
license = "EPL-2.0"
Expand Down
18 changes: 9 additions & 9 deletions zowex/src/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
*/

// Functions related to daemon cummunication.
// Functions related to daemon communication.

use std::io;
use std::io::prelude::*;
Expand Down Expand Up @@ -96,11 +96,11 @@ pub async fn comm_establish_connection(
we_started_daemon = true;
cmd_to_show = proc_start_daemon(njs_zowe_path);
} else if we_started_daemon && conn_retries > THREE_MIN_OF_RETRIES {
println!(
eprintln!(
"The Zowe daemon that we started is not running on socket: {}.",
daemon_socket
);
println!(
eprintln!(
"Command used to start the Zowe daemon was:\n {}\nTerminating.",
cmd_to_show
);
Expand All @@ -115,7 +115,7 @@ pub async fn comm_establish_connection(
};

if conn_retries > 0 {
println!(
eprintln!(
"{} ({} of {})",
retry_msg, conn_retries, THREE_MIN_OF_RETRIES
);
Expand All @@ -124,7 +124,7 @@ pub async fn comm_establish_connection(
conn_retries += 1;

if conn_retries > THREE_MIN_OF_RETRIES {
println!(
eprintln!(
"Terminating after {} connection retries.",
THREE_MIN_OF_RETRIES
);
Expand All @@ -136,13 +136,13 @@ pub async fn comm_establish_connection(

// before we wait too long, show diagnostics
if conn_retries == RETRY_TO_SHOW_DIAG {
println!("\nThe Zowe daemon was started with these options:");
eprintln!("\nThe Zowe daemon was started with these options:");
if we_started_daemon {
println!("Command = {}", cmd_to_show);
eprintln!("Command = {}", cmd_to_show);
} else {
println!("Command = {}", daemon_proc_info.cmd);
eprintln!("Command = {}", daemon_proc_info.cmd);
}
println!(
eprintln!(
"Process name = {} pid = {} socket = {}\n",
daemon_proc_info.name, daemon_proc_info.pid, daemon_socket
);
Expand Down
14 changes: 7 additions & 7 deletions zowex/src/proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn read_pid_for_user() -> Option<sysinfo::Pid> {
Ok(ok_val) => ok_val,
Err(err_val) => {
// we should not continue if we cannot open an existing pid file
println!(
eprintln!(
"Unable to open file = {}\nDetails = {}",
pid_file_path.display(),
err_val
Expand All @@ -209,7 +209,7 @@ fn read_pid_for_user() -> Option<sysinfo::Pid> {
Ok(ok_val) => ok_val,
Err(err_val) => {
// we should not continue if we cannot read an existing pid file
println!(
eprintln!(
"Unable to read file = {}\nDetails = {}",
pid_file_path.display(),
err_val
Expand All @@ -222,7 +222,7 @@ fn read_pid_for_user() -> Option<sysinfo::Pid> {

if daemon_pid_for_user.user != executor {
// our pid file should only contain our own user name
println!(
eprintln!(
"User name of '{}' in file '{}' does not match current user = '{}'.",
daemon_pid_for_user.user,
pid_file_path.display(),
Expand Down Expand Up @@ -273,11 +273,11 @@ fn read_pid_for_user() -> Option<sysinfo::Pid> {
*/

pub fn proc_start_daemon(njs_zowe_path: &str) -> String {
println!("Starting a background process to increase performance ...");
eprintln!("Starting a background process to increase performance ...");

let daemon_arg = LAUNCH_DAEMON_OPTION;
let mut cmd = Command::new(njs_zowe_path);

// Uses creation flags from https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags
// Flags are CREATE_NO_WINDOW, CREATE_NEW_PROCESS_GROUP, and CREATE_UNICODE_ENVIRONMENT
#[cfg(target_family = "windows")]
Expand All @@ -291,11 +291,11 @@ pub fn proc_start_daemon(njs_zowe_path: &str) -> String {
{
Ok(_unused) => { /* nothing to do */ }
Err(error) => {
println!(
eprintln!(
"Failed to start the following process:\n {} {}",
njs_zowe_path, daemon_arg
);
println!("Due to this error:\n {}", error);
eprintln!("Due to this error:\n {}", error);
std::process::exit(EXIT_CODE_CANNOT_START_DAEMON);
}
};
Expand Down
54 changes: 27 additions & 27 deletions zowex/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ pub async fn run_zowe_command(zowe_cmd_args: &mut Vec<String>) -> Result<i32, i3
*/
pub async fn run_restart_command(njs_zowe_path: &str) -> Result<i32, i32> {
if proc_get_daemon_info().is_running {
println!("Shutting down the running daemon ...");
eprintln!("Shutting down the running daemon ...");
let mut restart_cmd_args: Vec<String> = vec![SHUTDOWN_REQUEST.to_string()];
if let Err(err_val) = run_daemon_command(njs_zowe_path, &mut restart_cmd_args).await {
println!("Unable to communicate a command to the Zowe daemon.");
eprintln!("Unable to communicate a command to the Zowe daemon.");
return Err(err_val);
}
}

// Start a new daemon. Note that proc_start_daemon() exits on failure.
proc_start_daemon(njs_zowe_path);
println!("A new daemon has started.");
eprintln!("A new daemon has started.");
Ok(EXIT_CODE_SUCCESS)
}

Expand Down Expand Up @@ -134,12 +134,12 @@ fn run_nodejs_command(njs_zowe_path: &str, zowe_cmd_args: &mut Vec<String>) -> R
{
Ok(new_proc) => new_proc.status.code().unwrap(),
Err(error) => {
println!("Failed to run the following command:");
println!(
eprintln!("Failed to run the following command:");
eprintln!(
" Program = {}\n arguments = {:?}",
njs_zowe_path, zowe_cmd_args
);
println!("Due to this error:\n {}", error);
eprintln!("Due to this error:\n {}", error);
EXIT_CODE_FAILED_TO_RUN_NODEJS_CMD
}
};
Expand Down Expand Up @@ -177,12 +177,12 @@ fn run_delayed_zowe_command(njs_zowe_path: &str, zowe_cmd_args: &[String]) -> Re
let (curr_cmd_shell, cmd_shell_nm) = match proc_get_cmd_shell() {
Ok((curr_cmd_shell, cmd_shell_nm)) => (curr_cmd_shell, cmd_shell_nm),
Err(error) => {
println!("{} Terminating.", error);
eprintln!("{} Terminating.", error);
return Err(EXIT_CODE_CANT_FIND_CMD_SHELL);
}
};
if matches!(curr_cmd_shell, CmdShell::Unknown) {
println!(
eprintln!(
"The command shell process named '{}' is unknown to the Zowe CLI. Terminating.",
cmd_shell_nm
);
Expand All @@ -205,9 +205,9 @@ fn run_delayed_zowe_command(njs_zowe_path: &str, zowe_cmd_args: &[String]) -> Re
);

// The following line gives useful debugging info when it is uncommented.
// println!("script_arg_vec = {:?}", script_arg_vec);
// eprintln!("script_arg_vec = {:?}", script_arg_vec);

println!(
eprintln!(
"The '{}' command will run in the background ...",
arg_vec_to_string(zowe_cmd_args)
);
Expand All @@ -220,12 +220,12 @@ fn run_delayed_zowe_command(njs_zowe_path: &str, zowe_cmd_args: &[String]) -> Re
{
Ok(..) => Ok(EXIT_CODE_SUCCESS),
Err(err_val) => {
println!("Failed to run the following command:");
println!(
eprintln!("Failed to run the following command:");
eprintln!(
" cmd_shell_to_launch = {}\n arguments = {:?}",
njs_zowe_path, zowe_cmd_args
);
println!("Due to this error:\n {}", err_val);
eprintln!("Due to this error:\n {}", err_val);
Err(EXIT_CODE_FAILED_TO_RUN_NODEJS_CMD)
}
};
Expand All @@ -252,15 +252,15 @@ pub async fn run_daemon_command(
let cwd: PathBuf = match env::current_dir() {
Ok(ok_val) => ok_val,
Err(err_val) => {
println!("Unable to get current directory\nDetails = {:?}", err_val);
eprintln!("Unable to get current directory\nDetails = {:?}", err_val);
return Err(EXIT_CODE_ENV_ERROR);
}
};

let mut stdin = Vec::new();
if !std::io::stdin().is_terminal() {
if let Err(err_val) = io::stdin().read_to_end(&mut stdin) {
println!("Failed reading stdin\nDetails = {}", err_val);
eprintln!("Failed reading stdin\nDetails = {}", err_val);
return Err(EXIT_CODE_COMM_IO_ERROR);
}
}
Expand Down Expand Up @@ -301,7 +301,7 @@ pub async fn run_daemon_command(
}
}
Err(err_val) => {
println!("Failed convert response to JSON\nDetails = {}", err_val);
eprintln!("Failed to convert response to JSON\nDetails = {}", err_val);
return Err(EXIT_CODE_CANT_CONVERT_JSON);
}
}
Expand All @@ -323,15 +323,15 @@ pub async fn run_daemon_command(
match lock_file.try_lock() {
Ok(result) if !result => {
if tries > THREE_MIN_OF_RETRIES {
println!(
eprintln!(
"Terminating after {} connection retries.",
THREE_MIN_OF_RETRIES
);
return Err(EXIT_CODE_TIMEOUT_CONNECT_TO_RUNNING_DAEMON);
}

tries += 1;
println!(
eprintln!(
"The Zowe daemon is in use, retrying ({} of {})",
tries, THREE_MIN_OF_RETRIES
);
Expand All @@ -344,7 +344,7 @@ pub async fn run_daemon_command(
locked = true;
}
Err(ref e) => {
println!("Problem acquiring lock: {:?}", e);
eprintln!("Problem acquiring lock: {:?}", e);
return Err(EXIT_CODE_CANNOT_ACQUIRE_LOCK);
}
}
Expand All @@ -354,7 +354,7 @@ pub async fn run_daemon_command(
match comm_establish_connection(njs_zowe_path, &socket_string).await {
Ok(ok_val) => stream = ok_val,
Err(err_val) => {
println!(
eprintln!(
"Unable to establish communication with daemon.\nDetails = {}",
err_val
);
Expand All @@ -369,23 +369,23 @@ pub async fn run_daemon_command(
Err(ref err_val) => {
if err_val.kind() == io::ErrorKind::ConnectionReset {
if tries > THREE_MIN_OF_RETRIES {
println!(
eprintln!(
"Terminating after {} connection retries.",
THREE_MIN_OF_RETRIES
);
return Err(EXIT_CODE_TIMEOUT_CONNECT_TO_RUNNING_DAEMON);
}

tries += 1;
println!(
eprintln!(
"The Zowe daemon is in use, retrying ({} of {})",
tries, THREE_MIN_OF_RETRIES
);

// pause between attempts to connect
thread::sleep(Duration::from_secs(THREE_SEC_DELAY));
} else {
println!(
eprintln!(
"I/O error during daemon communication.\nDetails = {}",
err_val
);
Expand Down Expand Up @@ -648,21 +648,21 @@ fn get_win_lock_file() -> Result<LockFile, i32> {
lock_path.push("daemon.lock");

if let Err(err_val) = File::create(&lock_path) {
println!(
eprintln!(
"Unable to create zowe daemon lock file = {}.",
&lock_path.display()
);
println!("Reason = {}.", err_val);
eprintln!("Reason = {}.", err_val);
return Err(EXIT_CODE_FILE_IO_ERROR);
}
let lock_file: LockFile = match LockFile::open(&lock_path) {
Ok(ok_val) => ok_val,
Err(err_val) => {
println!(
eprintln!(
"Unable to open zowe daemon lock file = {}.",
&lock_path.display()
);
println!("Reason = {}.", err_val);
eprintln!("Reason = {}.", err_val);
return Err(EXIT_CODE_FILE_IO_ERROR);
}
};
Expand Down
14 changes: 7 additions & 7 deletions zowex/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn util_get_nodejs_zowe_path() -> String {
*/
let my_exe_result = env::current_exe();
if my_exe_result.is_err() {
println!("Unable to get path to my own executable. Terminating.");
eprintln!("Unable to get path to my own executable. Terminating.");
std::process::exit(EXIT_CODE_CANNOT_GET_MY_PATH);
}
let my_exe_path_buf = my_exe_result.unwrap();
Expand Down Expand Up @@ -73,8 +73,8 @@ pub fn util_get_nodejs_zowe_path() -> String {
break;
}
if njs_zowe_path == NOT_FOUND {
println!("Could not find a NodeJS zowe command on your path.");
println!("Will not be able to run Zowe commands. Terminating.");
eprintln!("Could not find a NodeJS zowe command on your path.");
eprintln!("Will not be able to run Zowe commands. Terminating.");
std::process::exit(EXIT_CODE_NO_NODEJS_ZOWE_ON_PATH);
}

Expand All @@ -96,7 +96,7 @@ pub fn util_get_daemon_dir() -> Result<PathBuf, i32> {
match home_dir() {
Some(path_buf_val) => daemon_dir = path_buf_val,
None => {
println!("Unable to get user's home directory.");
eprintln!("Unable to get user's home directory.");
return Err(EXIT_CODE_ENV_ERROR);
}
}
Expand All @@ -106,11 +106,11 @@ pub fn util_get_daemon_dir() -> Result<PathBuf, i32> {

if !daemon_dir.exists() {
if let Err(err_val) = std::fs::create_dir_all(&daemon_dir) {
println!(
eprintln!(
"Unable to create zowe daemon directory = {}.",
&daemon_dir.display()
);
println!("Reason = {}.", err_val);
eprintln!("Reason = {}.", err_val);
return Err(EXIT_CODE_FILE_IO_ERROR);
}
}
Expand Down Expand Up @@ -178,6 +178,6 @@ pub fn util_terminal_supports_color() -> i32 {
return 1;
}
}

0
}

0 comments on commit dbbd3ce

Please sign in to comment.