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

Daniel Berger djberg96 at gmail.com
Sat Nov 24 08:09:23 EST 2007


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 

def self.start(service, host=nil, *args)
    num_args = args.length

    if args.empty?
       args = nil
       args.unshift(service) # Necessary?
       args = [args.join("\000")].pack('p*') # Must pack?

    unless StartService(handle_scs, num_args, args)

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.

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

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?



More information about the win32utils-devel mailing list