Skip to content

Commit 76d2938

Browse files
authored
introspection: remove any invalid ROS-name chars from hostname (moveit#465)
1 parent 6a01550 commit 76d2938

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

core/src/introspection.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
#include <sstream>
5050
#include <boost/bimap.hpp>
5151

52+
namespace ros {
53+
namespace names {
54+
bool isValidCharInName(char c); // unfortunately this is not declared in ros/names.h
55+
} // namespace names
56+
} // namespace ros
57+
5258
namespace moveit {
5359
namespace task_constructor {
5460

@@ -57,8 +63,10 @@ std::string getTaskId(const TaskPrivate* task) {
5763
std::ostringstream oss;
5864
char our_hostname[256] = { 0 };
5965
gethostname(our_hostname, sizeof(our_hostname) - 1);
60-
// Hostname could have `-` as a character but this is an invalid character in ROS so we replace it with `_`
61-
std::replace(std::begin(our_hostname), std::end(our_hostname), '-', '_');
66+
// Replace all invalid ROS-name chars with an underscore
67+
std::replace_if(
68+
our_hostname, our_hostname + strlen(our_hostname),
69+
[](const char ch) { return !ros::names::isValidCharInName(ch); }, '_');
6270
oss << our_hostname << "_" << getpid() << "_" << reinterpret_cast<std::size_t>(task);
6371
return oss.str();
6472
}

0 commit comments

Comments
 (0)