All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [Xenomai] Posix named semaphore used by two separate applications
       [not found] <freemail.20180524135633.61226.1@fmxmldata03.freemail.hu>
@ 2018-05-24 14:18 ` Jan Kiszka
  2018-05-24 14:20   ` Jan Kiszka
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Kiszka @ 2018-05-24 14:18 UTC (permalink / raw)
  To: Paal Tamas, Xenomai

Again, re-adding the list - please always use "reply to all".

On 2018-05-24 13:56, Paal Tamas wrote:
> 
> 
> Jan Kiszka <jan.kiszka@siemens.com> írta:
>> [re-adding the list]
>>
>> On 2018-05-24 13:35, Paal Tamas wrote:
>>>
>>>
>>> Jan Kiszka <jan.kiszka@siemens.com> írta:
>>>> On 2018-05-24 10:50, Paal Tamas wrote:
>>>>> I would like to use the same named semaphore in two separate Xenomai binaries. I am using the Posix skin. It does not work as I am expecting it. 
>>>>> The first instance of my test application creates a named semaphore. It goes to sleep after that. The second instance of the same applications starts than. It realizes that the semaphore with the name already exists, so it opens it. The sem_open() returns a valid (like) pointer. After that all semaphore functions in this second application return EINVAL (22) (Invalid argument). Both the sem_wait() and the sem_close() function behave this way.
>>>>>
>>>>> The same procedure worked fine in 2.6.2.1 (the previous version I used). I tried 3.0.5 and the latest git repository too. The same bad behavior there.
>>>>>
>>>>
>>>> Did you configure userspace with --enable-pshared?
>>>>
>>>
>>> Yes. I invoked the "configure" script this way:
>>>
>>> ./configure --with-core=cobalt --enable-smp --enable-pshared
>>
>> OK.
>>
>>>
>>> This is my configuration:
>>>
>>> /xeno-config --info
>>> Xenomai version: Xenomai/cobalt v3.0.6 -- #50ef005 (2018-05-13 16:21:13 +0200)
>>> Linux clickandmove-NUC 4.9.51xeno #1 SMP Wed May 23 05:14:47 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux
>>> Kernel parameters: BOOT_IMAGE=/boot/vmlinuz-4.9.51xeno root=UUID=7e90a17b-1ea0-4b84-849f-7d621fe6d580 ro quiet splash vt.handoff=7
>>> I-pipe release #5 detected
>>> Cobalt core 3.0.6 detected
>>> Compiler: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)
>>> Build args: --with-core=cobalt --enable-smp --enable-pshared
>>>
>>> When I tried the git repository I cheated a bit. I could not find the configure script (neither some others) and all the makefile.in files were missing, so I copied these files from the xenomai-3.0.6.tar.bz2. I've never tried the git  repositore before, always used the bz2 file(s). In case of the 3.0.5 version I used the bz2 file for the tests.
>>
>> Just run scripts/bootstrap when using a git checkout.
> 
> Do I need any parameters to the scripts/bootstrap script in this case or I should simply run it?
> 
>>
>> To ensure that we are truly hunting a Xenomai issue: Does your testcase
>> work with plain Linux?
>>
> 
> Yes, it works fine under plain Linux. Sorry that I forgot to mention this...

Confirmed.

In fact, your test also exposes some cleanup issue: When terminating a
process, Xenomai does not remove the semaphore, and you need to reboot
to remove the object.

Will look into these problems.

Jan

-- 
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Xenomai] Posix named semaphore used by two separate applications
  2018-05-24 14:18 ` [Xenomai] Posix named semaphore used by two separate applications Jan Kiszka
@ 2018-05-24 14:20   ` Jan Kiszka
  2018-05-25  9:18     ` Paal Tamas
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Kiszka @ 2018-05-24 14:20 UTC (permalink / raw)
  To: Paal Tamas, Xenomai

On 2018-05-24 16:18, Jan Kiszka wrote:
> Again, re-adding the list - please always use "reply to all".
> 
> On 2018-05-24 13:56, Paal Tamas wrote:
>>
>>
>> Jan Kiszka <jan.kiszka@siemens.com> írta:
>>> [re-adding the list]
>>>
>>> On 2018-05-24 13:35, Paal Tamas wrote:
>>>>
>>>>
>>>> Jan Kiszka <jan.kiszka@siemens.com> írta:
>>>>> On 2018-05-24 10:50, Paal Tamas wrote:
>>>>>> I would like to use the same named semaphore in two separate Xenomai binaries. I am using the Posix skin. It does not work as I am expecting it. 
>>>>>> The first instance of my test application creates a named semaphore. It goes to sleep after that. The second instance of the same applications starts than. It realizes that the semaphore with the name already exists, so it opens it. The sem_open() returns a valid (like) pointer. After that all semaphore functions in this second application return EINVAL (22) (Invalid argument). Both the sem_wait() and the sem_close() function behave this way.
>>>>>>
>>>>>> The same procedure worked fine in 2.6.2.1 (the previous version I used). I tried 3.0.5 and the latest git repository too. The same bad behavior there.
>>>>>>
>>>>>
>>>>> Did you configure userspace with --enable-pshared?
>>>>>
>>>>
>>>> Yes. I invoked the "configure" script this way:
>>>>
>>>> ./configure --with-core=cobalt --enable-smp --enable-pshared
>>>
>>> OK.
>>>
>>>>
>>>> This is my configuration:
>>>>
>>>> /xeno-config --info
>>>> Xenomai version: Xenomai/cobalt v3.0.6 -- #50ef005 (2018-05-13 16:21:13 +0200)
>>>> Linux clickandmove-NUC 4.9.51xeno #1 SMP Wed May 23 05:14:47 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux
>>>> Kernel parameters: BOOT_IMAGE=/boot/vmlinuz-4.9.51xeno root=UUID=7e90a17b-1ea0-4b84-849f-7d621fe6d580 ro quiet splash vt.handoff=7
>>>> I-pipe release #5 detected
>>>> Cobalt core 3.0.6 detected
>>>> Compiler: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)
>>>> Build args: --with-core=cobalt --enable-smp --enable-pshared
>>>>
>>>> When I tried the git repository I cheated a bit. I could not find the configure script (neither some others) and all the makefile.in files were missing, so I copied these files from the xenomai-3.0.6.tar.bz2. I've never tried the git  repositore before, always used the bz2 file(s). In case of the 3.0.5 version I used the bz2 file for the tests.
>>>
>>> Just run scripts/bootstrap when using a git checkout.
>>
>> Do I need any parameters to the scripts/bootstrap script in this case or I should simply run it?
>>
>>>
>>> To ensure that we are truly hunting a Xenomai issue: Does your testcase
>>> work with plain Linux?
>>>
>>
>> Yes, it works fine under plain Linux. Sorry that I forgot to mention this...
> 
> Confirmed.
> 
> In fact, your test also exposes some cleanup issue: When terminating a
> process, Xenomai does not remove the semaphore, and you need to reboot
> to remove the object.

Correction: This is not a wrong behavior, Linux does the same. The test
code just has no chance to clean up a preexisting sem because of the
other problem (EINVAL).

Jan

> 
> Will look into these problems.
> 
> Jan
> 



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Xenomai] Posix named semaphore used by two separate applications
  2018-05-24 14:20   ` Jan Kiszka
@ 2018-05-25  9:18     ` Paal Tamas
  2018-05-26  5:09       ` Jan Kiszka
  0 siblings, 1 reply; 8+ messages in thread
From: Paal Tamas @ 2018-05-25  9:18 UTC (permalink / raw)
  To: xenomai



Jan Kiszka <jan.kiszka@siemens.com> írta:
>On 2018-05-24 16:18, Jan Kiszka wrote:
>> Again, re-adding the list - please always use "reply to all".
>> 
>> On 2018-05-24 13:56, Paal Tamas wrote:
>>>
>>>
>>> Jan Kiszka <jan.kiszka@siemens.com> írta:
>>>> [re-adding the list]
>>>>
>>>> On 2018-05-24 13:35, Paal Tamas wrote:
>>>>>
>>>>>
>>>>> Jan Kiszka <jan.kiszka@siemens.com> írta:
>>>>>> On 2018-05-24 10:50, Paal Tamas wrote:
>>>>>>> I would like to use the same named semaphore in two separate Xenomai binaries. I am using the Posix skin. It does not work as I am expecting it. 
>>>>>>> The first instance of my test application creates a named semaphore. It goes to sleep after that. The second instance of the same applications starts than. It realizes that the semaphore with the name already exists, so it opens it. The sem_open() returns a valid (like) pointer. After that all semaphore functions in this second application return EINVAL (22) (Invalid argument). Both the sem_wait() and the sem_close() function behave this way.
>>>>>>>
>>>>>>> The same procedure worked fine in 2.6.2.1 (the previous version I used). I tried 3.0.5 and the latest git repository too. The same bad behavior there.
>>>>>>>
>>>>>>
>>>>>> Did you configure userspace with --enable-pshared?
>>>>>>
>>>>>
>>>>> Yes. I invoked the "configure" script this way:
>>>>>
>>>>> ./configure --with-core=cobalt --enable-smp --enable-pshared
>>>>
>>>> OK.
>>>>
>>>>>
>>>>> This is my configuration:
>>>>>
>>>>> /xeno-config --info
>>>>> Xenomai version: Xenomai/cobalt v3.0.6 -- #50ef005 (2018-05-13 16:21:13 +0200)
>>>>> Linux clickandmove-NUC 4.9.51xeno #1 SMP Wed May 23 05:14:47 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux
>>>>> Kernel parameters: BOOT_IMAGE=/boot/vmlinuz-4.9.51xeno root=UUID=7e90a17b-1ea0-4b84-849f-7d621fe6d580 ro quiet splash vt.handoff=7
>>>>> I-pipe release #5 detected
>>>>> Cobalt core 3.0.6 detected
>>>>> Compiler: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)
>>>>> Build args: --with-core=cobalt --enable-smp --enable-pshared
>>>>>
>>>>> When I tried the git repository I cheated a bit. I could not find the configure script (neither some others) and all the makefile.in files were missing, so I copied these files from the xenomai-3.0.6.tar.bz2. I've never tried the git  repositore before, always used the bz2 file(s). In case of the 3.0.5 version I used the bz2 file for the tests.
>>>>
>>>> Just run scripts/bootstrap when using a git checkout.
>>>
>>> Do I need any parameters to the scripts/bootstrap script in this case or I should simply run it?
>>>
>>>>
>>>> To ensure that we are truly hunting a Xenomai issue: Does your testcase
>>>> work with plain Linux?
>>>>
>>>
>>> Yes, it works fine under plain Linux. Sorry that I forgot to mention this...
>> 
>> Confirmed.
>> 
>> In fact, your test also exposes some cleanup issue: When terminating a
>> process, Xenomai does not remove the semaphore, and you need to reboot
>> to remove the object.
>
>Correction: This is not a wrong behavior, Linux does the same. The test
>code just has no chance to clean up a preexisting sem because of the
>other problem (EINVAL).
>
>Jan
>
>> 
>> Will look into these problems.
>> 
>> Jan
>> 
>
I saw that you created some patches on this issue and modified the git repository. I cloned the latest one, rebuilt Xenomai and my test application but the original EINVAL, Invalid Argument error in case of the second instance of the test application still exists. In other words I do not see any change in the behavior.
Should I rebuild the Linux kernel too?

Thank you,
Tamas



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Xenomai] Posix named semaphore used by two separate applications
  2018-05-25  9:18     ` Paal Tamas
@ 2018-05-26  5:09       ` Jan Kiszka
  2018-05-28 11:10         ` Paal Tamas
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Kiszka @ 2018-05-26  5:09 UTC (permalink / raw)
  To: Paal Tamas, xenomai

On 2018-05-25 11:18, Paal Tamas wrote:
> 
> 
> Jan Kiszka <jan.kiszka@siemens.com> írta:
>> On 2018-05-24 16:18, Jan Kiszka wrote:
>>> Again, re-adding the list - please always use "reply to all".
>>>
>>> On 2018-05-24 13:56, Paal Tamas wrote:
>>>>
>>>>
>>>> Jan Kiszka <jan.kiszka@siemens.com> írta:
>>>>> [re-adding the list]
>>>>>
>>>>> On 2018-05-24 13:35, Paal Tamas wrote:
>>>>>>
>>>>>>
>>>>>> Jan Kiszka <jan.kiszka@siemens.com> írta:
>>>>>>> On 2018-05-24 10:50, Paal Tamas wrote:
>>>>>>>> I would like to use the same named semaphore in two separate Xenomai binaries. I am using the Posix skin. It does not work as I am expecting it. 
>>>>>>>> The first instance of my test application creates a named semaphore. It goes to sleep after that. The second instance of the same applications starts than. It realizes that the semaphore with the name already exists, so it opens it. The sem_open() returns a valid (like) pointer. After that all semaphore functions in this second application return EINVAL (22) (Invalid argument). Both the sem_wait() and the sem_close() function behave this way.
>>>>>>>>
>>>>>>>> The same procedure worked fine in 2.6.2.1 (the previous version I used). I tried 3.0.5 and the latest git repository too. The same bad behavior there.
>>>>>>>>
>>>>>>>
>>>>>>> Did you configure userspace with --enable-pshared?
>>>>>>>
>>>>>>
>>>>>> Yes. I invoked the "configure" script this way:
>>>>>>
>>>>>> ./configure --with-core=cobalt --enable-smp --enable-pshared
>>>>>
>>>>> OK.
>>>>>
>>>>>>
>>>>>> This is my configuration:
>>>>>>
>>>>>> /xeno-config --info
>>>>>> Xenomai version: Xenomai/cobalt v3.0.6 -- #50ef005 (2018-05-13 16:21:13 +0200)
>>>>>> Linux clickandmove-NUC 4.9.51xeno #1 SMP Wed May 23 05:14:47 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux
>>>>>> Kernel parameters: BOOT_IMAGE=/boot/vmlinuz-4.9.51xeno root=UUID=7e90a17b-1ea0-4b84-849f-7d621fe6d580 ro quiet splash vt.handoff=7
>>>>>> I-pipe release #5 detected
>>>>>> Cobalt core 3.0.6 detected
>>>>>> Compiler: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)
>>>>>> Build args: --with-core=cobalt --enable-smp --enable-pshared
>>>>>>
>>>>>> When I tried the git repository I cheated a bit. I could not find the configure script (neither some others) and all the makefile.in files were missing, so I copied these files from the xenomai-3.0.6.tar.bz2. I've never tried the git  repositore before, always used the bz2 file(s). In case of the 3.0.5 version I used the bz2 file for the tests.
>>>>>
>>>>> Just run scripts/bootstrap when using a git checkout.
>>>>
>>>> Do I need any parameters to the scripts/bootstrap script in this case or I should simply run it?
>>>>
>>>>>
>>>>> To ensure that we are truly hunting a Xenomai issue: Does your testcase
>>>>> work with plain Linux?
>>>>>
>>>>
>>>> Yes, it works fine under plain Linux. Sorry that I forgot to mention this...
>>>
>>> Confirmed.
>>>
>>> In fact, your test also exposes some cleanup issue: When terminating a
>>> process, Xenomai does not remove the semaphore, and you need to reboot
>>> to remove the object.
>>
>> Correction: This is not a wrong behavior, Linux does the same. The test
>> code just has no chance to clean up a preexisting sem because of the
>> other problem (EINVAL).
>>
>> Jan
>>
>>>
>>> Will look into these problems.
>>>
>>> Jan
>>>
>>
> I saw that you created some patches on this issue and modified the git repository. I cloned the latest one, rebuilt Xenomai and my test application but the original EINVAL, Invalid Argument error in case of the second instance of the test application still exists. In other words I do not see any change in the behavior.
> Should I rebuild the Linux kernel too?

Yes, the fix is targeting the kernel code.

Jan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://xenomai.org/pipermail/xenomai/attachments/20180526/64d80c89/attachment.sig>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Xenomai] Posix named semaphore used by two separate applications
  2018-05-26  5:09       ` Jan Kiszka
@ 2018-05-28 11:10         ` Paal Tamas
  0 siblings, 0 replies; 8+ messages in thread
From: Paal Tamas @ 2018-05-28 11:10 UTC (permalink / raw)
  To: xenomai



Jan Kiszka <jan.kiszka@web.de> írta:
>On 2018-05-25 11:18, Paal Tamas wrote:
>> 
>> 
>> Jan Kiszka <jan.kiszka@siemens.com> írta:
>>> On 2018-05-24 16:18, Jan Kiszka wrote:
>>>> Again, re-adding the list - please always use "reply to all".
>>>>
>>>> On 2018-05-24 13:56, Paal Tamas wrote:
>>>>>
>>>>>
>>>>> Jan Kiszka <jan.kiszka@siemens.com> írta:
>>>>>> [re-adding the list]
>>>>>>
>>>>>> On 2018-05-24 13:35, Paal Tamas wrote:
>>>>>>>
>>>>>>>
>>>>>>> Jan Kiszka <jan.kiszka@siemens.com> írta:
>>>>>>>> On 2018-05-24 10:50, Paal Tamas wrote:
>>>>>>>>> I would like to use the same named semaphore in two separate Xenomai binaries. I am using the Posix skin. It does not work as I am expecting it. 
>>>>>>>>> The first instance of my test application creates a named semaphore. It goes to sleep after that. The second instance of the same applications starts than. It realizes that the semaphore with the name already exists, so it opens it. The sem_open() returns a valid (like) pointer. After that all semaphore functions in this second application return EINVAL (22) (Invalid argument). Both the sem_wait() and the sem_close() function behave this way.
>>>>>>>>>
>>>>>>>>> The same procedure worked fine in 2.6.2.1 (the previous version I used). I tried 3.0.5 and the latest git repository too. The same bad behavior there.
>>>>>>>>>
>>>>>>>>
>>>>>>>> Did you configure userspace with --enable-pshared?
>>>>>>>>
>>>>>>>
>>>>>>> Yes. I invoked the "configure" script this way:
>>>>>>>
>>>>>>> ./configure --with-core=cobalt --enable-smp --enable-pshared
>>>>>>
>>>>>> OK.
>>>>>>
>>>>>>>
>>>>>>> This is my configuration:
>>>>>>>
>>>>>>> /xeno-config --info
>>>>>>> Xenomai version: Xenomai/cobalt v3.0.6 -- #50ef005 (2018-05-13 16:21:13 +0200)
>>>>>>> Linux clickandmove-NUC 4.9.51xeno #1 SMP Wed May 23 05:14:47 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux
>>>>>>> Kernel parameters: BOOT_IMAGE=/boot/vmlinuz-4.9.51xeno root=UUID=7e90a17b-1ea0-4b84-849f-7d621fe6d580 ro quiet splash vt.handoff=7
>>>>>>> I-pipe release #5 detected
>>>>>>> Cobalt core 3.0.6 detected
>>>>>>> Compiler: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)
>>>>>>> Build args: --with-core=cobalt --enable-smp --enable-pshared
>>>>>>>
>>>>>>> When I tried the git repository I cheated a bit. I could not find the configure script (neither some others) and all the makefile.in files were missing, so I copied these files from the xenomai-3.0.6.tar.bz2. I've never tried the git  repositore before, always used the bz2 file(s). In case of the 3.0.5 version I used the bz2 file for the tests.
>>>>>>
>>>>>> Just run scripts/bootstrap when using a git checkout.
>>>>>
>>>>> Do I need any parameters to the scripts/bootstrap script in this case or I should simply run it?
>>>>>
>>>>>>
>>>>>> To ensure that we are truly hunting a Xenomai issue: Does your testcase
>>>>>> work with plain Linux?
>>>>>>
>>>>>
>>>>> Yes, it works fine under plain Linux. Sorry that I forgot to mention this...
>>>>
>>>> Confirmed.
>>>>
>>>> In fact, your test also exposes some cleanup issue: When terminating a
>>>> process, Xenomai does not remove the semaphore, and you need to reboot
>>>> to remove the object.
>>>
>>> Correction: This is not a wrong behavior, Linux does the same. The test
>>> code just has no chance to clean up a preexisting sem because of the
>>> other problem (EINVAL).
>>>
>>> Jan
>>>
>>>>
>>>> Will look into these problems.
>>>>
>>>> Jan
>>>>
>>>
>> I saw that you created some patches on this issue and modified the git repository. I cloned the latest one, rebuilt Xenomai and my test application but the original EINVAL, Invalid Argument error in case of the second instance of the test application still exists. In other words I do not see any change in the behavior.
>> Should I rebuild the Linux kernel too?
>
>Yes, the fix is targeting the kernel code.
>
>Jan
>

After rebuilding the kernel the problem is disappeared. Now my test program works as expected.
Thank you very much!

Tamas



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Xenomai] Posix named semaphore used by two separate applications
       [not found] <freemail.20180524133540.48163.1@fmxmldata04.freemail.hu>
@ 2018-05-24 11:40 ` Jan Kiszka
  0 siblings, 0 replies; 8+ messages in thread
From: Jan Kiszka @ 2018-05-24 11:40 UTC (permalink / raw)
  To: Paal Tamas, Xenomai

[re-adding the list]

On 2018-05-24 13:35, Paal Tamas wrote:
> 
> 
> Jan Kiszka <jan.kiszka@siemens.com> írta:
>> On 2018-05-24 10:50, Paal Tamas wrote:
>>> I would like to use the same named semaphore in two separate Xenomai binaries. I am using the Posix skin. It does not work as I am expecting it. 
>>> The first instance of my test application creates a named semaphore. It goes to sleep after that. The second instance of the same applications starts than. It realizes that the semaphore with the name already exists, so it opens it. The sem_open() returns a valid (like) pointer. After that all semaphore functions in this second application return EINVAL (22) (Invalid argument). Both the sem_wait() and the sem_close() function behave this way.
>>>
>>> The same procedure worked fine in 2.6.2.1 (the previous version I used). I tried 3.0.5 and the latest git repository too. The same bad behavior there.
>>>
>>
>> Did you configure userspace with --enable-pshared?
>>
> 
> Yes. I invoked the "configure" script this way:
> 
> ./configure --with-core=cobalt --enable-smp --enable-pshared

OK.

> 
> This is my configuration:
> 
> /xeno-config --info
> Xenomai version: Xenomai/cobalt v3.0.6 -- #50ef005 (2018-05-13 16:21:13 +0200)
> Linux clickandmove-NUC 4.9.51xeno #1 SMP Wed May 23 05:14:47 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux
> Kernel parameters: BOOT_IMAGE=/boot/vmlinuz-4.9.51xeno root=UUID=7e90a17b-1ea0-4b84-849f-7d621fe6d580 ro quiet splash vt.handoff=7
> I-pipe release #5 detected
> Cobalt core 3.0.6 detected
> Compiler: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)
> Build args: --with-core=cobalt --enable-smp --enable-pshared
> 
> When I tried the git repository I cheated a bit. I could not find the configure script (neither some others) and all the makefile.in files were missing, so I copied these files from the xenomai-3.0.6.tar.bz2. I've never tried the git  repositore before, always used the bz2 file(s). In case of the 3.0.5 version I used the bz2 file for the tests.

Just run scripts/bootstrap when using a git checkout.

To ensure that we are truly hunting a Xenomai issue: Does your testcase
work with plain Linux?

Jan

-- 
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Xenomai] Posix named semaphore used by two separate applications
  2018-05-24  8:50 Paal Tamas
@ 2018-05-24 10:19 ` Jan Kiszka
  0 siblings, 0 replies; 8+ messages in thread
From: Jan Kiszka @ 2018-05-24 10:19 UTC (permalink / raw)
  To: Paal Tamas, xenomai

On 2018-05-24 10:50, Paal Tamas wrote:
> I would like to use the same named semaphore in two separate Xenomai binaries. I am using the Posix skin. It does not work as I am expecting it. 
> The first instance of my test application creates a named semaphore. It goes to sleep after that. The second instance of the same applications starts than. It realizes that the semaphore with the name already exists, so it opens it. The sem_open() returns a valid (like) pointer. After that all semaphore functions in this second application return EINVAL (22) (Invalid argument). Both the sem_wait() and the sem_close() function behave this way.
> 
> The same procedure worked fine in 2.6.2.1 (the previous version I used). I tried 3.0.5 and the latest git repository too. The same bad behavior there.
> 

Did you configure userspace with --enable-pshared?

Jan

-- 
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Xenomai] Posix named semaphore used by two separate applications
@ 2018-05-24  8:50 Paal Tamas
  2018-05-24 10:19 ` Jan Kiszka
  0 siblings, 1 reply; 8+ messages in thread
From: Paal Tamas @ 2018-05-24  8:50 UTC (permalink / raw)
  To: xenomai

I would like to use the same named semaphore in two separate Xenomai binaries. I am using the Posix skin. It does not work as I am expecting it. 
The first instance of my test application creates a named semaphore. It goes to sleep after that. The second instance of the same applications starts than. It realizes that the semaphore with the name already exists, so it opens it. The sem_open() returns a valid (like) pointer. After that all semaphore functions in this second application return EINVAL (22) (Invalid argument). Both the sem_wait() and the sem_close() function behave this way.

The same procedure worked fine in 2.6.2.1 (the previous version I used). I tried 3.0.5 and the latest git repository too. The same bad behavior there.


My testcode:

#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <semaphore.h>
#include <sys/time.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <time.h>
#include <sys/types.h>

#define SEMA_NAME "/testsema18"

void Sleep(unsigned int time)
{
struct timespec delay;  // structure for providing timeout
   delay.tv_sec = time / (1000*1000); // sec
   delay.tv_nsec = (time % (1000*1000)) * 1000;
   nanosleep(&delay, NULL);
}

int main(int argc, char* argv[])
{
sem_t *sema1=0;   
   if(argc<=1)
   {
      printf("Please supply a name for your process as an argument...\n");
      exit(1);
   }
   sema1=sem_open(SEMA_NAME, O_CREAT | O_EXCL,0777, 0);        
   if(sema1==SEM_FAILED)
   {
      if(errno==EEXIST)
      {
         printf("%s:sem_open(): semaphore already exists\n",argv[1]);
//         sema1=sem_open(SEMA_NAME,O_CREAT);  
         sema1=sem_open(SEMA_NAME,0);  
         if(sema1==SEM_FAILED)
         {
            printf("%s:sem_open(): sem_open() error:%d,%s\n",argv[1],errno,strerror(errno));
            exit(2);
         }
// try to acquire the semaphore
         struct timespec localTimeOut;
         struct timeval now;
         gettimeofday(&now, 0);
         if(sem_wait(sema1)!=0)
         {
            printf("%s:sem_wait() error:%d,%s\n",argv[1],errno,strerror(errno));
            if(sem_close(sema1)!=0) 
            {
               printf("%s:sem_close() error:%d,%s: exit(3)\n",argv[1],errno,strerror(errno));
               exit(3);
            }            
         }
         else
         {// access granted
            printf("%s:semaphore acquired successfully\n",argv[1]);
            if(sem_post(sema1)!=0)
            {
               printf("%s:sem_post() error:%d,%s\n",argv[1],errno,strerror(errno));
               if(sem_close(sema1)!=0) 
               {
                  printf("%s:sem_close() error:%d,%s: exit(4)\n",argv[1],errno,strerror(errno));
                  exit(4);
               }            
            }
            else printf("%s:semapore released successfully\n",argv[1]);
         }     
      }
      else
      {
         printf("%s:sem_open(): sem_open() error:%d,%s\n",argv[1],errno,strerror(errno));      
      }
   }
   else   
   {
      printf("%s:semapore created successfully\n",argv[1]);
      if(sem_post(sema1)!=0)
      {
         printf("%s:sem_post() error:%d,%s\n",argv[1],errno,strerror(errno));
         if(sem_close(sema1)!=0) 
         {
            printf("%s:sem_close() error:%d,%s: exit(6)\n",argv[1],errno,strerror(errno));
            exit(4);
         }            
      }
      else printf("%s:semapore released successfully\n",argv[1]);
   } 
   printf("%s:application goes to sleep\n",argv[1]);
   Sleep(3000000);
   if(sem_close(sema1)!=0) 
   {
      printf("%s:sem_close() error:%d,%s:exit(5)\n",argv[1],errno,strerror(errno));
      exit(5);
   }     
   else printf("%s:semaphore closed succesfully.%d\n",argv[1],errno);  
   if(sem_unlink(SEMA_NAME)!=0)
   {
      printf("%s:sem_unlink() error:%d,%s\n",argv[1],errno,strerror(errno));
   }
   else printf("%s:semaphore unlinked succesfully.%d\n",argv[1],errno);  
   printf("%s:application end.\n",argv[1]);
   return 0;   
}   



The makefile I use to compile it:

XENO_CONFIG := /usr/xenomai/bin/xeno-config
CFLAGS := $(shell $(XENO_CONFIG) --posix --cflags)
LDFLAGS := $(shell $(XENO_CONFIG) --posix --ldflags)
CC := $(shell $(XENO_CONFIG) --cc)

EXECUTABLE := mutextest

all: $(EXECUTABLE)

%: %.c
	$(CC) -o $@ $< $(CFLAGS) $(LDFLAGS)



The script file I use to start the applications:

#!/bin/bash
export LD_LIBRARY_PATH="/usr/xenomai/lib"
./mutextest testapp111 &
sleep 1
./mutextest testapp222 &
#end



The output of the applications:

clickandmove@clickandmove-NUC:~/candm/xeno$ sudo ./run.sh
testapp111:semapore created successfully
testapp111:semapore released successfully
testapp111:application goes to sleep
clickandmove@clickandmove-NUC:~/candm/xeno$ testapp222:sem_open(): semaphore already exists
testapp222:sem_wait() error:22,Invalid argument
testapp222:sem_close() error:22,Invalid argument: exit(3)
testapp111:semaphore closed succesfully.0
testapp111:semaphore unlinked succesfully.0
testapp111:application end.



My system info:

./xeno-config --info
Xenomai version: Xenomai/cobalt v3.0.6 -- #50ef005 (2018-05-13 16:21:13 +0200)
Linux clickandmove-NUC 4.9.51xeno #1 SMP Wed May 23 05:14:47 PDT 2018 x86_64 x86_64 x86_64 GNU/Linux
Kernel parameters: BOOT_IMAGE=/boot/vmlinuz-4.9.51xeno root=UUID=7e90a17b-1ea0-4b84-849f-7d621fe6d580 ro quiet splash vt.handoff=7
I-pipe release #5 detected
Cobalt core 3.0.6 detected
Compiler: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5) 
Build args: --with-core=cobalt --enable-smp --enable-pshared



Please help me. What am I doing wrong?

Thank you,
Tamas




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-05-28 11:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <freemail.20180524135633.61226.1@fmxmldata03.freemail.hu>
2018-05-24 14:18 ` [Xenomai] Posix named semaphore used by two separate applications Jan Kiszka
2018-05-24 14:20   ` Jan Kiszka
2018-05-25  9:18     ` Paal Tamas
2018-05-26  5:09       ` Jan Kiszka
2018-05-28 11:10         ` Paal Tamas
     [not found] <freemail.20180524133540.48163.1@fmxmldata04.freemail.hu>
2018-05-24 11:40 ` Jan Kiszka
2018-05-24  8:50 Paal Tamas
2018-05-24 10:19 ` Jan Kiszka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.