Skip to content

Commit 5756937

Browse files
authored
Fix foreground logic
1 parent 03462ef commit 5756937

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

component/daemon.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@ def runas_daemon(argv)
88
$mode = :daemon
99

1010
# daemonize
11-
Process.daemon(false, true) unless ARGV.include?('--foreground')
11+
unless ARGV.include?('--foreground')
12+
Process.daemon(false, true)
1213

13-
Process.setproctitle('crew-sudo daemon process')
14+
# redirect output to log
15+
$log = File.open(DAEMON_LOG_PATH, 'w')
1416

15-
warn "crew-sudo: Daemon started with PID #{Process.pid}"
17+
$stdin.reopen('/dev/null')
18+
$stdout.reopen($log)
19+
$stderr.reopen($log)
1620

17-
# redirect output to log
18-
$log = File.open(DAEMON_LOG_PATH, 'w')
21+
[$log, $stdout, $stderr].each {|io| io.sync = true }
22+
end
1923

20-
$stdin.reopen('/dev/null')
21-
$stdout.reopen($log)
22-
$stderr.reopen($log)
24+
Process.setproctitle('crew-sudo daemon process')
2325

24-
[$log, $stdout, $stderr].each {|io| io.sync = true }
26+
warn "crew-sudo: Daemon started with PID #{Process.pid}"
2527

2628
if Process.uid.zero?
2729
message 'Daemon running with root permission.'
@@ -105,4 +107,4 @@ def runas_daemon(argv)
105107
ensure
106108
@server.close
107109
File.delete(SOCKET_PATH) if File.exist?(SOCKET_PATH)
108-
end
110+
end

0 commit comments

Comments
 (0)