yarp icon indicating copy to clipboard operation
yarp copied to clipboard

yarp wait return non zero code when the port requested is ready

Open Nicogene opened this issue 4 years ago • 0 comments
trafficstars

Describe the bug The yarp wait commands return 1 when the port is available and for bash scripts, this is in interpreted as an error. This gives problems for example when used with &&.

This is due to the fact that the return of the command is int see: https://github.com/robotology/yarp/blob/9b52a71e176e23ebe42956cf5b23d8ae40b255f0/src/libYARP_companion/src/yarp/companion/impl/Companion.cmdWait.cpp#L17-L27

and the function waitPort returns a bool, see https://github.com/robotology/yarp/blob/37075613365b04ddc6c9804653282d2d5c1b26f6/src/libYARP_os/src/yarp/os/Network.cpp#L828-L847

And the implicit conversion bool to int lead to have:

[..] true which expands to the integer constant 1, false which expands to the integer constant 0,[..]

I am afraid that this problem can be also in other companion's commands

To Reproduce

$ yarp wait /foo && yarp wait /bar
[INFO] |yarp.os.Network| Waiting for /foo...
[INFO] |yarp.os.Network| Waiting for /foo...
[INFO] |yarp.os.Network| Waiting for /foo...
[INFO] |yarp.os.Network| Waiting for /foo...

If in another terminal you type yarp write /foo, the yarp wait /bar will never execute.

Expected behavior This should return 0 on success, 1 on failure.

Screenshots If applicable, add screenshots to help explain your problem.

Configuration (please complete the following information):

  • OS: WSL2, Ubuntu 20.04.2
  • yarp version: 3.4.3+38-20210330.6+gitf7f000f39
  • compiler: clang

Additional context Add any other context about the problem here.

Nicogene avatar Apr 08 '21 09:04 Nicogene