Bugzilla – Bug 3541
ACE_OS::event_init() needs ACE_OS::set_errno_to_last_error ();
Last modified: 2009-02-03 17:38:02
You need to log in before you can comment on or make changes to this bug.
ACE VERSION: 5.6 HOST MACHINE and OPERATING SYSTEM: Windows XP Pro 2002 SP3 COMPILER NAME AND VERSION (AND PATCHLEVEL): MS VS2008 VC9 THE $ACE_ROOT/ace/config.h FILE config-win32.h AREA/CLASS/EXAMPLE AFFECTED: OS_NS_Thread.cpp ACE_OS::event_init() DOES THE PROBLEM AFFECT: EXECUTION - application only SYNOPSIS: The return value of ACE_OS::last_error() after calling ACE_OS::event_init() does not necessarily reflect the value of Win32 GetLastError(). DESCRIPTION: ACE_OS::event_init() calls WIN32 CreateEvent(). The return value of GetLastError() after calling CreateEvent() is meaningful - if the event has just been created, GetLastError() returns 0. If the event has already been created GetLastError() returns ERROR_ALREADY_EXISTS (this does not necessarily indicate an error). Calling ACE_OS::last_error() after a call to ACE_OS::event_init() where the named event has already been created will not necessarily return ERROR_ALREADY_EXISTS - if errno is non-zero, that value will be returned instead. REPEAT BY: Create a named ACE_Event. Check that ACE_OS::last_error() is 0. Create another ACE_Event with the same name. Check that ACE_OS::last_error() is ERROR_ALREADY_EXISTS. The above will work if errno is 0 and will fail otherwise. To ensure failure call ACE_OS::last_error (2) first. SAMPLE FIX/WORKAROUND: Call ACE_OS::set_errno_to_last_error () after calling ACE_OS::event_init() in an application. I note that ACE_Pagefile_Memory_Pool::map() has this code snippet: first_time = ::GetLastError () == ERROR_ALREADY_EXISTS ? 0 : 1; where first_time is a a reference to an int and is passed as an argument to map(). I'd like to perform a similar check on the return of ACE_OS::event_init() in my app using ACE_OS::last_error(). I also note also that ACE_OS::mutex_init() does the following: // Make sure to set errno to ERROR_ALREADY_EXISTS if necessary. ACE_OS::set_errno_to_last_error (); It seems to me that ACE_OS::event_init() should do the same. If the maintainers agree I'll submit a bugzilla report and a fix. Thanks, Bill Rizzi
Can you extend a test under ACE_wrappers/tests as reproducer and put a patch of the test change and the code change here
The same changes are needed for ACE_OS::mutex_init() and ACE_OS::sema_init. This is true for any Win32 Create() function that can return ERROR_ALREADY_EXISTS. Here are the diffs for the proposed patch: OS_NS_Thread.inl: 475,476d474 < // Make sure to set errno to ERROR_ALREADY_EXISTS if necessary. < ACE_OS::set_errno_to_last_error (); 1711,1715c1709 < { < // Make sure to set errno to ERROR_ALREADY_EXISTS if necessary. < ACE_OS::set_errno_to_last_error (); < return 0; < } --- > return 0; 1799,1803c1793 < { < // Make sure to set errno to ERROR_ALREADY_EXISTS if necessary. < ACE_OS::set_errno_to_last_error (); < return 0; < } --- > return 0; OS_NS_Thread.cpp: 1926c1926 < // Make sure to set errno to ERROR_ALREADY_EXISTS if necessary. --- > // Make sure to set errno to ERROR_ALREADY_EXISTS if necessary. 2023,2027c2023 < { < // Make sure to set errno to ERROR_ALREADY_EXISTS if necessary. < ACE_OS::set_errno_to_last_error (); < return 0; < } --- > return 0; 2559,2563c2555 < { < // Make sure to set errno to ERROR_ALREADY_EXISTS if necessary. < ACE_OS::set_errno_to_last_error (); < return 0; < } --- > return 0;
can you create a unified diff (diff -u) and add it as attachment. Also add an extension to the regression test to reproduce this
Created an attachment (id=1048) [details] Unified diff of OS_NS_Thread.cpp
Created an attachment (id=1049) [details] Unified diff of OS_NS_Thread.inl
thanks, then we need an extended regression test
Created an attachment (id=1054) [details] Regression test This regression test checks Event, Mutex and Semaphore using their constructors rather than direct calls to ACE_OS::event_init(), etc.
Created an attachment (id=1055) [details] run_test.lst containing regression tests for Bug3500 and Bug3541
Created an attachment (id=1056) [details] tests.mpc containing Bug3500 and Bug3541
Marcel, also this one?
Test is in the repository and teststats show that the test always fails on windows
Fixed: Tue Feb 3 23:28:50 UTC 2009 Steve Huston <shuston@riverace.com> In the future, please diff against svn head, old->new. I have a cold and in my virus-fogged state it took me a while to realize the diffs were for ACE 5.6 and done new->old. But I caught on... ;-) Thanks for the fixes!