[Win32utils-devel] win32-daemon 0.6.1 problem

Heesob Park phasis at gmail.com
Mon Nov 3 19:55:42 EST 2008


2008/11/4 Berger, Daniel <Daniel.Berger at qwest.com>:
> Hi,
>
>> -----Original Message-----
>> From: win32utils-devel-bounces at rubyforge.org
>> [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of
>> Heesob Park
>> Sent: Sunday, November 02, 2008 8:52 AM
>> To: Development and ideas for win32utils projects
>> Subject: Re: [Win32utils-devel] win32-daemon 0.6.1 problem
>>
>> Hi,
>>
>> 2008/11/1 Berger, Daniel <Daniel.Berger at qwest.com>:
>> >
>> > Anyway, still no luck with running the Daemon itself. Now
>> that we have
>> > callbacks working better in win32-api, I'm hoping to
>> revisit the pure
>> > Ruby Win32::Daemon class again. :)
>> >
>> I struggled with the callback and service control whole
>> weekend :) I made the pure Ruby Win32::Daemon class as you expected.
>> Here are two patches and two ruby code.
>
> Oh, excellent!
>
>> First patch is trivial for callback support.
>> Second patch is a little messy. I added address attribute to
>> callback class.
>>
>> As you know, Win32 thread is not working well with Ruby.
>> So I implemented pure Ruby version as two separate processes
>> without thread.
>> The daemon.rb and daemon0.rb must be in the same folder.
>> Some code cleanup and adding close handle code are required.
>> I think the startup argument notification need to reform.
>> I tried mmap and pipe but both failed with segment fault.
>>
>> Patch for windows-pr/lib/windows/service.rb
>> --- service.rb.bak      2008-11-03 00:24:35.000000000 +0900
>> +++ service.rb  2008-11-03 00:24:35.000000000 +0900
>> @@ -128,7 +128,7 @@
>>        API.new('QueryServiceLockStatus', 'LPLP', 'B', 'advapi32')
>>        API.new('QueryServiceStatus', 'LP', 'B', 'advapi32')
>>        API.new('QueryServiceStatusEx', 'LLPLP', 'B', 'advapi32')
>> -      API.new('RegisterServiceCtrlHandler', 'PL', 'L', 'advapi32')
>> +      API.new('RegisterServiceCtrlHandler', 'PK', 'L', 'advapi32')
>>        API.new('RegisterServiceCtrlHandlerEx', 'PPP', 'L', 'advapi32')
>>        API.new('SetServiceBits', 'LLII', 'B', 'advapi32')
>>        API.new('SetServiceStatus', 'LP', 'B', 'advapi32')
>
> Ok, I've updated both RegisterServiceCtrlHandler and
> RegisterServiceCtrlHandlerEx in CVS. That update will be part of the
> 0.9.6 release of windows-pr.
>
>> Patch for win32-api/ext/win32/api.c
>> --- api.c.old   2008-11-03 00:25:46.000000000 +0900
>> +++ api.c       2008-11-03 00:25:05.000000000 +0900
>> @@ -12,6 +12,7 @@
>>  #define _T_STRING   5
>>
>>  VALUE cAPIError, cCallbackError;
>> +static VALUE ActiveCallback = Qnil;
>>
>>  typedef struct {
>>      HANDLE library;
>> @@ -109,6 +110,7 @@
>>   */
>>  static VALUE callback_init(int argc, VALUE* argv, VALUE self)  {
>> +   extern void *CallbackTable[];
>>     VALUE v_proto, v_return, v_proc;
>>     int i;
>>
>> @@ -131,6 +133,8 @@
>>     rb_iv_set(self, "@function", v_proc);
>>     rb_iv_set(self, "@prototype", v_proto);
>>     rb_iv_set(self, "@return_type", v_return);
>> +   rb_iv_set(self, "@address",
>> ULONG2NUM((LPARAM)CallbackTable[RSTRING(v_proto)
>
> Whoops. I think something got cut off here. What should that be?
>
 +   rb_iv_set(self, "@address",
 ULONG2NUM((LPARAM)CallbackTable[RSTRING(v_proto)
Should be one line.

>> +   ActiveCallback = self;
>>
>>     return self;
>>  }
>> @@ -473,7 +477,6 @@
>>     DWORD params[16];
>>  } CALLPARAM;
>>
>> -static VALUE ActiveCallback;
>>
>>  DWORD CallbackFunction(CALLPARAM param)  { @@ -811,6 +814,7 @@
>>     rb_define_attr(cCallback, "return_type", 1, 0);
>>
>>     /* The numeric address of the function pointer */
>> +   rb_define_attr(cCallback, "address", 1, 0);
>>     rb_define_attr(cFunction, "address", 1, 0);
>>
>>    /* Constants */
>
> <snip the pure Ruby stuff>
>
> Looks good. It may be a little while before I can get back to it, since
> I'm getting swamped at work.
>

>
> PS - Maybe it's time to revisit
> http://rubyforge.org/tracker/index.php?func=detail&aid=16627&group_id=85
> &atid=413, too.
>
Yes. The inter process communication with the socket might a good choice.
I will test it.

Regards,

Park Heesob


More information about the win32utils-devel mailing list