Skip to content

Commit 2250401

Browse files
committed
Add support running as root
1 parent 04829a4 commit 2250401

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

component/daemon.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def runas_daemon(argv)
1010
# daemonize
1111
Process.daemon(false, true) unless ARGV.include?('--foreground')
1212

13-
Process.setproctitle('sudo-server daemon process')
13+
Process.setproctitle('crew-sudo daemon process')
1414

1515
warn "crew-sudo: Daemon started with PID #{Process.pid}"
1616

@@ -23,9 +23,20 @@ def runas_daemon(argv)
2323

2424
[$log, $stdout, $stderr].each {|io| io.sync = true }
2525

26+
if Process.uid.zero?
27+
message 'Daemon running with root permission.'
28+
else
29+
message "Daemon running under UID #{Process.uid}."
30+
end
31+
32+
message "Started with PID #{Process.pid}"
33+
2634
# create unix socket
2735
@server = UNIXServer.new(SOCKET_PATH)
28-
File.chmod(0o600, SOCKET_PATH)
36+
File.chmod(0o660, SOCKET_PATH)
37+
38+
# fix permission if we are running as root
39+
File.chown(0, 1000, SOCKET_PATH) if Process.uid.zero?
2940

3041
Socket.accept_loop(@server) do |socket, _|
3142
Thread.new do

0 commit comments

Comments
 (0)