Commit dc53a38a authored by Tristan Matthews's avatar Tristan Matthews

* #31529: daemon: use strerr_r to print errno messages

parent 41524e46
......@@ -105,7 +105,8 @@ void History::ensurePath()
if (mkdir(userdata.data(), 0755) != 0) {
// If directory creation failed
if (errno != EEXIST) {
DEBUG("Cannot create directory: %s!: %s", userdata.c_str(), strerror(errno));
DEBUG("Cannot create directory: %s", userdata.c_str());
Logger::strErr();
return;
}
}
......
......@@ -85,4 +85,27 @@ bool getDebugMode()
{
return debugMode;
}
void strErr()
{
#ifdef __GLIBC__
ERROR("%m");
#else
char buf[1000];
const char *msg;
switch (strerror_r(error, buf, sizeof(buf))) {
case 0:
msg = buf;
break;
case ERANGE: /* should never happen */
msg = "unknown (too big to display)";
break;
default:
msg = "unknown (invalid error number)";
break;
}
ERROR("%s", msg);
#endif
}
}
......@@ -45,6 +45,7 @@ void log(const int, const char*, ...);
void setConsoleLog(bool);
void setDebugMode(bool);
bool getDebugMode();
void strErr();
};
#define LOG_FORMAT(M, ...) "%s:%d:0x%x: " M, FILE_NAME, __LINE__, (unsigned long) pthread_self() & 0xffff, ##__VA_ARGS__
......
......@@ -79,8 +79,8 @@ bool SHMSink::start()
if (not shm_name_.empty()) {
fd_ = shm_open(shm_name_.c_str(), flags, perms);
if (fd_ < 0) {
ERROR("could not open shm area \"%s\", shm_open failed:%s", shm_name_.c_str(), strerror(errno));
perror(strerror(errno));
ERROR("could not open shm area \"%s\"", shm_name_.c_str());
Logger::strErr();
return false;
}
} else {
......@@ -90,7 +90,7 @@ bool SHMSink::start()
shm_name_ = name.str();
fd_ = shm_open(shm_name_.c_str(), flags, perms);
if (fd_ < 0 and errno != EEXIST) {
ERROR("%s", strerror(errno));
Logger::strErr();
return false;
}
}
......@@ -103,7 +103,7 @@ bool SHMSink::start()
if (ftruncate(fd_, shm_area_len_)) {
ERROR("Could not make shm area large enough for header");
perror(strerror(errno));
Logger::strErr();
return false;
}
......@@ -128,8 +128,9 @@ bool SHMSink::start()
bool SHMSink::stop()
{
if (fd_ >= 0)
close(fd_);
if (fd_ >= 0 and close(fd_) == -1)
Logger::strErr();
fd_ = -1;
if (not opened_name_.empty()) {
......@@ -154,13 +155,13 @@ bool SHMSink::resize_area(size_t desired_length)
if (munmap(shm_area_, shm_area_len_)) {
ERROR("Could not unmap shared area");
perror(strerror(errno));
Logger::strErr();
return false;
}
if (ftruncate(fd_, desired_length)) {
ERROR("Could not resize shared area");
perror(strerror(errno));
Logger::strErr();
return false;
}
......
......@@ -116,7 +116,8 @@ int udp_socket_create(sockaddr_storage *addr, socklen_t *addr_len,
// bind socket so that we send from and receive
// on local port
if (bind(udp_fd, reinterpret_cast<sockaddr*>(addr), *addr_len) < 0) {
ERROR("Bind failed: %s", strerror(errno));
ERROR("Bind failed");
Logger::strErr();
close(udp_fd);
udp_fd = -1;
}
......@@ -160,9 +161,9 @@ void SocketPair::interrupt()
void SocketPair::closeSockets()
{
if (rtcpHandle_ > 0 and close(rtcpHandle_))
ERROR("%s", strerror(errno));
Logger::strErr();
if (rtpHandle_ > 0 and close(rtpHandle_))
ERROR("%s", strerror(errno));
Logger::strErr();
}
void SocketPair::openSockets(const char *uri, int local_rtp_port)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment