First Last Prev Next    No search results available
Details
: ACE_OS::event_init() needs ACE_OS::set_errno_to_last_erro...
Bug#: 3541
: ACE
: ACE Core
Status: RESOLVED
Resolution: FIXED
: All
: Windows XP
: 5.6.6
: P3
: normal
: ---

:
:
:
:
  Show dependency tree - Show dependency graph
People
Reporter: rizzi@softserv.com
Assigned To: DOC Center Support List (internal) <tao-support@dre.vanderbilt.edu>

Attachments
Unified diff of OS_NS_Thread.cpp (1.19 KB, patch)
2009-01-12 15:39, rizzi@softserv.com
Details | Diff
Unified diff of OS_NS_Thread.inl (1.02 KB, patch)
2009-01-12 15:40, rizzi@softserv.com
Details | Diff
Regression test (4.03 KB, text/plain)
2009-01-16 15:12, rizzi@softserv.com
Details
run_test.lst containing regression tests for Bug3500 and Bug3541 (7.39 KB, text/plain)
2009-01-16 15:13, rizzi@softserv.com
Details
tests.mpc containing Bug3500 and Bug3541 (27.46 KB, application/octet-stream)
2009-01-16 15:14, rizzi@softserv.com
Details


Note

You need to log in before you can comment on or make changes to this bug.

Related actions


Description:   Opened: 2009-01-07 17:51
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
------- Comment #1 From Johnny Willemsen 2009-01-08 01:11:28 -------
Can you extend a test under ACE_wrappers/tests as reproducer and put a patch of
the test change and the code change here
------- Comment #2 From rizzi@softserv.com 2009-01-09 16:13:08 -------
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;
------- Comment #3 From Johnny Willemsen 2009-01-10 01:36:23 -------
can you create a unified diff (diff -u) and add it as attachment. Also add an
extension to the regression test to reproduce this
------- Comment #4 From rizzi@softserv.com 2009-01-12 15:39:36 -------
Created an attachment (id=1048) [details]
Unified diff of OS_NS_Thread.cpp
------- Comment #5 From rizzi@softserv.com 2009-01-12 15:40:01 -------
Created an attachment (id=1049) [details]
Unified diff of OS_NS_Thread.inl
------- Comment #6 From Johnny Willemsen 2009-01-13 00:36:33 -------
thanks, then we need an extended regression test
------- Comment #7 From rizzi@softserv.com 2009-01-16 15:12:50 -------
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.
------- Comment #8 From rizzi@softserv.com 2009-01-16 15:13:56 -------
Created an attachment (id=1055) [details]
run_test.lst containing regression tests for Bug3500 and Bug3541
------- Comment #9 From rizzi@softserv.com 2009-01-16 15:14:56 -------
Created an attachment (id=1056) [details]
tests.mpc containing Bug3500 and Bug3541
------- Comment #10 From Johnny Willemsen 2009-01-17 13:15:59 -------
Marcel, also this one?
------- Comment #11 From Johnny Willemsen 2009-01-28 03:52:48 -------
Test is in the repository and teststats show that the test always fails on
windows
------- Comment #12 From Steve Huston 2009-02-03 17:38:02 -------
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!

First Last Prev Next    No search results available