]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[master] Finished merge of trac3841 (use remove() vs unlink()) at the exception of...
authorFrancis Dupont <fdupont@isc.org>
Wed, 24 Jun 2015 08:06:52 +0000 (10:06 +0200)
committerFrancis Dupont <fdupont@isc.org>
Wed, 24 Jun 2015 08:06:52 +0000 (10:06 +0200)
1  2 
src/bin/d2/tests/d_test_stubs.h
src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/kea_controller_unittest.cc
src/bin/dhcp6/tests/config_parser_unittest.cc
src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
src/bin/dhcp6/tests/kea_controller_unittest.cc
src/lib/dhcp/tests/iface_mgr_unittest.cc

Simple merge
index 29efa3735343d94aa97d4043ca98546a52d21ea0,8389cdfe866475fa0c70619135e3a6d5075eb6ab..8c56930d9552d7fdd7bbb24e659331999bd04a79
@@@ -69,74 -68,9 +69,74 @@@ public
          HooksManager::unloadLibraries();
  
          // Get rid of any marker files.
-         static_cast<void>(unlink(LOAD_MARKER_FILE));
-         static_cast<void>(unlink(UNLOAD_MARKER_FILE));
+         static_cast<void>(remove(LOAD_MARKER_FILE));
+         static_cast<void>(remove(UNLOAD_MARKER_FILE));
      }
 +
 +    /// @brief sends commands over specified UNIX socket
 +    ///
 +    /// @param command command to be sent (should be valid JSON)
 +    /// @param response response received (expected to be a valid JSON)
 +    /// @param socket_path UNIX socket path
 +    ///
 +    /// @return true if send/response exchange was successful, false otherwise
 +    bool sendCommandUnixSocket(const std::string& command,
 +                               std::string& response,
 +                               const std::string& socket_path) {
 +
 +        // Create UNIX socket
 +        int socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
 +        if (socket_fd < 0) {
 +            ADD_FAILURE() << "Failed to open unix stream socket.";
 +            return (false);
 +        }
 +
 +        // Prepare socket address
 +        struct sockaddr_un srv_addr;
 +        memset(&srv_addr, 0, sizeof(struct sockaddr_un));
 +        srv_addr.sun_family = AF_UNIX;
 +        strncpy(srv_addr.sun_path, socket_path.c_str(), sizeof(srv_addr.sun_path));
 +        socklen_t len = sizeof(srv_addr);
 +
 +        // Connect to the specified UNIX socket
 +        int status = connect(socket_fd, (struct sockaddr*)&srv_addr, len);
 +        if (status == -1) {
 +            ADD_FAILURE() << "Failed to connect unix socket: fd=" << socket_fd
 +                          << ", path=" << socket_path;
 +            close(socket_fd);
 +            return (false);
 +        }
 +
 +
 +        // Send command
 +        cout << "Sending command: " << command << endl;
 +        int bytes_sent = send(socket_fd, command.c_str(), command.length(), 0);
 +        if (bytes_sent < command.length()) {
 +            ADD_FAILURE() << "Failed to send " << command.length()
 +                      << " bytes, send() returned " << bytes_sent;
 +            close(socket_fd);
 +            return (false);
 +        }
 +
 +        // Receive response
 +        /// @todo: this may block if server fails to respond. Some sort of
 +        /// of a timer is needed.
 +        char buf[65536];
 +        memset(buf, 0, sizeof(buf));
 +        int bytes_rcvd = recv(socket_fd, buf, sizeof(buf), 0);
 +        if (bytes_rcvd < 0) {
 +            ADD_FAILURE() << "Failed to receive a response. recv() returned "
 +                      << bytes_rcvd;
 +            close(socket_fd);
 +            return (false);
 +        }
 +
 +        // Convert the response to a string, close the socket and return
 +        response = string(buf, bytes_rcvd);
 +        cout << "Received response: " << response << endl;
 +        close(socket_fd);
 +        return (true);
 +    }
  };
  
  TEST_F(CtrlDhcpv4SrvTest, commands) {