5
5
6
6
use std:: { env, thread} ;
7
7
use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
8
- use std:: process:: exit;
9
- use std:: fs:: File ;
10
- use std:: io:: Write ;
11
8
use std:: time:: Duration ;
12
9
use std:: path:: PathBuf ;
13
- use libc:: fork;
14
10
use time;
15
11
use docbuilder:: RustwideBuilder ;
16
12
use DocBuilderOptions ;
17
13
use DocBuilder ;
18
14
use utils:: { update_release_activity, github_updater, pubsubhubbub} ;
19
15
use db:: { connect_db, update_search_index} ;
20
16
21
-
17
+ #[ cfg( not( target_os = "windows" ) ) ]
18
+ use :: {
19
+ libc:: fork,
20
+ std:: process:: exit,
21
+ std:: fs:: File ,
22
+ std:: io:: Write
23
+ } ;
22
24
23
25
pub fn start_daemon ( background : bool ) {
24
26
// first check required environment variables
@@ -36,15 +38,22 @@ pub fn start_daemon(background: bool) {
36
38
dbopts. check_paths ( ) . unwrap ( ) ;
37
39
38
40
if background {
39
- // fork the process
40
- let pid = unsafe { fork ( ) } ;
41
- if pid > 0 {
42
- let mut file = File :: create ( dbopts. prefix . join ( "cratesfyi.pid" ) )
43
- . expect ( "Failed to create pid file" ) ;
44
- writeln ! ( & mut file, "{}" , pid) . expect ( "Failed to write pid" ) ;
45
-
46
- info ! ( "cratesfyi {} daemon started on: {}" , :: BUILD_VERSION , pid) ;
47
- exit ( 0 ) ;
41
+ #[ cfg( target_os = "windows" ) ]
42
+ {
43
+ panic ! ( "running in background not supported on windows" ) ;
44
+ }
45
+ #[ cfg( not( target_os = "windows" ) ) ]
46
+ {
47
+ // fork the process
48
+ let pid = unsafe { fork ( ) } ;
49
+ if pid > 0 {
50
+ let mut file = File :: create ( dbopts. prefix . join ( "cratesfyi.pid" ) )
51
+ . expect ( "Failed to create pid file" ) ;
52
+ writeln ! ( & mut file, "{}" , pid) . expect ( "Failed to write pid" ) ;
53
+
54
+ info ! ( "cratesfyi {} daemon started on: {}" , :: BUILD_VERSION , pid) ;
55
+ exit ( 0 ) ;
56
+ }
48
57
}
49
58
}
50
59
0 commit comments