[Win32utils-devel] Service.start arguments failing or causing segfault

Heesob Park phasis at gmail.com
Sat Nov 24 09:17:11 EST 2007


Hi,

2007/11/24, Daniel Berger <djberg96 at gmail.com>:
>
> Hi,
>
> Unless I'm mistaken the final arguments to Service.start should be
> passed to the Daemon's service_main method. Correct?
>
> I modified the Service.start method (now in CVS) to look something like
> this:
>
> def self.start(service, host=nil, *args)
>    ...
>    num_args = args.length
>
>    if args.empty?
>       args = nil
>    else
>       args.unshift(service) # Necessary?
>       args = [args.join("\000")].pack('p*') # Must pack?
>    end
>
>    unless StartService(handle_scs, num_args, args)
>    ...
> end
>
> I wasn't sure if I needed to explicitly push the service name onto the
> array, but it does segfault without it.
>
> I also wasn't sure if I needed to explicitly pack the array. Again, it
> segfaulted without it.


Don't ask me why, just follow the rule of the microsoft :)

Acording to http://msdn2.microsoft.com/en-US/library/ms686321.aspx ,
StartService function requires NULL or an argument which the first element
must be service name.
And argument type is not LPCSTR, but LPCTSTR* ( pointer of string), so it
need to be packed.

To test, I modified the demo_daemon.rb file's service_main method so
> that it looks like this:
>
> def service_main(args = nil)
>    msg = 'service_main entered at: ' + Time.now.to_s
>    File.open(LOG_FILE, 'a+'){ |f|
>       f.puts msg
>       f.puts "Args: " + args.join(',') if args
>    }
>    ...
> end
>
> In the demo_daemon_ctl.rb script, I modified the start option like so:
>
> Service.start(SERVICE_NAME, nil, 'hello', 'world')
>
> As things stand now I get:
>
> C:/ruby/lib/ruby/site_ruby/1.8/win32/service.rb:684:in `start': The
> service did not respond to the start or control requ
> est in a timely fashion. (Win32::Service::Error)
>         from demo_daemon_ctl.rb:66
>
> Any ideas?



Regards,

Park Heesob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/win32utils-devel/attachments/20071124/05e4ce86/attachment-0001.html 


More information about the win32utils-devel mailing list