diff options
| author | Scott Lawrence <scott+git@ineffectivetheory.com> | 2024-11-27 22:49:58 -0700 |
|---|---|---|
| committer | Scott Lawrence <scott+git@ineffectivetheory.com> | 2024-11-27 22:49:58 -0700 |
| commit | 87298226d0033a2db699d5bb6b1e1dbd7960c04a (patch) | |
| tree | 243f1ad347fd7d4f6aff1656016679cc67a96033 | |
| parent | 3dd4c3c6f3c876a2128f0153794412d35a37f1bd (diff) | |
| download | varanus-87298226d0033a2db699d5bb6b1e1dbd7960c04a.tar.gz varanus-87298226d0033a2db699d5bb6b1e1dbd7960c04a.tar.bz2 varanus-87298226d0033a2db699d5bb6b1e1dbd7960c04a.zip | |
Removing socket on exit
| -rw-r--r-- | Cargo.lock | 26 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/forecast.rs | 24 | ||||
| -rw-r--r-- | src/main.rs | 23 |
4 files changed, 69 insertions, 5 deletions
@@ -122,6 +122,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] +name = "libc" +version = "0.2.166" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2ccc108bbc0b1331bd061864e7cd823c0cab660bbe6970e66e2c0614decde36" + +[[package]] name = "proc-macro2" version = "1.0.84" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -177,6 +183,25 @@ dependencies = [ ] [[package]] +name = "signal-hook" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -213,6 +238,7 @@ dependencies = [ "cty", "serde", "serde_json", + "signal-hook", ] [[package]] @@ -10,3 +10,4 @@ clap = { version = "4.5.4", features = ["derive"] } cty = { version = "0.2.2" } serde = { version = "1.0.203", features = ["derive"] } serde_json = { version = "1.0" } +signal-hook = "0.3.17" diff --git a/src/forecast.rs b/src/forecast.rs index e69de29..5a71665 100644 --- a/src/forecast.rs +++ b/src/forecast.rs @@ -0,0 +1,24 @@ +/* Varanus + * forecast.rs: lightweight time-series forecasting + * + * Copyright (c) 2024 Scott Lawrence. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +pub struct Forecast { +} + diff --git a/src/main.rs b/src/main.rs index fbb23e2..ccff659 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,10 +20,10 @@ /* TODO * - * Remove socket file when daemon exits. - * * Accept command-line arguments to query only part of JSON. (Maybe also a formatting string?) * + * Forecast + * */ use std::error; @@ -37,6 +37,9 @@ use std::time::{Duration,Instant,SystemTime}; use clap::Parser; use serde::{Serialize,Deserialize}; +use signal_hook::{consts::SIGINT, iterator::Signals}; + +mod forecast; #[derive(Default)] #[repr(C)] @@ -180,10 +183,20 @@ impl Listener { fn listen(&self) { let state_mutex = Arc::clone(&self.state); - let sfn = self.file.clone(); + let sfn1 = self.file.clone(); + let sfn2 = self.file.clone(); + spawn(move || { + match Signals::new([SIGINT]) { + Ok(mut signals) => for _sig in signals.forever() { + let _ = remove_file(&sfn1); + std::process::exit(0) + }, + Err(_) => () + } + }); spawn(move || { - let _ = remove_file(&sfn); - let listener = UnixListener::bind(sfn).unwrap(); + let _ = remove_file(&sfn2); + let listener = UnixListener::bind(sfn2).unwrap(); loop { match listener.accept() { Ok((mut socket,accept)) => { |
