Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop win32-api gem #3849

Merged
merged 2 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions fluentd.gemspec
Expand Up @@ -34,12 +34,9 @@ Gem::Specification.new do |gem|
fake_platform = ENV['GEM_BUILD_FAKE_PLATFORM'].to_s
gem.platform = fake_platform unless fake_platform.empty?
if /mswin|mingw/ =~ fake_platform || (/mswin|mingw/ =~ RUBY_PLATFORM && fake_platform.empty?)
gem.add_runtime_dependency("win32-api", [">= 1.10", "< 2.0.0"])
gem.add_runtime_dependency("win32-service", ["~> 2.3.0"])
gem.add_runtime_dependency("win32-ipc", ["~> 0.7.0"])
gem.add_runtime_dependency("win32-event", ["~> 0.6.3"])
gem.add_runtime_dependency("windows-api", ["~> 0.4.5"])
gem.add_runtime_dependency("windows-pr", ["~> 1.2.6"])
gem.add_runtime_dependency("certstore_c", ["~> 0.1.7"])
end

Expand Down
7 changes: 1 addition & 6 deletions lib/fluent/command/fluentd.rb
Expand Up @@ -189,9 +189,6 @@
}

if Fluent.windows?
require 'windows/library'
include Windows::Library

opts.merge!(
:winsvc_name => 'fluentdwinsvc',
:winsvc_display_name => 'Fluentd Windows Service',
Expand Down Expand Up @@ -292,9 +289,7 @@
case winsvcinstmode
when 'i'
binary_path = File.join(File.dirname(__FILE__), "..")
ruby_path = "\0" * 256
GetModuleFileName.call(0,ruby_path,256)
ruby_path = ruby_path.rstrip.gsub(/\\/, '/')
ruby_path = ServerEngine.ruby_bin_path
start_type = Service::DEMAND_START
if opts[:regwinsvcautostart]
start_type = Service::AUTO_START
Expand Down
32 changes: 24 additions & 8 deletions lib/fluent/plugin/file_wrapper.rb
Expand Up @@ -35,20 +35,36 @@ def self.stat(path)
end
end

class WindowsFile
require 'windows/file'
require 'windows/handle'
module Win32API
require 'fiddle/import'
require 'fiddle/types'
extend Fiddle::Importer

if RUBY_PLATFORM.split('-')[-1] == "ucrt"
MSVCRT_DLL = 'ucrtbase.dll'
else
MSVCRT_DLL = 'msvcrt.dll'
end

dlload MSVCRT_DLL, "kernel32.dll"
include Fiddle::Win32Types

extern "intptr_t _get_osfhandle(int)"
cosmo0920 marked this conversation as resolved.
Show resolved Hide resolved
extern "BOOL GetFileInformationByHandle(HANDLE, void *)"
extern "BOOL GetFileInformationByHandleEx(HANDLE, int, void *, DWORD)"
end
ashie marked this conversation as resolved.
Show resolved Hide resolved

class WindowsFile
include File::Constants
include Windows::File
include Windows::Handle

attr_reader :io

INVALID_HANDLE_VALUE = -1

def initialize(path, mode='r')
@path = path
@io = File.open(path, mode2flags(mode))
@file_handle = _get_osfhandle(@io.to_i)
@file_handle = Win32API._get_osfhandle(@io.to_i)
@io.instance_variable_set(:@file_index, self.ino)
def @io.ino
@file_index
Expand All @@ -68,7 +84,7 @@ def close
def ino
by_handle_file_information = '\0'*(4+8+8+8+4+4+4+4+4+4) #72bytes

unless GetFileInformationByHandle.call(@file_handle, by_handle_file_information)
unless Win32API.GetFileInformationByHandle(@file_handle, by_handle_file_information)
return 0
end

Expand Down Expand Up @@ -122,7 +138,7 @@ def delete_pending
bufsize = 1024
buf = '\0' * bufsize

unless GetFileInformationByHandleEx.call(@file_handle, file_standard_info, buf, bufsize)
unless Win32API.GetFileInformationByHandleEx(@file_handle, file_standard_info, buf, bufsize)
return false
end

Expand Down
9 changes: 2 additions & 7 deletions lib/fluent/supervisor.rb
Expand Up @@ -32,12 +32,6 @@
require 'serverengine'

if Fluent.windows?
require 'windows/library'
require 'windows/synchronize'
require 'windows/system_info'
include Windows::Library
include Windows::Synchronize
include Windows::SystemInfo
require 'win32/ipc'
require 'win32/event'
end
Expand Down Expand Up @@ -235,7 +229,8 @@ def install_windows_event_handler
end
begin
loop do
ipc_idx = ipc.wait_any(events.map {|e| e[:win32_event]}, Windows::Synchronize::INFINITE)
infinite = 0xFFFFFFFF
ipc_idx = ipc.wait_any(events.map {|e| e[:win32_event]}, infinite)
event_idx = ipc_idx - 1

if event_idx >= 0 && event_idx < events.length
Expand Down
10 changes: 2 additions & 8 deletions lib/fluent/winsvc.rb
Expand Up @@ -17,14 +17,10 @@
begin

require 'optparse'
require 'windows/debug'
require 'Windows/Library'
require 'win32/daemon'
require 'win32/event'

include Win32
include Windows::Library
include Windows::Debug

op = OptionParser.new
opts = {service_name: nil}
Expand All @@ -37,16 +33,14 @@
end

def read_fluentdopt(service_name)
require 'win32/Registry'
require 'win32/registry'
Win32::Registry::HKEY_LOCAL_MACHINE.open("SYSTEM\\CurrentControlSet\\Services\\#{service_name}") do |reg|
reg.read("fluentdopt")[1] rescue ""
end
end

def service_main_start(service_name)
ruby_path = 0.chr * 260
GetModuleFileName.call(0, ruby_path,260)
ruby_path = ruby_path.rstrip.gsub(/\\/, '/')
ruby_path = ServerEngine.ruby_bin_path
rubybin_dir = ruby_path[0, ruby_path.rindex("/")]
opt = read_fluentdopt(service_name)
Process.spawn("\"#{rubybin_dir}/ruby.exe\" \"#{rubybin_dir}/fluentd\" #{opt} -x #{service_name}")
Expand Down
5 changes: 0 additions & 5 deletions test/plugin/test_file_wrapper.rb
Expand Up @@ -2,11 +2,6 @@
require 'fluent/plugin/file_wrapper'

class FileWrapperTest < Test::Unit::TestCase
require 'windows/file'
require 'windows/error'
include Windows::File
include Windows::Error

TMP_DIR = File.dirname(__FILE__) + "/../tmp/file_wrapper#{ENV['TEST_ENV_NUMBER']}"

def setup
Expand Down