From: Guido De Rosa Date: 2010-10-19T07:18:01+09:00 Subject: Re: su {block of code.} Tony Arcieri wrote in post #955183: > I'd suggest spawning a new Ruby instance which runs under sudo and > talking > to it with DRb My big concern comes directly from DRb doc: "As blocks (or rather the Proc objects that represent them) are not marshallable, the block executes in the local, not the remote, context." Following your suggestion, I thought about a solution based on a DRb server run as root: require 'drb/drb' URI="druby://localhost:8787" class Executor def execute(&blk) blk.call end end DRb.start_service(URI, Executor.new) DRb.thread.join The client code being executed as a non-privileged user: require 'drb/drb' SERVER_URI="druby://localhost:8787" DRb.start_service executor = DRbObject.new_with_uri(SERVER_URI) executor.execute do # a file writable only by root File.open('/TEST', 'w'){|f| f.puts 'hello!'} end BUT I get a permission denied! On the other if I don't use Procs, everything works fine: server.rb: # ... class FileWriter def write(file, str) File.open(file, 'w'){|f| f.puts str} end end # DRb.start_service(URI, FileWriter.new) client.rb: # ... writer = DRbObject.new_with_uri(SERVER_URI) writer.write '/TEST', 'hello!' -- Posted via http://www.ruby-forum.com/.