File tree Expand file tree Collapse file tree 4 files changed +34
-14
lines changed
Expand file tree Collapse file tree 4 files changed +34
-14
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,14 @@ repository = "https://gitee.com/seeker_rs/mysql-audit-extend"
1111# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212
1313[dependencies ]
14- daemonize = " 0.4.1"
15- users = " 0.11.0"
1614rcron = " 1.2.1"
1715clap = { version = " 3.2.16" , features = [" derive" ] }
1816anyhow = " 1.0.61"
1917chrono = " 0.4.21"
2018rust_decimal = " 1.25.0"
2119log = " 0.4.14"
22- simple_logger = " 2.1.0"
20+ simple_logger = " 2.1.0"
21+
22+ [target .'cfg(unix)' .dependencies ]
23+ daemonize = " 0.4.1"
24+ users = " 0.11.0"
Original file line number Diff line number Diff line change 1+ #[ cfg( target_family = "unix" ) ]
12use crate :: tasks:: start_backstage_task;
3+ #[ cfg( target_family = "unix" ) ]
24use daemonize:: Daemonize ;
5+ #[ cfg( target_family = "unix" ) ]
36use std:: fs;
7+ #[ cfg( target_family = "unix" ) ]
48use std:: fs:: File ;
59
10+ #[ cfg( target_family = "unix" ) ]
611pub fn daemonize (
712 username : & str ,
813 pkg_name : & str ,
Original file line number Diff line number Diff line change 1+ #[ cfg( target_family = "unix" ) ]
12use users:: { get_current_uid, get_user_by_uid} ;
23
4+ #[ cfg( target_family = "unix" ) ]
35pub fn get_current_user ( ) -> String {
46 let user = get_user_by_uid ( get_current_uid ( ) ) . unwrap ( ) ;
57 let username = user. name ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
Original file line number Diff line number Diff line change 1+ #[ cfg( target_family = "unix" ) ]
12mod daemon_util;
3+ #[ cfg( target_family = "unix" ) ]
24mod libc_util;
35mod tasks;
46
57use anyhow:: Result ;
68use clap:: Parser ;
79use std:: fs;
10+ use crate :: tasks:: start_backstage_task;
811
912/// An extension tool of mysql-audit, which provides functions such as log rotation and log cleaning.
1013#[ derive( Parser , Debug ) ]
@@ -39,20 +42,28 @@ fn main() -> Result<()> {
3942
4043 init_log ( ) ;
4144
42- let username = libc_util:: get_current_user ( ) ;
43- let pkg_name = env ! ( "CARGO_PKG_NAME" ) ;
44- let author_name = env ! ( "CARGO_PKG_AUTHORS" ) ;
4545 let path: String = options. path ;
4646 let max_size: u32 = options. max_size ;
4747 let max_file: u32 = options. max_file ;
48- daemon_util:: daemonize (
49- username. as_str ( ) ,
50- pkg_name,
51- author_name,
52- path,
53- max_size,
54- max_file,
55- ) ;
48+
49+ if cfg ! ( target_family = "unix" ) {
50+ #[ cfg( target_family = "unix" ) ]
51+ {
52+ let username = libc_util:: get_current_user ( ) ;
53+ let pkg_name = env ! ( "CARGO_PKG_NAME" ) ;
54+ let author_name = env ! ( "CARGO_PKG_AUTHORS" ) ;
55+ daemon_util:: daemonize (
56+ username. as_str ( ) ,
57+ pkg_name,
58+ author_name,
59+ path,
60+ max_size,
61+ max_file,
62+ ) ;
63+ }
64+ } else {
65+ start_backstage_task ( path, max_size, max_file) ;
66+ }
5667
5768 Ok ( ( ) )
5869}
You can’t perform that action at this time.
0 commit comments