aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorScott Lawrence <scott+git@ineffectivetheory.com>2024-11-27 22:49:58 -0700
committerScott Lawrence <scott+git@ineffectivetheory.com>2024-11-27 22:49:58 -0700
commit87298226d0033a2db699d5bb6b1e1dbd7960c04a (patch)
tree243f1ad347fd7d4f6aff1656016679cc67a96033 /src
parent3dd4c3c6f3c876a2128f0153794412d35a37f1bd (diff)
downloadvaranus-87298226d0033a2db699d5bb6b1e1dbd7960c04a.tar.gz
varanus-87298226d0033a2db699d5bb6b1e1dbd7960c04a.tar.bz2
varanus-87298226d0033a2db699d5bb6b1e1dbd7960c04a.zip
Removing socket on exit
Diffstat (limited to 'src')
-rw-r--r--src/forecast.rs24
-rw-r--r--src/main.rs23
2 files changed, 42 insertions, 5 deletions
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)) => {