Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch Ctrl-C and enable Ctrl-D #77

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ jobs:
build:
strategy:
matrix:
platform: [ ubuntu-latest, macos-latest, windows-latest ]
toolchain: [ stable, beta ]
include:
- toolchain: stable
check-fmt: true
runs-on: ubuntu-latest
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout source code
uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bitcoin = "0.29.0"
bitcoin-bech32 = "0.12"
bech32 = "0.8"
hex = "0.3"
libc = "0.2"

futures = "0.3"
chrono = "0.4"
Expand Down
11 changes: 10 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ pub(crate) async fn poll_for_user_input<E: EventHandler>(
inbound_payments: PaymentInfoStorage, outbound_payments: PaymentInfoStorage,
ldk_data_dir: String, network: Network,
) {
println!("LDK startup successful. To view available commands: \"help\".");
println!(
"LDK startup successful. Enter \"help\" to view available commands. Press Ctrl-D to quit."
);
println!("LDK logs are available at <your-supplied-ldk-data-dir-path>/.ldk/logs");
println!("Local Node ID is {}.", channel_manager.get_our_node_id());
loop {
Expand All @@ -158,6 +160,11 @@ pub(crate) async fn poll_for_user_input<E: EventHandler>(
break println!("ERROR: {e:#}");
}

if line.len() == 0 {
// We hit EOF / Ctrl-D
break;
}

let mut words = line.split_whitespace();
if let Some(word) = words.next() {
match word {
Expand Down Expand Up @@ -459,6 +466,7 @@ pub(crate) async fn poll_for_user_input<E: EventHandler>(
Err(e) => println!("ERROR: failed to send onion message: {:?}", e),
}
}
"quit" | "exit" => break,
_ => println!("Unknown command. See `\"help\" for available commands."),
}
}
Expand All @@ -479,6 +487,7 @@ fn help() {
println!("listpeers");
println!("signmessage <message>");
println!("sendonionmessage <node_id_1,node_id_2,..,destination_node_id>");
println!("quit")
}

fn node_info(channel_manager: &Arc<ChannelManager>, peer_manager: &Arc<PeerManager>) {
Expand Down
23 changes: 23 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,5 +775,28 @@ async fn start_ldk() {

#[tokio::main]
pub async fn main() {
#[cfg(not(target_os = "windows"))]
{
// Catch Ctrl-C with a dummy signal handler.
unsafe {
let mut new_action: libc::sigaction = core::mem::zeroed();
let mut old_action: libc::sigaction = core::mem::zeroed();

extern "C" fn dummy_handler(
_: libc::c_int, _: *const libc::siginfo_t, _: *const libc::c_void,
) {
}

new_action.sa_sigaction = dummy_handler as libc::sighandler_t;
new_action.sa_flags = libc::SA_SIGINFO;

libc::sigaction(
libc::SIGINT,
&new_action as *const libc::sigaction,
&mut old_action as *mut libc::sigaction,
);
}
}

start_ldk().await;
}