win32-service 2.3.2 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 746b781ce8ab92f9ef2f38854781e593281687956b171bd4aa57054e02b68648
4
- data.tar.gz: 55ac6d06feb8f47751ffee8edee887420001d4b11ba5e5cce16daae343c80e1b
3
+ metadata.gz: d6e082fe0332a702fd8a8abe6be757173ac44a97f5aca6b544e63aea98435e41
4
+ data.tar.gz: 22628c39784ab449296e8775298bbb9502b1fd944097dfa7c8fac25b423f1f69
5
5
  SHA512:
6
- metadata.gz: 3cd8d485dae8159f1d0d788baa22c30fb5b98ab71623ef935c7b27535c100e6fa4b33cc59aa9617c313c3d33a637ab1dc8034aac236f5231e0fb09d2487fa308
7
- data.tar.gz: e8410fc1cd05028d99b6f3c1822e635e85e50eb3b08f48e291fb20cfa06ad1c98bce740fc25af51eea7aa1a18b990f78727be0eed7ddc648d4f4b3875ac5c6fa
6
+ metadata.gz: 3c20950b21f865da21aef986bed1d8f9eb72cca83f6e78f91bf4abc963bce43ae715b73a3ed5e72cc2649138209bd2120cb8e38870487620d728e264864db8fc
7
+ data.tar.gz: 4327e6a58cc533509506ad72783f2150f6d84ff60df1661abc8b3a5b7193d0627ed806e09c2db219ebc390202a9fa2e91902ee27eac0ff6ffac39966bb9e9a6d
data/lib/win32/daemon.rb CHANGED
@@ -79,8 +79,8 @@ module Win32
79
79
  ss[:dwControlsAccepted] = 0
80
80
  else
81
81
  ss[:dwControlsAccepted] =
82
- SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN |
83
- SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_PARAMCHANGE
82
+ SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN |
83
+ SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_PARAMCHANGE
84
84
  end
85
85
 
86
86
  # Initialize ss structure.
@@ -142,48 +142,48 @@ module Win32
142
142
 
143
143
  # Called by the service control manager after the call to StartServiceCtrlDispatcher.
144
144
  Service_Main = FFI::Function.new(:void, %i{ulong pointer}, blocking: false) do |dwArgc, lpszArgv|
145
- begin
146
- # Obtain the name of the service.
147
- if lpszArgv.address != 0
148
- argv = lpszArgv.get_array_of_string(0, dwArgc)
149
- lpszServiceName = argv[0]
150
- else
151
- lpszServiceName = ""
152
- end
153
145
 
154
- # Args passed to Service.start
155
- if dwArgc > 1
156
- @@Argv = argv[1..-1]
157
- else
158
- @@Argv = nil
159
- end
146
+ # Obtain the name of the service.
147
+ if lpszArgv.address != 0
148
+ argv = lpszArgv.get_array_of_string(0, dwArgc)
149
+ lpszServiceName = argv[0]
150
+ else
151
+ lpszServiceName = ""
152
+ end
160
153
 
161
- # Register the service ctrl handler.
162
- @@ssh = RegisterServiceCtrlHandlerEx(
163
- lpszServiceName,
164
- Service_Ctrl_ex,
165
- nil
166
- )
154
+ # Args passed to Service.start
155
+ if dwArgc > 1
156
+ @@Argv = argv[1..-1]
157
+ else
158
+ @@Argv = nil
159
+ end
167
160
 
168
- # No service to stop, no service handle to notify, nothing to do but exit.
169
- return if @@ssh == 0
161
+ # Register the service ctrl handler.
162
+ @@ssh = RegisterServiceCtrlHandlerEx(
163
+ lpszServiceName,
164
+ Service_Ctrl_ex,
165
+ nil
166
+ )
170
167
 
171
- # The service has started.
172
- SetTheServiceStatus.call(SERVICE_RUNNING, NO_ERROR, 0, 0)
168
+ # No service to stop, no service handle to notify, nothing to do but exit.
169
+ return if @@ssh == 0 # rubocop:disable Lint/NonLocalExitFromIterator
173
170
 
174
- SetEvent(@@hStartEvent)
171
+ # The service has started.
172
+ SetTheServiceStatus.call(SERVICE_RUNNING, NO_ERROR, 0, 0)
175
173
 
176
- # Main loop for the service.
177
- while WaitForSingleObject(@@hStopEvent, 1000) != WAIT_OBJECT_0
178
- end
174
+ SetEvent(@@hStartEvent)
179
175
 
180
- # Main loop for the service.
181
- while WaitForSingleObject(@@hStopCompletedEvent, 1000) != WAIT_OBJECT_0
182
- end
183
- ensure
184
- # Stop the service.
185
- SetTheServiceStatus.call(SERVICE_STOPPED, NO_ERROR, 0, 0)
176
+ # Main loop for the service.
177
+ while WaitForSingleObject(@@hStopEvent, 1000) != WAIT_OBJECT_0
186
178
  end
179
+
180
+ # Main loop for the service.
181
+ while WaitForSingleObject(@@hStopCompletedEvent, 1000) != WAIT_OBJECT_0
182
+ end
183
+ ensure
184
+ # Stop the service.
185
+ SetTheServiceStatus.call(SERVICE_STOPPED, NO_ERROR, 0, 0)
186
+
187
187
  end
188
188
 
189
189
  ThreadProc = FFI::Function.new(:ulong, [:pointer]) do |lpParameter|
@@ -277,44 +277,44 @@ module Win32
277
277
  end
278
278
 
279
279
  thr = Thread.new do
280
- begin
281
- while WaitForSingleObject(@@hStopEvent, 1000) == WAIT_TIMEOUT
282
- # Check to see if anything interesting has been signaled
283
- case @@waiting_control_code
284
- when SERVICE_CONTROL_PAUSE
285
- service_pause if respond_to?("service_pause")
286
- when SERVICE_CONTROL_CONTINUE
287
- service_resume if respond_to?("service_resume")
288
- when SERVICE_CONTROL_INTERROGATE
289
- service_interrogate if respond_to?("service_interrogate")
290
- when SERVICE_CONTROL_SHUTDOWN
291
- service_shutdown if respond_to?("service_shutdown")
292
- when SERVICE_CONTROL_PARAMCHANGE
293
- service_paramchange if respond_to?("service_paramchange")
294
- when SERVICE_CONTROL_NETBINDADD
295
- service_netbindadd if respond_to?("service_netbindadd")
296
- when SERVICE_CONTROL_NETBINDREMOVE
297
- service_netbindremove if respond_to?("service_netbindremove")
298
- when SERVICE_CONTROL_NETBINDENABLE
299
- service_netbindenable if respond_to?("service_netbindenable")
300
- when SERVICE_CONTROL_NETBINDDISABLE
301
- service_netbinddisable if respond_to?("service_netbinddisable")
302
- end
303
280
 
304
- # handle user defined control codes
305
- if @@waiting_control_code >= 128 && @@waiting_control_code <= 255
306
- if respond_to?("service_user_defined_control")
307
- service_user_defined_control(@@waiting_control_code)
308
- end
309
- end
281
+ while WaitForSingleObject(@@hStopEvent, 1000) == WAIT_TIMEOUT
282
+ # Check to see if anything interesting has been signaled
283
+ case @@waiting_control_code
284
+ when SERVICE_CONTROL_PAUSE
285
+ service_pause if respond_to?("service_pause")
286
+ when SERVICE_CONTROL_CONTINUE
287
+ service_resume if respond_to?("service_resume")
288
+ when SERVICE_CONTROL_INTERROGATE
289
+ service_interrogate if respond_to?("service_interrogate")
290
+ when SERVICE_CONTROL_SHUTDOWN
291
+ service_shutdown if respond_to?("service_shutdown")
292
+ when SERVICE_CONTROL_PARAMCHANGE
293
+ service_paramchange if respond_to?("service_paramchange")
294
+ when SERVICE_CONTROL_NETBINDADD
295
+ service_netbindadd if respond_to?("service_netbindadd")
296
+ when SERVICE_CONTROL_NETBINDREMOVE
297
+ service_netbindremove if respond_to?("service_netbindremove")
298
+ when SERVICE_CONTROL_NETBINDENABLE
299
+ service_netbindenable if respond_to?("service_netbindenable")
300
+ when SERVICE_CONTROL_NETBINDDISABLE
301
+ service_netbinddisable if respond_to?("service_netbinddisable")
302
+ end
310
303
 
311
- @@waiting_control_code = IDLE_CONTROL_CODE
304
+ # handle user defined control codes
305
+ if @@waiting_control_code.between?(128, 255)
306
+ if respond_to?("service_user_defined_control")
307
+ service_user_defined_control(@@waiting_control_code)
308
+ end
312
309
  end
313
310
 
314
- service_stop if respond_to?("service_stop")
315
- ensure
316
- SetEvent(@@hStopCompletedEvent)
311
+ @@waiting_control_code = IDLE_CONTROL_CODE
317
312
  end
313
+
314
+ service_stop if respond_to?("service_stop")
315
+ ensure
316
+ SetEvent(@@hStopCompletedEvent)
317
+
318
318
  end
319
319
 
320
320
  if respond_to?("service_main")
data/lib/win32/service.rb CHANGED
@@ -301,24 +301,24 @@ module Win32
301
301
  end
302
302
 
303
303
  opts = {
304
- "display_name" => nil,
305
- "desired_access" => SERVICE_ALL_ACCESS,
306
- "service_type" => SERVICE_WIN32_OWN_PROCESS,
307
- "start_type" => SERVICE_DEMAND_START,
308
- "error_control" => SERVICE_ERROR_NORMAL,
309
- "binary_path_name" => nil,
310
- "load_order_group" => nil,
311
- "dependencies" => nil,
312
- "service_start_name" => nil,
313
- "password" => nil,
314
- "description" => nil,
315
- "failure_reset_period" => nil,
304
+ "display_name" => nil,
305
+ "desired_access" => SERVICE_ALL_ACCESS,
306
+ "service_type" => SERVICE_WIN32_OWN_PROCESS,
307
+ "start_type" => SERVICE_DEMAND_START,
308
+ "error_control" => SERVICE_ERROR_NORMAL,
309
+ "binary_path_name" => nil,
310
+ "load_order_group" => nil,
311
+ "dependencies" => nil,
312
+ "service_start_name" => nil,
313
+ "password" => nil,
314
+ "description" => nil,
315
+ "failure_reset_period" => nil,
316
316
  "failure_reboot_message" => nil,
317
- "failure_command" => nil,
318
- "failure_actions" => nil,
319
- "failure_delay" => 0,
320
- "host" => nil,
321
- "service_name" => nil,
317
+ "failure_command" => nil,
318
+ "failure_actions" => nil,
319
+ "failure_delay" => 0,
320
+ "host" => nil,
321
+ "service_name" => nil,
322
322
  }
323
323
 
324
324
  # Validate the hash options
@@ -403,8 +403,6 @@ module Win32
403
403
  self.class.close_service_handle(handle_scs)
404
404
  self.class.close_service_handle(handle_scm)
405
405
  end
406
-
407
- self
408
406
  end
409
407
 
410
408
  # Configures the named +service+ on +host+, or the local host if no host
@@ -460,24 +458,24 @@ module Win32
460
458
  end
461
459
 
462
460
  opts = {
463
- "service_type" => SERVICE_NO_CHANGE,
464
- "start_type" => SERVICE_NO_CHANGE,
465
- "error_control" => SERVICE_NO_CHANGE,
466
- "binary_path_name" => nil,
467
- "load_order_group" => nil,
468
- "dependencies" => nil,
469
- "service_start_name" => nil,
470
- "password" => nil,
471
- "display_name" => nil,
472
- "description" => nil,
473
- "failure_reset_period" => nil,
461
+ "service_type" => SERVICE_NO_CHANGE,
462
+ "start_type" => SERVICE_NO_CHANGE,
463
+ "error_control" => SERVICE_NO_CHANGE,
464
+ "binary_path_name" => nil,
465
+ "load_order_group" => nil,
466
+ "dependencies" => nil,
467
+ "service_start_name" => nil,
468
+ "password" => nil,
469
+ "display_name" => nil,
470
+ "description" => nil,
471
+ "failure_reset_period" => nil,
474
472
  "failure_reboot_message" => nil,
475
- "failure_command" => nil,
476
- "failure_actions" => nil,
477
- "failure_delay" => 0,
478
- "service_name" => nil,
479
- "host" => nil,
480
- "delayed_start" => false,
473
+ "failure_command" => nil,
474
+ "failure_actions" => nil,
475
+ "failure_delay" => 0,
476
+ "service_name" => nil,
477
+ "host" => nil,
478
+ "delayed_start" => false,
481
479
  }
482
480
 
483
481
  # Validate the hash options
@@ -686,7 +684,8 @@ module Win32
686
684
  close_service_handle(handle_scm)
687
685
  end
688
686
 
689
- service_name.read_string
687
+ # Return a lowercase, UTF-8 encoded string
688
+ service_name.read_string.downcase.force_encoding("UTF-8")
690
689
  end
691
690
 
692
691
  # Attempts to start the named +service+ on +host+, or the local machine
@@ -714,13 +713,12 @@ module Win32
714
713
  num_args = 0
715
714
 
716
715
  if args.empty?
717
- args = nil
716
+ nil # rubocop:disable Lint/Void
718
717
  else
719
- str_ptrs = []
720
718
  num_args = args.size
721
719
 
722
- args.each { |string|
723
- str_ptrs << FFI::MemoryPointer.from_string(string)
720
+ str_ptrs = args.map { |string|
721
+ FFI::MemoryPointer.from_string(string)
724
722
  }
725
723
 
726
724
  str_ptrs << nil
@@ -1212,12 +1210,12 @@ module Win32
1212
1210
  delayed_start_buf = get_config2_info(handle_scs, SERVICE_CONFIG_DELAYED_AUTO_START_INFO)
1213
1211
  if delayed_start_buf.is_a?(FFI::MemoryPointer)
1214
1212
  delayed_start_info = SERVICE_DELAYED_AUTO_START_INFO.new(delayed_start_buf)
1215
- delayed_start = delayed_start_info[:fDelayedAutostart]
1213
+ delayed_start_info[:fDelayedAutostart]
1216
1214
  else
1217
- delayed_start = false
1215
+ false
1218
1216
  end
1219
1217
  rescue SystemCallError
1220
- delayed_start = nil
1218
+ nil
1221
1219
  ensure
1222
1220
  close_service_handle(handle_scs)
1223
1221
  close_service_handle(handle_scm)
@@ -1252,18 +1250,18 @@ module Win32
1252
1250
  # @see Windows::ServiceConstants
1253
1251
  #
1254
1252
  def self.open_service(scm_handle, service_name, desired_access)
1255
- service_handle = OpenService(
1253
+ service_handle = OpenService(
1256
1254
  scm_handle,
1257
1255
  service_name,
1258
1256
  desired_access
1259
1257
  )
1260
- FFI.raise_windows_error("OpenService") if service_handle == 0
1258
+ FFI.raise_windows_error("OpenService") if service_handle == 0
1261
1259
 
1262
- if block_given?
1263
- yield service_handle
1264
- else
1265
- service_handle
1266
- end
1260
+ if block_given?
1261
+ yield service_handle
1262
+ else
1263
+ service_handle
1264
+ end
1267
1265
  ensure
1268
1266
  close_service_handle(service_handle) if block_given?
1269
1267
  end
@@ -1606,30 +1604,19 @@ module Win32
1606
1604
  # Converts a service type numeric constant into a human readable string.
1607
1605
  #
1608
1606
  def self.get_service_type(service_type)
1609
- case service_type
1610
- when SERVICE_FILE_SYSTEM_DRIVER
1611
- "file system driver"
1612
- when SERVICE_KERNEL_DRIVER
1613
- "kernel driver"
1614
- when SERVICE_WIN32_OWN_PROCESS
1615
- "own process"
1616
- when SERVICE_WIN32_SHARE_PROCESS
1617
- "share process"
1618
- when SERVICE_RECOGNIZER_DRIVER
1619
- "recognizer driver"
1620
- when SERVICE_DRIVER
1621
- "driver"
1622
- when SERVICE_WIN32
1623
- "win32"
1624
- when SERVICE_TYPE_ALL
1625
- "all"
1626
- when SERVICE_INTERACTIVE_PROCESS | SERVICE_WIN32_OWN_PROCESS
1627
- "own process, interactive"
1628
- when SERVICE_INTERACTIVE_PROCESS | SERVICE_WIN32_SHARE_PROCESS
1629
- "share process, interactive"
1630
- else
1631
- nil
1607
+ if (service_type & SERVICE_INTERACTIVE_PROCESS) > 0
1608
+ interactive_suffix = ", interactive"
1632
1609
  end
1610
+
1611
+ return "share process#{interactive_suffix}" if (service_type & SERVICE_WIN32_SHARE_PROCESS) > 0
1612
+ return "own process#{interactive_suffix}" if (service_type & SERVICE_WIN32_OWN_PROCESS) > 0
1613
+ return "file system driver" if (service_type & SERVICE_FILE_SYSTEM_DRIVER) > 0
1614
+ return "kernel driver" if (service_type & SERVICE_KERNEL_DRIVER) > 0
1615
+ return "recognizer driver" if (service_type & SERVICE_RECOGNIZER_DRIVER) > 0
1616
+ return "driver" if (service_type & SERVICE_DRIVER) > 0
1617
+ return "all" if (service_type == SERVICE_TYPE_ALL) > 0
1618
+
1619
+ "win32" if (service_type & SERVICE_WIN32) > 0
1633
1620
  end
1634
1621
 
1635
1622
  # A shortcut method that simplifies the various service control methods.
@@ -49,7 +49,7 @@ module Windows
49
49
  attach_pfunc :CreateService, :CreateServiceA,
50
50
  %i{handle string string dword dword dword dword
51
51
  string string ptr pointer string string},
52
- :handle
52
+ :handle
53
53
 
54
54
  attach_pfunc :ControlService, %i{handle dword ptr}, :bool
55
55
  attach_pfunc :DeleteService, [:handle], :bool
@@ -1,6 +1,6 @@
1
1
  module Win32
2
2
  class Service
3
- VERSION = "2.3.2".freeze
3
+ VERSION = "2.4.0".freeze
4
4
  MAJOR, MINOR, TINY = VERSION.split(".")
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-04-07 00:00:00.000000000 Z
12
+ date: 2025-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: 1.17.2
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '0'
27
+ version: 1.17.2
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: ffi-win32-extensions
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -141,14 +141,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - ">="
143
143
  - !ruby/object:Gem::Version
144
- version: '2.3'
144
+ version: '3.1'
145
145
  required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  requirements:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
149
  version: '0'
150
150
  requirements: []
151
- rubygems_version: 3.1.4
151
+ rubygems_version: 3.3.27
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: An interface for MS Windows services