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
|
|
@ -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…
Add table
Add a link
Reference in a new issue