Module: Sudo::System
- Defined in:
- lib/sudo/system.rb
Constant Summary collapse
- ProcessStillExists =
Class.new(RuntimeError)
- FileStillExists =
Class.new(RuntimeError)
Class Method Summary collapse
-
.check ⇒ Object
just to check if we can sudo; and we’ll receive a sudo token.
- .command(ruby_opts, socket, env = {}) ⇒ Object
- .kill(pid) ⇒ Object
- .unlink(file) ⇒ Object
Class Method Details
.check ⇒ Object
just to check if we can sudo; and we’ll receive a sudo token
34 35 36 37 38 |
# File 'lib/sudo/system.rb', line 34 def check cmd_args, env = command_base cmd_args.concat(["-e", ""]) raise Sudo::Wrapper::SudoFailed unless system(env, *cmd_args) end |
.command(ruby_opts, socket, env = {}) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/sudo/system.rb', line 18 def command(ruby_opts, socket, env = {}) cmd_args, env = command_base(env) cmd_args << "-I#{LIBDIR}" cmd_args.concat(ruby_opts.split) unless ruby_opts.empty? cmd_args.concat([SERVER_SCRIPT.to_s, socket, Process.uid.to_s]) [cmd_args, env] end |
.kill(pid) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/sudo/system.rb', line 10 def kill(pid) if pid and Process.exists? pid system("sudo", "kill", pid.to_s) or system("sudo", "kill", "-9", pid.to_s) or raise ProcessStillExists, "Couldn't kill sudo process (PID=#{pid})" end end |
.unlink(file) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/sudo/system.rb', line 26 def unlink(file) if file and File.exist? file system("sudo", "rm", "-f", file) or raise(FileStillExists, "Couldn't delete #{file}") end end |