Skip to content

Commit c6cd27f

Browse files
authored
Fix silent error while starting daemon
1 parent 339cf4c commit c6cd27f

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

component/daemon.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
require_relative '../lib/pty_helper'
66

77
def runas_daemon(argv)
8-
$mode = :daemon
8+
$mode = :daemon
9+
@server = UNIXServer.new(SOCKET_PATH) # create unix socket
10+
11+
# fix permission if we are running as root
12+
File.chown(0, 1000, SOCKET_PATH) if Process.euid.zero?
13+
File.chmod(0o660, SOCKET_PATH)
914

1015
# daemonize
1116
unless ARGV.include?('--foreground')
@@ -33,13 +38,6 @@ def runas_daemon(argv)
3338

3439
message "Started with PID #{Process.pid}"
3540

36-
# create unix socket
37-
@server = UNIXServer.new(SOCKET_PATH)
38-
File.chmod(0o660, SOCKET_PATH)
39-
40-
# fix permission if we are running as root
41-
File.chown(0, 1000, SOCKET_PATH) if Process.uid.zero?
42-
4341
Socket.accept_loop(@server) do |socket, _|
4442
client_pid, client_uid, client_gid = socket.getsockopt(:SOL_SOCKET, :SO_PEERCRED).unpack('L*')
4543

0 commit comments

Comments
 (0)