1919use std:: cell:: RefCell ;
2020use std:: fs;
2121use std:: io;
22- use std:: os:: unix:: fs:: PermissionsExt ;
2322use std:: path:: PathBuf ;
2423use std:: process:: exit;
2524use std:: rc:: Rc ;
@@ -54,8 +53,6 @@ use tar::Archive;
5453use tar:: Builder as TarBuilder ;
5554use tempfile:: TempDir ;
5655use tokio:: runtime:: Builder as TB ;
57- use uzers:: get_current_uid;
58- use uzers:: get_user_by_uid;
5956
6057mod exitstat;
6158#[ cfg( test) ]
@@ -331,13 +328,6 @@ pub enum Service {
331328 Off ,
332329}
333330
334- // Whether or not to redirect log to stderr on fs failure
335- #[ derive( PartialEq ) ]
336- pub enum RedirectLogOnFail {
337- On ,
338- Off ,
339- }
340-
341331fn bump_memlock_rlimit ( ) -> Result < ( ) > {
342332 // TODO(T78976996) remove the fbcode_gate once we can exit stats is
343333 // enabled for opensource
@@ -355,44 +345,6 @@ fn bump_memlock_rlimit() -> Result<()> {
355345 Ok ( ( ) )
356346}
357347
358- fn create_log_dir ( path : & PathBuf ) -> Result < ( ) > {
359- if path. exists ( ) && !path. is_dir ( ) {
360- bail ! ( "{} exists and is not a directory" , path. to_string_lossy( ) ) ;
361- }
362-
363- if !path. is_dir ( ) {
364- match fs:: create_dir_all ( path) {
365- Ok ( ( ) ) => { }
366- Err ( e) => {
367- bail ! (
368- "Failed to create dir {}: {}\n Try sudo." ,
369- path. to_string_lossy( ) ,
370- e
371- ) ;
372- }
373- }
374- }
375-
376- let dir = fs:: File :: open ( path) . unwrap ( ) ;
377- let mut perm = dir. metadata ( ) . unwrap ( ) . permissions ( ) ;
378-
379- if perm. mode ( ) & 0o777 != 0o777 {
380- perm. set_mode ( 0o777 ) ;
381- match dir. set_permissions ( perm) {
382- Ok ( ( ) ) => { }
383- Err ( e) => {
384- bail ! (
385- "Failed to set permissions on {}: {}" ,
386- path. to_string_lossy( ) ,
387- e
388- ) ;
389- }
390- }
391- }
392-
393- Ok ( ( ) )
394- }
395-
396348// Exitstat runs a bpf program that hooks into process exit events. This allows below to keep
397349// track of processes whose lifetimes are shorter than polling interval.
398350fn start_exitstat (
@@ -407,7 +359,7 @@ fn start_exitstat(
407359 . spawn ( move || {
408360 match exit_driver. drive ( ) {
409361 Ok ( _) => { }
410- Err ( e) => bpf_err_send. send ( e) . unwrap ( ) ,
362+ Err ( e) => bpf_err_send. send ( e) . expect ( "Failed to send error" ) ,
411363 } ;
412364 } )
413365 . expect ( "Failed to spawn thread" ) ;
@@ -605,24 +557,14 @@ pub fn run<F>(
605557 debug : bool ,
606558 below_config : & BelowConfig ,
607559 _service : Service ,
608- redirect : RedirectLogOnFail ,
609560 command : F ,
610561) -> i32
611562where
612563 F : FnOnce ( init:: InitToken , & BelowConfig , slog:: Logger , Receiver < Error > ) -> Result < ( ) > ,
613564{
614565 let ( err_sender, err_receiver) = channel ( ) ;
615- let mut log_dir = below_config. log_dir . clone ( ) ;
616- let user = get_user_by_uid ( get_current_uid ( ) ) . expect ( "Failed to get current user for logging" ) ;
617-
618- log_dir. push ( format ! ( "error_{}.log" , user. name( ) . to_string_lossy( ) ) ) ;
619-
620- if let Err ( e) = create_log_dir ( & below_config. log_dir ) {
621- eprintln ! ( "{:#}" , e) ;
622- return 1 ;
623- }
624-
625- let logger = logging:: setup ( init, log_dir, debug, redirect) ;
566+ let log_path = below_config. log_dir . join ( "below.log" ) ;
567+ let logger = logging:: setup ( init, log_path, debug) ;
626568 setup_log_on_panic ( logger. clone ( ) ) ;
627569
628570 match Signals :: new ( [ signal_hook:: consts:: SIGINT , signal_hook:: consts:: SIGTERM ] ) {
@@ -640,7 +582,9 @@ where
640582 }
641583 term_now = true ;
642584 error ! ( logger, "Stop signal received: {}, exiting." , signal) ;
643- err_sender. send ( anyhow ! ( StopSignal { signal } ) ) . unwrap ( ) ;
585+ err_sender
586+ . send ( anyhow ! ( StopSignal { signal } ) )
587+ . expect ( "Failed to send stop signal" ) ;
644588 }
645589 } )
646590 . expect ( "Failed to spawn thread" ) ;
@@ -731,7 +675,6 @@ fn real_main(init: init::InitToken) {
731675 debug,
732676 below_config,
733677 Service :: Off ,
734- RedirectLogOnFail :: On ,
735678 |_, below_config, logger, errs| {
736679 live (
737680 init,
@@ -763,7 +706,6 @@ fn real_main(init: init::InitToken) {
763706 debug,
764707 below_config,
765708 Service :: On ( * port) ,
766- RedirectLogOnFail :: Off ,
767709 |init, below_config, logger, errs| {
768710 record (
769711 init,
@@ -800,7 +742,6 @@ fn real_main(init: init::InitToken) {
800742 debug,
801743 below_config,
802744 Service :: Off ,
803- RedirectLogOnFail :: Off ,
804745 |_, below_config, logger, errs| {
805746 replay (
806747 logger,
@@ -834,7 +775,6 @@ fn real_main(init: init::InitToken) {
834775 debug,
835776 below_config,
836777 Service :: Off ,
837- RedirectLogOnFail :: Off ,
838778 |_, below_config, logger, _errs| {
839779 snapshot (
840780 logger,
@@ -858,7 +798,6 @@ fn real_main(init: init::InitToken) {
858798 debug,
859799 below_config,
860800 Service :: Off ,
861- RedirectLogOnFail :: Off ,
862801 |_, below_config, logger, _errs| dump_store ( logger, time, below_config, json) ,
863802 )
864803 }
@@ -884,7 +823,6 @@ fn real_main(init: init::InitToken) {
884823 debug,
885824 below_config,
886825 Service :: Off ,
887- RedirectLogOnFail :: Off ,
888826 |_, below_config, logger, _errs| {
889827 convert_store (
890828 logger,
@@ -918,7 +856,6 @@ fn real_main(init: init::InitToken) {
918856 debug,
919857 below_config,
920858 Service :: Off ,
921- RedirectLogOnFail :: Off ,
922859 |_, _below_config, logger, errs| {
923860 dump:: run ( logger, errs, store_dir, host, port, snapshot, cmd)
924861 } ,
@@ -961,7 +898,7 @@ fn replay(
961898 tarball. unpack ( & snapshot_dir) ?;
962899 // Find and append the name of the original snapshot directory
963900 for path in fs:: read_dir ( & snapshot_dir) ? {
964- snapshot_dir. push ( path. unwrap ( ) . file_name ( ) ) ;
901+ snapshot_dir. push ( path? . file_name ( ) ) ;
965902 }
966903 new_advance_local ( logger. clone ( ) , snapshot_dir, timestamp)
967904 }
0 commit comments