From: Joel VanderWerf Date: 2005-07-21T08:15:48+09:00 Subject: Re: Changing Process#uid while staying with $SAFE=0 benny wrote: > Dear List, > > a have written a daemon that should finally run as a different user than > root. However I need to initially start as root to get DRb running and want > to switch the uid of the process after that. > > When I change the uid $SAFE is set to 1. But I need $SAFE to be 0. > > Any idea that I might do? (Running FreeBSD btw.) Have another thread with $SAFE=0 that exists just to call Process.uid= . ($SAFE is a per-thread variable.) Set this thread up before changing to $SAFE=1, like this: # cat safe.rb Thread.abort_on_exception = true uid_thread = Thread.new do # still $SAFE==0 sleep # wait for wakeup puts "in uid_thread: $SAFE = #{$SAFE}" Process.uid=1000 end $SAFE = 1 puts "in main thread: $SAFE = #{$SAFE}" uid_thread.wakeup uid_thread.join puts "uid = #{Process.uid}" # ruby safe.rb in main thread: $SAFE = 1 in uid_thread: $SAFE = 0 uid = 1000