Improved yarp run apis and tests.#3334
Conversation
Run.cpp file divided into seprate files: server and client. Improved `ps` funzionality to provide list of all running processes
|
Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would update the release notes by adding a file in |
There was a problem hiding this comment.
Code Review
This pull request refactors the yarp::run library by splitting the monolithic Run.cpp into separate RunClient.cpp and RunServer.cpp files. The public API has been updated to return bool instead of int for many operations, and several internal methods now correctly use const references for Bottle parameters. Additionally, the test suite was expanded to cover more process management scenarios. Feedback focuses on a potential data race with a shared random number generator, a risk of segmentation faults due to insufficient validation of network responses, and various code quality improvements including the removal of unused variables and redundant logic.
| static std::random_device rd; | ||
| static std::mt19937 gen(rd()); | ||
| static std::uniform_int_distribution<> dist(0, 99999); |
There was a problem hiding this comment.
| yarp::os::Bottle* b = response.get(i).asList(); | ||
|
|
||
| temp.pid = b->get(0).asList()->get(1).asInt32(); | ||
| temp.tag = b->get(1).asList()->get(1).asString(); | ||
| temp.status = b->get(2).asList()->get(1).asString(); | ||
| temp.command = b->get(3).asList()->get(1).asString(); | ||
| temp.env = b->get(4).asList()->get(1).asString(); |
There was a problem hiding this comment.
This code is highly fragile and prone to crashes. It assumes that response.get(i) is a list and that its elements are also lists with specific indices. If the server returns an unexpected format, asList() will return nullptr, leading to a null pointer dereference and a segmentation fault. You should validate the structure of the Bottle before accessing its elements.
|
|
||
| bool connected = yarp::os::Network::connect(port.getName(), config.find("on").asString()); | ||
| std::string tempportname = port.getName(); | ||
| bool bb = yarp::os::Network::isConnected(tempportname, target); |
| sprintf(buff, "%d", response.get(0).asInt32()); | ||
| keyv=std::string(buff); | ||
|
|
||
| return response.get(0).asInt32()>0?true:false; |
There was a problem hiding this comment.
| response=sendMsg(msg, node); | ||
| for (size_t i=0; i<response.size(); i++) | ||
| { | ||
| response.get(i).toString(); |
| #if defined(_WIN32) | ||
| int yarp::run::Run::server() | ||
| { | ||
| //yarp::os::Semaphore serializer(1); ///?????unused |
Run.cpp file divided into seprate files: server and client.
Improved
psfunzionality to provide list of all running processes