From noreply at rubyforge.org Mon Jul 13 17:19:59 2009 From: noreply at rubyforge.org (noreply at rubyforge.org) Date: Mon, 13 Jul 2009 17:19:59 -0400 (EDT) Subject: [Win32utils-devel] [ win32utils-Bugs-26603 ] TaskScheduler creates .job file on 2k3 but does not register job with the scheduler Message-ID: <20090713211959.150BC197858D@rubyforge.org> Bugs item #26603, was opened at 2009-07-13 14:19 You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=411&aid=26603&group_id=85 Category: win32-taskscheduler Group: None Status: Open Resolution: None Priority: 3 Submitted By: Erik Hollensbe (erikh) Assigned to: Nobody (None) Summary: TaskScheduler creates .job file on 2k3 but does not register job with the scheduler Initial Comment: Using this code: require 'rubygems' require 'win32/taskscheduler' t = Win32::TaskScheduler.new("task", { "start_month" => 4, "start_day" => 11, "start_hour" => 7, "start_minute" => 14, "trigger_type" => Win32::TaskScheduler::DAILY, "type" => { "days_interval" => 2 } }) t.application_name = "ruby test.rb" t.save Which is taken almost verbatim out of: http://jp.rubyist.net/magazine/?0005-RLR-en It saves C:\Windows\Tasks\task.job but upon viewing the scheduled tasks list, it does not appear. I'm not really a windows maven, but here's what I know about the environment: Windows 2003 Server R2 Ruby mingw32 build of 1.8.6 pl 114 (2008-03-03) gem list --local reports these gems in use: win32-api 1.4.3 windows-api 0.3.0 windows-pr 1.0.5 win32-taskscheduler 0.2.0 HTH, Let me know if you require any more information. Thanks as always, -Erik ---------------------------------------------------------------------- You can respond by visiting: http://rubyforge.org/tracker/?func=detail&atid=411&aid=26603&group_id=85 From djberg96 at gmail.com Tue Jul 14 14:31:09 2009 From: djberg96 at gmail.com (Daniel Berger) Date: Tue, 14 Jul 2009 12:31:09 -0600 Subject: [Win32utils-devel] Multiple clipboards? Message-ID: <005f01ca04b1$4376c4a0$ca644de0$@com> Hi all, I'm back from vacation! Anyway, I was just wondering if Windows supported multiple, separate clipboards out of the box, or if that is only possible with 3rd party add-ons. I'm wondering if we should alter Clipboard.set_data so that it takes a "clipboard_number" parameter. Regards, Dan From waldo1979 at gmail.com Tue Jul 14 15:41:22 2009 From: waldo1979 at gmail.com (Robert Clugston) Date: Tue, 14 Jul 2009 12:41:22 -0700 Subject: [Win32utils-devel] Multiple clipboards? In-Reply-To: <005f01ca04b1$4376c4a0$ca644de0$@com> References: <005f01ca04b1$4376c4a0$ca644de0$@com> Message-ID: <735576A6-A39E-4194-8C49-261D5BBFE4CC@gmail.com> I know that versions of Office support Multiple Clipboards: http://en.wikipedia.org/wiki/Clipboard_manager If I had to guess I'd say that Window's default clipboard manager only supports 1 objects. -Rob On Jul 14, 2009, at 11:31 AM, Daniel Berger wrote: > Hi all, > > I'm back from vacation! > > Anyway, I was just wondering if Windows supported multiple, separate > clipboards out of the box, or if that is only possible with 3rd party > add-ons. > > I'm wondering if we should alter Clipboard.set_data so that it takes a > "clipboard_number" parameter. > > Regards, > > Dan > > _______________________________________________ > win32utils-devel mailing list > win32utils-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/win32utils-devel From djberg96 at gmail.com Tue Jul 14 22:45:38 2009 From: djberg96 at gmail.com (Daniel Berger) Date: Tue, 14 Jul 2009 20:45:38 -0600 Subject: [Win32utils-devel] JRuby installer? Message-ID: <007b01ca04f6$575b0810$06111830$@com> Hi all, The JRuby folks are looking for someone to create a bonafide installer for JRuby if anyone's interested. Something along the lines of the one-click's installer I imagine. Head over to #jruby on IRC and talk to headius if you're interested. Regards, Dan From djberg96 at gmail.com Wed Jul 15 09:51:37 2009 From: djberg96 at gmail.com (Daniel Berger) Date: Wed, 15 Jul 2009 07:51:37 -0600 Subject: [Win32utils-devel] Working on FFI win32-api again Message-ID: <008d01ca0553$611d8730$23589590$@com> Hi, I've been working on the FFI version of win32-api again and I've got the basic test down to 2 errors using JRuby 1.3.1. You can checkout the latest win32-api and look at lib/ffi/win32/api.rb: c:\Users\djberge\workspace\win32-api>jake test (in C:/Users/djberge/workspace/win32-api) c:/jruby/bin/../bin/jruby.bat -w -I"lib;lib/ffi" "C:/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.r b" "test/test_win32_api.rb" Loaded suite C:/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader Started .FF.............. Finished in 1.386 seconds. 1) Failure: test_call_expected_failures(TC_Win32_API) [test/test_win32_api.rb:114]: exception expected but was Class: Message: <"Value test is not an integer"> ---Backtrace--- test/test_win32_api.rb:114:in `test_call_expected_failures' test/test_win32_api.rb:114:in `test_call_expected_failures' --------------- 2) Failure: test_call_with_void(TC_Win32_API) [test/test_win32_api.rb:41]: Exception raised: Class: Message: <"wrong number of arguments(1 for 0)"> ---Backtrace--- test/test_win32_api.rb:41:in `test_call_with_void' test/test_win32_api.rb:41:in `test_call_with_void' --------------- 17 tests, 41 assertions, 2 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications The first failure is coming from this: assert_raise(TypeError){ @gcd.call('test', @buf) } Here I'm passing a string 'test' instead of a long. This may be an issue with FFI itself, so I'm not sure if we can fix it. The second failure is coming from this: assert_nothing_raised{ @gle.call(nil) } Here I'm passing an explicit nil for a void parameter. Again, maybe FFI simply doesn't allow this. Regards, Dan From djberg96 at gmail.com Wed Jul 15 19:15:00 2009 From: djberg96 at gmail.com (Daniel Berger) Date: Wed, 15 Jul 2009 17:15:00 -0600 Subject: [Win32utils-devel] Possible method - Process.hide Message-ID: <009d01ca05a2$150ffa90$3f2fefb0$@com> Hi all, What do you think about adding a Process.hide method? This would make it so that the current process does not show up in the Task Manager. http://search.cpan.org/~rootkwok/Win32-Process-Hide-1.84/ Here's the implementation that library uses. Regards, Dan #include #include #include #include #pragma comment(lib,"advapi32.lib") #define NT_SUCCESS(Status)((NTSTATUS)(Status) >= 0) #define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS)0xC0000004L) #define STATUS_ACCESS_DENIED ((NTSTATUS)0xC0000022L) typedef LONG NTSTATUS; typedef struct _IO_STATUS_BLOCK { NTSTATUS Status; ULONG Information; } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK; typedef struct _UNICODE_STRING { USHORT Length; USHORT MaximumLength; PWSTR Buffer; } UNICODE_STRING, *PUNICODE_STRING; #define OBJ_INHERIT 0x00000002L #define OBJ_PERMANENT 0x00000010L #define OBJ_EXCLUSIVE 0x00000020L #define OBJ_CASE_INSENSITIVE 0x00000040L #define OBJ_OPENIF 0x00000080L #define OBJ_OPENLINK 0x00000100L #define OBJ_KERNEL_HANDLE 0x00000200L #define OBJ_VALID_ATTRIBUTES 0x000003F2L typedef struct _OBJECT_ATTRIBUTES{ ULONG Length; HANDLE RootDirectory; PUNICODE_STRING ObjectName; ULONG Attributes; PVOID SecurityDescriptor; PVOID SecurityQualityOfService; } OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES; typedef NTSTATUS (CALLBACK* ZWOPENSECTION)( OUT PHANDLE SectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes ); typedef VOID (CALLBACK* RTLINITUNICODESTRING)( IN OUT PUNICODE_STRING DestinationString, IN PCWSTR SourceString ); RTLINITUNICODESTRING RtlInitUnicodeString; ZWOPENSECTION ZwOpenSection; HMODULE g_hNtDLL = NULL; PVOID g_pMapPhysicalMemory = NULL; HANDLE g_hMPM = NULL; OSVERSIONINFO g_osvi; BOOL InitNTDLL(){ g_hNtDLL = LoadLibrary("ntdll.dll"); if (NULL == g_hNtDLL) return FALSE; RtlInitUnicodeString = (RTLINITUNICODESTRING)GetProcAddress( g_hNtDLL, "RtlInitUnicodeString"); ZwOpenSection = (ZWOPENSECTION)GetProcAddress( g_hNtDLL, "ZwOpenSection"); return TRUE; } VOID CloseNTDLL(){ if(NULL != g_hNtDLL) FreeLibrary(g_hNtDLL); g_hNtDLL = NULL; } VOID SetPhyscialMemorySectionCanBeWrited(HANDLE hSection){ PACL pDacl = NULL; PSECURITY_DESCRIPTOR pSD = NULL; PACL pNewDacl = NULL; DWORD dwRes = GetSecurityInfo(hSection, SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, NULL,NULL, &pDacl, NULL, &pSD); if(ERROR_SUCCESS != dwRes){ if(pSD) LocalFree(pSD); if(pNewDacl) LocalFree(pNewDacl); } EXPLICIT_ACCESS ea; RtlZeroMemory(&ea, sizeof(EXPLICIT_ACCESS)); ea.grfAccessPermissions = SECTION_MAP_WRITE; ea.grfAccessMode = GRANT_ACCESS; ea.grfInheritance= NO_INHERITANCE; ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME; ea.Trustee.TrusteeType = TRUSTEE_IS_USER; ea.Trustee.ptstrName = "CURRENT_USER"; dwRes = SetEntriesInAcl(1,&ea,pDacl,&pNewDacl); if(ERROR_SUCCESS != dwRes){ if(pSD) LocalFree(pSD); if(pNewDacl) LocalFree(pNewDacl); } dwRes = SetSecurityInfo(hSection,SE_KERNEL_OBJECT,DACL_SECURITY_INFORMATION,NULL,NUL L,pNewDacl,NULL); if(ERROR_SUCCESS != dwRes){ if(pSD) LocalFree(pSD); if(pNewDacl) LocalFree(pNewDacl); } } HANDLE OpenPhysicalMemory(){ NTSTATUS status; UNICODE_STRING physmemString; OBJECT_ATTRIBUTES attributes; ULONG PhyDirectory; g_osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx (&g_osvi); if (5 != g_osvi.dwMajorVersion) return NULL; switch(g_osvi.dwMinorVersion){ case 0: PhyDirectory = 0x30000; break; case 1: PhyDirectory = 0x39000; break; default: return NULL; } RtlInitUnicodeString(&physmemString, L"\\Device\\PhysicalMemory"); attributes.Length = sizeof(OBJECT_ATTRIBUTES); attributes.RootDirectory = NULL; attributes.ObjectName = &physmemString; attributes.Attributes = 0; attributes.SecurityDescriptor = NULL; attributes.SecurityQualityOfService = NULL; status = ZwOpenSection(&g_hMPM, SECTION_MAP_READ|SECTION_MAP_WRITE, &attributes); if(status == STATUS_ACCESS_DENIED){ status = ZwOpenSection(&g_hMPM, READ_CONTROL|WRITE_DAC, &attributes); SetPhyscialMemorySectionCanBeWrited(g_hMPM); CloseHandle(g_hMPM); status = ZwOpenSection(&g_hMPM, SECTION_MAP_READ|SECTION_MAP_WRITE, &attributes); } if(!NT_SUCCESS(status)) return NULL; g_pMapPhysicalMemory = MapViewOfFile(g_hMPM, FILE_MAP_READ|FILE_MAP_WRITE, 0, PhyDirectory, 0x1000); if( g_pMapPhysicalMemory == NULL ) return NULL; return g_hMPM; } PVOID LinearToPhys(PULONG BaseAddress, PVOID addr){ ULONG VAddr = (ULONG)addr,PGDE,PTE,PAddr; PGDE = BaseAddress[VAddr>>22]; if (0 == (PGDE&1)) return 0; ULONG tmp = PGDE & 0x00000080; if (0 != tmp){ PAddr = (PGDE & 0xFFC00000) + (VAddr & 0x003FFFFF); }else{ PGDE = (ULONG)MapViewOfFile(g_hMPM, 4, 0, PGDE & 0xfffff000, 0x1000); PTE = ((PULONG)PGDE)[(VAddr&0x003FF000)>>12]; if (0 == (PTE&1)) return 0; PAddr=(PTE&0xFFFFF000)+(VAddr&0x00000FFF); UnmapViewOfFile((PVOID)PGDE); } return (PVOID)PAddr; } ULONG GetData(PVOID addr){ ULONG phys = (ULONG)LinearToPhys((PULONG)g_pMapPhysicalMemory, (PVOID)addr); PULONG tmp = (PULONG)MapViewOfFile(g_hMPM, FILE_MAP_READ|FILE_MAP_WRITE, 0, phys & 0xfffff000, 0x1000); if (0 == tmp) return 0; ULONG ret = tmp[(phys & 0xFFF)>>2]; UnmapViewOfFile(tmp); return ret; } BOOL SetData(PVOID addr,ULONG data){ ULONG phys = (ULONG)LinearToPhys((PULONG)g_pMapPhysicalMemory, (PVOID)addr); PULONG tmp = (PULONG)MapViewOfFile(g_hMPM, FILE_MAP_WRITE, 0, phys & 0xfffff000, 0x1000); if (0 == tmp) return FALSE; tmp[(phys & 0xFFF)>>2] = data; UnmapViewOfFile(tmp); return TRUE; } long __stdcall exeception(struct _EXCEPTION_POINTERS *tmp){ ExitProcess(0); return 1 ; } BOOL HideProcessEx(){ if (FALSE == InitNTDLL()) return FALSE; if (0 == OpenPhysicalMemory()) return FALSE; ULONG thread = GetData((PVOID)0xFFDFF124); ULONG process = GetData(PVOID(thread + 0x44)); ULONG fw, bw; if (0 == g_osvi.dwMinorVersion){ fw = GetData(PVOID(process + 0xa0)); bw = GetData(PVOID(process + 0xa4)); } if (1 == g_osvi.dwMinorVersion){ fw = GetData(PVOID(process + 0x88)); bw = GetData(PVOID(process + 0x8c)); } SetData(PVOID(fw + 4), bw); SetData(PVOID(bw), fw); CloseHandle(g_hMPM); CloseNTDLL(); return TRUE; } BOOL HideProcess(){ static BOOL b_hide = false; if (!b_hide) { b_hide = true; HideProcessEx(); return true; } return true; } From luislavena at gmail.com Wed Jul 15 19:19:50 2009 From: luislavena at gmail.com (Luis Lavena) Date: Wed, 15 Jul 2009 20:19:50 -0300 Subject: [Win32utils-devel] JRuby installer? In-Reply-To: <007b01ca04f6$575b0810$06111830$@com> References: <007b01ca04f6$575b0810$06111830$@com> Message-ID: <71166b3b0907151619p5859083s2f6adf9f3010f922@mail.gmail.com> On Tue, Jul 14, 2009 at 11:45 PM, Daniel Berger wrote: > Hi all, > > The JRuby folks are looking for someone to create a bonafide installer for > JRuby if anyone's interested. Something along the lines of the one-click's > installer I imagine. > Something in the lines of the new installer or the current NSIS based installer? > Head over to #jruby on IRC and talk to headius if you're interested. Can't jump to IRC, but can someone point to Charles to take a look to this type of installer? http://blog.mmediasys.com/2009/06/28/rubyinstaller-preview1-released/ And some screenshots (the one with the RubyInstaller logo): http://blog.smajn.net/2009/07/installing-ruby-191-rails-232-and.html -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry From djberg96 at gmail.com Thu Jul 16 01:45:23 2009 From: djberg96 at gmail.com (Daniel Berger) Date: Wed, 15 Jul 2009 23:45:23 -0600 Subject: [Win32utils-devel] Process.getpriority implementation Message-ID: <00a401ca05d8$9e47f070$dad7d150$@com> Hi, How does this look for a Process.getpriority implementation for Windows? # Retrieves the priority class for the specified process id +int+. Unlike # the default implementation, lower values do not necessarily correspond to # higher priority classes. # # The +kind+ parameter is ignored but present for API compatibility. # You can only retrieve process information, not process group or user # information, so it is effectively always Process::PRIO_PROCESS. # # Possible return values are: # # 32 - NORMAL_PRIORITY_CLASS # 64 - IDLE_PRIORITY_CLASS # 128 - HIGH_PRIORITY_CLASS # 256 - REALTIME_PRIORITY_CLASS # 16384 - BELOW_NORMAL_PRIORITY_CLASS # 32768 - ABOVE_NORMAL_PRIORITY_CLASS # def getpriority(kind = nil, int = nil) raise ArgumentError unless int handle = OpenProcess(PROCESS_QUERY_INFORMATION, 0 , int) if handle == INVALID_HANDLE_VALUE raise Error, get_last_error end priority_class = GetPriorityClass(handle) if priority_class == 0 raise Error, get_last_error end priority_class end From djberg96 at gmail.com Fri Jul 17 12:27:43 2009 From: djberg96 at gmail.com (Daniel Berger) Date: Fri, 17 Jul 2009 10:27:43 -0600 Subject: [Win32utils-devel] JRuby installer? In-Reply-To: <71166b3b0907151619p5859083s2f6adf9f3010f922@mail.gmail.com> References: <007b01ca04f6$575b0810$06111830$@com> <71166b3b0907151619p5859083s2f6adf9f3010f922@mail.gmail.com> Message-ID: <6037b70c0907170927q60326e13q206f4b0d1f1994ee@mail.gmail.com> On Wed, Jul 15, 2009 at 5:19 PM, Luis Lavena wrote: > On Tue, Jul 14, 2009 at 11:45 PM, Daniel Berger wrote: >> Hi all, >> >> The JRuby folks are looking for someone to create a bonafide installer for >> JRuby if anyone's interested. Something along the lines of the one-click's >> installer I imagine. >> > > Something in the lines of the new installer or the current NSIS based installer? > >> Head over to #jruby on IRC and talk to headius if you're interested. > > Can't jump to IRC, but can someone point to Charles to take a look to > this type of installer? > > http://blog.mmediasys.com/2009/06/28/rubyinstaller-preview1-released/ > > And some screenshots (the one with the RubyInstaller logo): > > http://blog.smajn.net/2009/07/installing-ruby-191-rails-232-and.html Yep, basically something like that but for JRuby. Regards, Dan From djberg96 at gmail.com Fri Jul 17 12:29:38 2009 From: djberg96 at gmail.com (Daniel Berger) Date: Fri, 17 Jul 2009 10:29:38 -0600 Subject: [Win32utils-devel] JRuby installer? In-Reply-To: <71166b3b0907151619p5859083s2f6adf9f3010f922@mail.gmail.com> References: <007b01ca04f6$575b0810$06111830$@com> <71166b3b0907151619p5859083s2f6adf9f3010f922@mail.gmail.com> Message-ID: <6037b70c0907170929s47577534rcfda038ef914ab4a@mail.gmail.com> On Wed, Jul 15, 2009 at 5:19 PM, Luis Lavena wrote: > On Tue, Jul 14, 2009 at 11:45 PM, Daniel Berger wrote: >> Hi all, >> >> The JRuby folks are looking for someone to create a bonafide installer for >> JRuby if anyone's interested. Something along the lines of the one-click's >> installer I imagine. >> > > Something in the lines of the new installer or the current NSIS based installer? > >> Head over to #jruby on IRC and talk to headius if you're interested. > > Can't jump to IRC, but can someone point to Charles to take a look to > this type of installer? > > http://blog.mmediasys.com/2009/06/28/rubyinstaller-preview1-released/ > > And some screenshots (the one with the RubyInstaller logo): > > http://blog.smajn.net/2009/07/installing-ruby-191-rails-232-and.html Oh, Charles just mentioned Install4J, because it can bundle or fetch a jre if necessary. Dunno if you've ever used that. Regards, Dan From luislavena at gmail.com Fri Jul 17 13:27:07 2009 From: luislavena at gmail.com (Luis Lavena) Date: Fri, 17 Jul 2009 14:27:07 -0300 Subject: [Win32utils-devel] JRuby installer? In-Reply-To: <6037b70c0907170929s47577534rcfda038ef914ab4a@mail.gmail.com> References: <007b01ca04f6$575b0810$06111830$@com> <71166b3b0907151619p5859083s2f6adf9f3010f922@mail.gmail.com> <6037b70c0907170929s47577534rcfda038ef914ab4a@mail.gmail.com> Message-ID: <71166b3b0907171027s52fccef5nd7649395a9e80d03@mail.gmail.com> On Fri, Jul 17, 2009 at 1:29 PM, Daniel Berger wrote: > On Wed, Jul 15, 2009 at 5:19 PM, Luis Lavena wrote: >> On Tue, Jul 14, 2009 at 11:45 PM, Daniel Berger wrote: >>> Hi all, >>> >>> The JRuby folks are looking for someone to create a bonafide installer for >>> JRuby if anyone's interested. Something along the lines of the one-click's >>> installer I imagine. >>> >> >> Something in the lines of the new installer or the current NSIS based installer? >> >>> Head over to #jruby on IRC and talk to headius if you're interested. >> >> Can't jump to IRC, but can someone point to Charles to take a look to >> this type of installer? >> >> http://blog.mmediasys.com/2009/06/28/rubyinstaller-preview1-released/ >> >> And some screenshots (the one with the RubyInstaller logo): >> >> http://blog.smajn.net/2009/07/installing-ruby-191-rails-232-and.html > > Oh, Charles just mentioned Install4J, because it can bundle or fetch a > jre if necessary. Dunno if you've ever used that. > Nop, not a Java fan, was suggesting options. InnoSetup can also, programmatically depend or install components form internet. -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry From djberg96 at gmail.com Sat Jul 18 08:32:09 2009 From: djberg96 at gmail.com (Daniel Berger) Date: Sat, 18 Jul 2009 06:32:09 -0600 Subject: [Win32utils-devel] Simulating Process.getrlimit Message-ID: <001c01ca07a3$c68c5630$53a50290$@com> Hi, I've added several job functions and constants to the windows-pr library (in CVS). I was hoping that with the job functions we could provide an analogue for Process.getrlimit and Process.setrlimit. My initial stab at Process.getrlimit doesn't quite work. I always get 0 for the result: module Process undef_method :getrlimit unless defined? RLIMIT_CPU RLIMIT_CPU = 0 # PerProcessUserTimeLimit RLIMIT_FSIZE = 1 # Hard coded at 4TB - 64K (assumes NTFS) RLIMIT_AS = 5 # ProcessMemoryLimit RLIMIT_RSS = 5 # ProcessMemoryLimit RLIMIT_VMEM = 5 # ProcessMemoryLimit end def getrlimit(resource) # Strictly for API compatibility (actually 4 GB on FAT32) if resource == RLIMIT_FSIZE return ((1024**4) * 4) - (1024 * 64) end job_name = 'ruby_' + Time.now.to_s # Create a job object and add the current process to it handle = CreateJobObject(nil, job_name) if handle == 0 raise Error, get_last_error end begin unless AssignProcessToJobObject(handle, GetCurrentProcess()) raise Error, get_last_error end buf = 0.chr * 112 # sizeof(struct JOBJECT_EXTENDED_LIMIT_INFORMATION) val = nil # value returned at end of method case resource when RLIMIT_CPU buf[16,4] = [JOB_OBJECT_LIMIT_PROCESS_TIME].pack('L') when RLIMIT_AS, RLIMIT_VMEM, RLIMIT_RSS buf[16,4] = [JOB_OBJECT_LIMIT_PROCESS_MEMORY].pack('L') end bool = QueryInformationJobObject( handle, JobObjectExtendedLimitInformation, buf, buf.size, nil ) unless bool raise Error, get_last_error end case resource when Process::RLIMIT_CPU val = buf[0,8].unpack('Q').first when RLIMIT_AS, RLIMIT_VMEM, RLIMIT_RSS val = buf[96,4].unpack('L').first end ensure CloseHandle(handle) end [val, val] # Return an array of two values to comply with spec end end What am I doing wrong there? The other problem I noticed is that you can't call Process.getrlimit more than once per process, presumably because I don't call TerminateJobObject. But if I call that it kills the process. I don't see a way around that. I didn't see a way to remove a process from a job object first. Is there a way? Also, does the above approach seem reasonable in general? Any suggestions for other RLIMIT constants? Regards, Dan From phasis at gmail.com Sat Jul 18 10:46:16 2009 From: phasis at gmail.com (Heesob Park) Date: Sat, 18 Jul 2009 23:46:16 +0900 Subject: [Win32utils-devel] Simulating Process.getrlimit In-Reply-To: <001c01ca07a3$c68c5630$53a50290$@com> References: <001c01ca07a3$c68c5630$53a50290$@com> Message-ID: Hi, 2009/7/18 Daniel Berger : > Hi, > > I've added several job functions and constants to the windows-pr library (in > CVS). I was hoping that with the job functions we could provide an analogue > for Process.getrlimit and Process.setrlimit. > > My initial stab at Process.getrlimit doesn't quite work. I always get 0 for > the result: > > module Process > ? undef_method :getrlimit > > ? unless defined? RLIMIT_CPU > ? ? ?RLIMIT_CPU ? ?= 0 # PerProcessUserTimeLimit > ? ? ?RLIMIT_FSIZE ?= 1 # Hard coded at 4TB - 64K (assumes NTFS) > ? ? ?RLIMIT_AS ? ? = 5 # ProcessMemoryLimit > ? ? ?RLIMIT_RSS ? ?= 5 # ProcessMemoryLimit > ? ? ?RLIMIT_VMEM ? = 5 # ProcessMemoryLimit > ? end > > ? def getrlimit(resource) > ? ? ?# Strictly for API compatibility (actually 4 GB on FAT32) > ? ? ?if resource == RLIMIT_FSIZE > ? ? ? ? return ((1024**4) * 4) - (1024 * 64) > ? ? ?end > > ? ? ?job_name = 'ruby_' + Time.now.to_s > > ? ? ?# Create a job object and add the current process to it > ? ? ?handle = CreateJobObject(nil, job_name) > > ? ? ?if handle == 0 > ? ? ? ? raise Error, get_last_error > ? ? ?end > > ? ? ?begin > ? ? ? ? unless AssignProcessToJobObject(handle, GetCurrentProcess()) > ? ? ? ? ? ?raise Error, get_last_error > ? ? ? ? end > > ? ? ? ? buf = 0.chr * 112 # sizeof(struct > JOBJECT_EXTENDED_LIMIT_INFORMATION) > ? ? ? ? val = nil ? ? ? ? # value returned at end of method > > ? ? ? ? case resource > ? ? ? ? when RLIMIT_CPU > ? ? ? ? ? ?buf[16,4] = [JOB_OBJECT_LIMIT_PROCESS_TIME].pack('L') > ? ? ? ? when RLIMIT_AS, RLIMIT_VMEM, RLIMIT_RSS > ? ? ? ? ? ?buf[16,4] = [JOB_OBJECT_LIMIT_PROCESS_MEMORY].pack('L') > ? ? ? ? end > > ? ? ? ? bool = QueryInformationJobObject( > ? ? ? ? ? ?handle, > ? ? ? ? ? ?JobObjectExtendedLimitInformation, > ? ? ? ? ? ?buf, > ? ? ? ? ? ?buf.size, > ? ? ? ? ? ?nil > ? ? ? ? ) > > ? ? ? ? unless bool > ? ? ? ? ? ?raise Error, get_last_error > ? ? ? ? end > > ? ? ? ? case resource > ? ? ? ? when Process::RLIMIT_CPU > ? ? ? ? ? ?val = buf[0,8].unpack('Q').first > ? ? ? ? when RLIMIT_AS, RLIMIT_VMEM, RLIMIT_RSS > ? ? ? ? ? ?val = buf[96,4].unpack('L').first > ? ? ? ? end > ? ? ?ensure > ? ? ? ? CloseHandle(handle) > ? ? ?end > > ? ? ?[val, val] # Return an array of two values to comply with spec > ? end > end > > What am I doing wrong there? > I guess the value 0 means no limit. If you call QueryInformationJobObject after setting some specific limit with SetInformationJobObject, you will get the same value. > The other problem I noticed is that you can't call Process.getrlimit more > than once per process, presumably because I don't call TerminateJobObject. > But if I call that it kills the process. I don't see a way around that. I > didn't see a way to remove a process from a job object first. Is there a > way? > If you want the information of the current process only, you don't need to call CreateJobObject and AssignProcessToJobObject, just call QueryInformationJobObject with null job handle. But SetInformationJobObject cannot be called with null job handle. > Also, does the above approach seem reasonable in general? Any suggestions > for other RLIMIT constants? > I have no idea. Regards, Park Heesob From djberg96 at gmail.com Mon Jul 20 11:26:37 2009 From: djberg96 at gmail.com (Daniel Berger) Date: Mon, 20 Jul 2009 09:26:37 -0600 Subject: [Win32utils-devel] Simulating Process.getrlimit In-Reply-To: References: <001c01ca07a3$c68c5630$53a50290$@com> Message-ID: <6037b70c0907200826q665ed2e8yed89078c1852c140@mail.gmail.com> Hi, > I guess the value 0 means no limit. Ok, thanks. >> The other problem I noticed is that you can't call Process.getrlimit more >> than once per process, presumably because I don't call TerminateJobObject. >> But if I call that it kills the process. I don't see a way around that. I >> didn't see a way to remove a process from a job object first. Is there a >> way? >> > If you want the information of the current process only, you don't > need to call CreateJobObject and AssignProcessToJobObject, just call > QueryInformationJobObject with null job handle. > But SetInformationJobObject cannot be called with null job handle. I get an error on both XP and Vista if I pass a null filehandle. require 'windows/process' require 'windows/error' include Windows::Process include Windows::Error buf = 0.chr * 48 val = nil # Set the LimitFlag buf[16,4] = [JOB_OBJECT_LIMIT_PROCESS_TIME].pack('L') bool = QueryInformationJobObject( nil, JobObjectBasicLimitInformation, buf, buf.size, nil ) unless bool raise Error, get_last_error end [val, val] # Return an array of two values to comply with spec What have I done wrong? Thanks, Dan From phasis at gmail.com Mon Jul 20 20:45:25 2009 From: phasis at gmail.com (Heesob Park) Date: Tue, 21 Jul 2009 09:45:25 +0900 Subject: [Win32utils-devel] Simulating Process.getrlimit In-Reply-To: <6037b70c0907200826q665ed2e8yed89078c1852c140@mail.gmail.com> References: <001c01ca07a3$c68c5630$53a50290$@com> <6037b70c0907200826q665ed2e8yed89078c1852c140@mail.gmail.com> Message-ID: Hi, 2009/7/21 Daniel Berger : > Hi, > >> I guess the value 0 means no limit. > > Ok, thanks. > >>> The other problem I noticed is that you can't call Process.getrlimit more >>> than once per process, presumably because I don't call TerminateJobObject. >>> But if I call that it kills the process. I don't see a way around that. I >>> didn't see a way to remove a process from a job object first. Is there a >>> way? >>> >> If you want the information of the current process only, you don't >> need to call CreateJobObject and AssignProcessToJobObject, just call >> QueryInformationJobObject with null job handle. >> But SetInformationJobObject cannot be called with null job handle. > > I get an error on both XP and Vista if I pass a null filehandle. > > require 'windows/process' > require 'windows/error' > include Windows::Process > include Windows::Error > > buf = 0.chr * 48 > val = nil > > # Set the LimitFlag > buf[16,4] = [JOB_OBJECT_LIMIT_PROCESS_TIME].pack('L') > > bool = QueryInformationJobObject( > ? nil, > ? JobObjectBasicLimitInformation, > ? buf, > ? buf.size, > ? nil > ) > > unless bool > ? raise Error, get_last_error > end > > [val, val] # Return an array of two values to comply with spec > > What have I done wrong? > Sorry for misleading. The null jobhandle works only if the current process is already a member of a predefined job. You must check it by calling IsProcessInJob function with null jobhandle. Regards, Park Heesob From phasis at gmail.com Fri Jul 31 23:34:59 2009 From: phasis at gmail.com (Heesob Park) Date: Sat, 1 Aug 2009 12:34:59 +0900 Subject: [Win32utils-devel] What's the plan for support 1.9.x Message-ID: Hi, I tried RubyInstaller preview 1 ruby 1.9.1p129 at http://rubyinstaller.org/downloads/ . I noticed the package contains no gems unlike OCI. When I tried to install windows-pr, it failed like this: C:\>gem install windows-pr Building native extensions. This could take a while... ERROR: Error installing windows-pr: ERROR: Failed to build gem native extension. c:/Ruby19/bin/ruby.exe extconf.rb checking for strncpy_s()... *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. I know I did not install developer kit. Is there any chance of providing binary gem for ruby 1.9.1 mingw32 version? Does anyone checked the compatibility of the win32-utils with ruby 1.9.x? Or just do not use win32-utils in ruby 1.9.x? Regards, Park Heesob