[Win32utils-devel] win32-service configure description

Heesob Park phasis at gmail.com
Wed Jun 19 01:56:01 UTC 2013


Hi,

2013/6/19 Daniel Berger <djberg96 at gmail.com>:
> For some reason with the current FFI code, I'm picking up junk characters
> when I read back the service description after setting it:
>
> Failure:
> test: configuring the description works as
> expected(TC_Win32_Service_Configure)
> c:/Users/djberge/Repositories/win32-service/test/test_win32_service_configure.rb:59:in
> `block i
> n <class:TC_Win32_Service_Configure>'
>      56:   test "configuring the description works as expected" do
>      57:     assert_equal('', full_info.description)
>      58:     service_configure(:description => 'test service')
>   => 59:     assert_equal('test service', full_info.description)
>      60:   end
>      61:
>      62: =begin
> <"test service">(US-ASCII) expected but was
> <"\x84\xC2\xFE\x02test service">(ASCII-8BIT)
>
> The relevant code is in the Service.configure method, around line 550.
>
> description = SERVICE_DESCRIPTION.new
> description[:lpDescription] =
> FFI::MemoryPointer.from_string(opts['description'])
>
> What's wrong with that?
>
The description is structure pointer of string.
You need to read pointer of string first.
Here is a patch

diff --git a/service.rb b/service.rb.new
index f1f5fd2..fd393a7 100644
--- a/service.rb
+++ b/service.rb.new
@@ -1065,7 +1065,12 @@ module Win32
               deps =
config_struct[:lpDependencies].read_array_of_null_separated_strings

               buf = get_config2_info(handle_scs, SERVICE_CONFIG_DESCRIPTION)
-              description = buf.read_string
+              if buf.read_pointer.to_i==0
+                  description = ''
+              else
+                  buf = buf.read_pointer
+                  description = buf.read_string
+              end
             else
               msg = "WARNING: The registry entry for the #{service_name} "
               msg += "service could not be found."

Regards,
Park Heesob


More information about the win32utils-devel mailing list