feat: use /run/user to store socket and pid file
This commit is contained in:
parent
0727b3e053
commit
67b3be4c4a
5 changed files with 20 additions and 4 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -621,9 +621,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.146"
|
||||
version = "0.2.147"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b"
|
||||
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
|
@ -1134,6 +1134,7 @@ dependencies = [
|
|||
"clap",
|
||||
"daemonize",
|
||||
"humantime",
|
||||
"libc",
|
||||
"notify-rust",
|
||||
"serde",
|
||||
"serde_cbor",
|
||||
|
|
|
@ -10,6 +10,7 @@ anyhow = "1.0.71"
|
|||
clap = { version = "4.3.4", features = ["derive"] }
|
||||
daemonize = "0.5.0"
|
||||
humantime = "2.1.0"
|
||||
libc = "0.2.147"
|
||||
notify-rust = "4.8.0"
|
||||
serde = { version = "1.0.164", features = ["derive"] }
|
||||
serde_cbor = "0.11.2"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::daemon::{Answer, AnswerErr, Command as OtherCommand};
|
||||
use crate::run_path;
|
||||
use anyhow::{Context, Result};
|
||||
use clap::{Parser, Subcommand};
|
||||
use std::net::Shutdown;
|
||||
|
@ -12,7 +13,7 @@ pub struct Cli {
|
|||
#[command(subcommand)]
|
||||
pub command: Command,
|
||||
#[arg(short, long)]
|
||||
#[clap(default_value = "/tmp/timers.socket")]
|
||||
#[clap(default_value_t = format!("{}/timers.socket", run_path()))]
|
||||
pub socket: String,
|
||||
}
|
||||
|
||||
|
|
7
src/helper.rs
Normal file
7
src/helper.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
pub fn getuid() -> u32 {
|
||||
unsafe { libc::getuid() }
|
||||
}
|
||||
|
||||
pub fn run_path() -> String {
|
||||
format!("/run/user/{}", getuid())
|
||||
}
|
|
@ -1,11 +1,14 @@
|
|||
mod cli;
|
||||
mod daemon;
|
||||
mod helper;
|
||||
mod notification;
|
||||
mod pomodoro;
|
||||
mod timer;
|
||||
|
||||
use crate::helper::getuid;
|
||||
use crate::cli::{send_command, Cli, Command as CliCommand};
|
||||
use crate::daemon::{Command as DaemonCommand, Daemon};
|
||||
use crate::helper::run_path;
|
||||
use clap::Parser;
|
||||
use cli::PomodoroCommand;
|
||||
|
||||
|
@ -13,7 +16,10 @@ fn main() -> Result<(), anyhow::Error> {
|
|||
let args = Cli::parse();
|
||||
let daemon_command = match args.command {
|
||||
CliCommand::Daemon { no_notify } => {
|
||||
daemonize::Daemonize::new().start()?;
|
||||
daemonize::Daemonize::new()
|
||||
.pid_file(format!("{}/timers.pid", run_path()))
|
||||
.user(getuid())
|
||||
.start()?;
|
||||
return Daemon::new(args.socket, no_notify)?.run();
|
||||
}
|
||||
CliCommand::Add { name, duration } => {
|
||||
|
|
Loading…
Reference in a new issue