Module: ChildProcess::Windows::Lib
- Extended by:
- FFI::Library
- Defined in:
- lib/childprocess/windows.rb,
lib/childprocess/windows/lib.rb
Class Method Summary collapse
- .check_error(bool) ⇒ Object
- .dont_inherit(file) ⇒ Object
- .duplicate_handle(handle) ⇒ Object
- .get_handle_inheritance(handle) ⇒ Object
- .handle_for(fd_or_io) ⇒ Object
- .io_for(handle, flags = File::RDONLY) ⇒ Object
- .kill(signal, *pids) ⇒ Object
- .last_error_message ⇒ Object
- .msvcrt_name ⇒ Object
- .no_hang?(flags) ⇒ Boolean
- .set_handle_inheritance(handle, bool) ⇒ Object
- .wait_for_pid(pid, no_hang) ⇒ Object
- .waitpid(pid, flags = 0) ⇒ Object
- .waitpid2(pid, flags = 0) ⇒ Object
Class Method Details
.check_error(bool) ⇒ Object
335 336 337 |
# File 'lib/childprocess/windows/lib.rb', line 335 def check_error(bool) bool or raise Error, end |
.dont_inherit(file) ⇒ Object
237 238 239 240 241 242 243 |
# File 'lib/childprocess/windows/lib.rb', line 237 def dont_inherit(file) unless file.respond_to?(:fileno) raise ArgumentError, "expected #{file.inspect} to respond to :fileno" end set_handle_inheritance(handle_for(file.fileno), false) end |
.duplicate_handle(handle) ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/childprocess/windows/lib.rb', line 291 def duplicate_handle(handle) dup = FFI::MemoryPointer.new(:pointer) proc = current_process ok = Lib._duplicate_handle( proc, handle, proc, dup, 0, false, DUPLICATE_SAME_ACCESS ) check_error ok dup.read_pointer ensure close_handle proc end |
.get_handle_inheritance(handle) ⇒ Object
322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/childprocess/windows/lib.rb', line 322 def get_handle_inheritance(handle) flags = FFI::MemoryPointer.new(:uint) status = get_handle_information( handle, flags ) check_error status flags.read_uint end |
.handle_for(fd_or_io) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/childprocess/windows/lib.rb', line 258 def handle_for(fd_or_io) if fd_or_io.kind_of?(IO) || fd_or_io.respond_to?(:fileno) handle = get_osfhandle(fd_or_io.fileno) elsif fd_or_io.kind_of?(Fixnum) handle = get_osfhandle(fd_or_io) elsif fd_or_io.respond_to?(:to_io) io = fd_or_io.to_io unless io.kind_of?(IO) raise TypeError, "expected #to_io to return an instance of IO" end handle = get_osfhandle(io.fileno) else raise TypeError, "invalid type: #{fd_or_io.inspect}" end if handle == INVALID_HANDLE_VALUE raise Error, end FFI::Pointer.new handle end |
.io_for(handle, flags = File::RDONLY) ⇒ Object
282 283 284 285 286 287 288 289 |
# File 'lib/childprocess/windows/lib.rb', line 282 def io_for(handle, flags = File::RDONLY) fd = open_osfhandle(handle, flags) if fd == -1 raise Error, end FFI::IO.for_fd fd, flags end |
.kill(signal, *pids) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/childprocess/windows/lib.rb', line 210 def kill(signal, *pids) case signal when 'SIGINT', 'INT', :SIGINT, :INT signal = WIN_SIGINT when 'SIGBRK', 'BRK', :SIGBREAK, :BRK signal = WIN_SIGBREAK when 'SIGKILL', 'KILL', :SIGKILL, :KILL signal = WIN_SIGKILL when 0..9 # Do nothing else raise Error, "invalid signal #{signal.inspect}" end pids.map { |pid| pid if Lib.send_signal(signal, pid) }.compact end |
.last_error_message ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/childprocess/windows/lib.rb', line 245 def errnum = get_last_error buf = FFI::MemoryPointer.new :char, 512 size = ( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, nil, errnum, 0, buf, buf.size, nil ) str = buf.read_string(size).strip "#{str} (#{errnum})" end |
.msvcrt_name ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/childprocess/windows.rb', line 9 def self.msvcrt_name host_part = RbConfig::CONFIG['host_os'].split("_")[1] manifest = File.join(RbConfig::CONFIG['bindir'], 'ruby.exe.manifest') if host_part && host_part.to_i > 80 && File.exists?(manifest) "msvcr#{host_part}" else "msvcrt" end end |
.no_hang?(flags) ⇒ Boolean
339 340 341 |
# File 'lib/childprocess/windows/lib.rb', line 339 def no_hang?(flags) (flags & Process::WNOHANG) == Process::WNOHANG end |
.set_handle_inheritance(handle, bool) ⇒ Object
312 313 314 315 316 317 318 319 320 |
# File 'lib/childprocess/windows/lib.rb', line 312 def set_handle_inheritance(handle, bool) status = set_handle_information( handle, HANDLE_FLAG_INHERIT, bool ? HANDLE_FLAG_INHERIT : 0 ) check_error status end |
.wait_for_pid(pid, no_hang) ⇒ Object
343 344 345 346 347 348 349 350 |
# File 'lib/childprocess/windows/lib.rb', line 343 def wait_for_pid(pid, no_hang) code = Handle.open(pid) { |handle| handle.wait unless no_hang handle.exit_code } code if code != PROCESS_STILL_ACTIVE end |
.waitpid(pid, flags = 0) ⇒ Object
227 228 229 |
# File 'lib/childprocess/windows/lib.rb', line 227 def waitpid(pid, flags = 0) wait_for_pid(pid, no_hang?(flags)) end |
.waitpid2(pid, flags = 0) ⇒ Object
231 232 233 234 235 |
# File 'lib/childprocess/windows/lib.rb', line 231 def waitpid2(pid, flags = 0) code = wait_for_pid(pid, no_hang?(flags)) [pid, code] if code end |