@@ -56,12 +56,12 @@ ipc::Socket::Socket(const std::chrono::duration<int>& timeout, const std::string
5656 std::string dest_path = Configuration::get_instance ().hapd_sockdir + " /" + sockname;
5757 std::string local_path = " /var/run/wimoved." + random_name ();
5858 if (unlink (local_path.c_str ()) == 0 ) {
59- WMLOG (DEBUG) << " Successfully unlinked socket" << local_path;
59+ WMLOG (DEBUG) << " Successfully unlinked socket local_path= " << local_path;
6060 }
6161
6262 sock_fd = socket (AF_UNIX, SOCK_DGRAM, 0 );
6363 if (sock_fd == -1 ) {
64- throw std::runtime_error (std::string (" could not create socket: " ) + std::strerror (errno));
64+ throw std::runtime_error (std::string (" Could not create socket error= " ) + std::strerror (errno));
6565 }
6666 auto timeout_usec = std::chrono::duration_cast<std::chrono::microseconds>(timeout);
6767 struct timeval tv {};
@@ -74,29 +74,31 @@ ipc::Socket::Socket(const std::chrono::duration<int>& timeout, const std::string
7474 local.sun_path [sizeof (local.sun_path ) - 1 ] = ' \0 ' ;
7575 if (bind (sock_fd, reinterpret_cast <struct sockaddr *>(&local), sizeof (local)) == -1 ) {
7676 close (sock_fd);
77- throw std::runtime_error (" could not bind to socket " + dest_path + " : " + std::strerror (errno));
77+ throw std::runtime_error (std::string (" Could not bind to socket error=" ) + std::strerror (errno) +
78+ std::string (" dest_path=" ) + dest_path);
7879 }
7980
8081 std::array<char , GETGRNAM_BUFFER_SIZE> buf{};
8182 struct group grp {};
8283 struct group * grp_result = nullptr ;
8384 getgrnam_r (Configuration::get_instance ().hapd_group .c_str (), &grp, buf.data (), buf.size (), &grp_result);
8485 if (grp_result == nullptr ) {
85- throw std::runtime_error (std::string (" getgrnam failed: " ) + std::strerror (errno));
86+ throw std::runtime_error (std::string (" Failed getgrnam_r() error= " ) + std::strerror (errno));
8687 }
8788 if (chown (local_path.c_str (), -1 , grp_result->gr_gid ) == -1 ) {
88- throw std::runtime_error (std::string (" could not set socket group: " ) + std::strerror (errno));
89+ throw std::runtime_error (std::string (" Could not set socket group error= " ) + std::strerror (errno));
8990 }
9091 if (chmod (local_path.c_str (), LOCAL_SOCKET_PERMISSIONS) == -1 ) {
91- throw std::runtime_error (std::string (" could not set socket permissions: " ) + std::strerror (errno));
92+ throw std::runtime_error (std::string (" Could not set socket permissions error= " ) + std::strerror (errno));
9293 }
9394
9495 dest.sun_family = AF_UNIX;
9596 strncpy (dest.sun_path , dest_path.c_str (), sizeof (dest.sun_path ));
9697 dest.sun_path [sizeof (dest.sun_path ) - 1 ] = ' \0 ' ;
9798 if (connect (sock_fd, reinterpret_cast <struct sockaddr *>(&dest), sizeof (dest)) == -1 ) {
9899 close (sock_fd);
99- throw std::runtime_error (" could not connect to socket at " + dest_path + " : " + std::strerror (errno));
100+ throw std::runtime_error (std::string (" Could not connect to socket error=" ) + std::strerror (errno) +
101+ std::string (" dest_path=" ) + dest_path);
100102 }
101103}
102104
@@ -105,10 +107,10 @@ ipc::Socket::~Socket() {
105107 return ;
106108 }
107109 if (close (sock_fd) == -1 ) {
108- WMLOG (ERROR) << " Could not close socket: " << std::strerror (errno) << " \n " ;
110+ WMLOG (ERROR) << " Could not close socket error= " << std::strerror (errno) << " \n " ;
109111 }
110112 if (unlink (local.sun_path ) != 0 ) {
111- WMLOG (ERROR) << " Could not unlink socket: " << std::strerror (errno) << " \n " ;
113+ WMLOG (ERROR) << " Could not unlink socket error= " << std::strerror (errno) << " \n " ;
112114 }
113115}
114116
@@ -118,7 +120,7 @@ void ipc::Socket::send_command(const std::vector<std::string>& args) {
118120
119121 ssize_t err = send (sock_fd, command.c_str (), command.size (), 0 );
120122 if (err < 0 ) {
121- throw std::runtime_error (std::string (" could not send_command to socket: " ) + std::strerror (errno));
123+ throw std::runtime_error (std::string (" Could not send to socket error= " ) + std::strerror (errno));
122124 }
123125}
124126
@@ -136,10 +138,10 @@ std::string ipc::Socket::receive() {
136138 return buf.substr (0 , len);
137139 }
138140 if (errno == EAGAIN) {
139- throw TimeoutException (" timeout in recv() from hostapd " );
141+ throw TimeoutException (" Timeout from hostapd recv()" );
140142 }
141143 if (errno != EINTR) {
142- throw std::runtime_error (std::string (" could not recv from socket: " ) + std::strerror (errno));
144+ throw std::runtime_error (std::string (" Could not receive from socket error= " ) + std::strerror (errno));
143145 }
144146 }
145147}
0 commit comments