Skip to content

Commit

Permalink
cleanup: pullrequest review
Browse files Browse the repository at this point in the history
- removed unneccessary includes
- refactored some code
  • Loading branch information
franku committed Jul 4, 2019
1 parent 2f5c11e commit 45f654b
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 48 deletions.
12 changes: 1 addition & 11 deletions core/src/console/connect_to_director.cc
Expand Up @@ -20,7 +20,6 @@
*/

#include "include/bareos.h"
#include "include/make_unique.h"
#include "console/console_conf.h"
#include "console/console_globals.h"
#include "console/console_output.h"
Expand All @@ -43,27 +42,18 @@ BareosSocket* ConnectToDirector(JobControlRecord& jcr,
delete UA_sock;
return nullptr;
}

jcr.dir_bsock = UA_sock;

const char* name;
s_password* password = NULL;

TlsResource* local_tls_resource;
BareosResource* own_resource;
if (console_resource) {
own_resource = console_resource;
name = console_resource->resource_name_;
ASSERT(console_resource->password.encoding == p_encoding_md5);
password = &console_resource->password;
local_tls_resource = console_resource;
} else { /* default console */
static ConsoleResource consoleresource_for_bsock_debugging;
consoleresource_for_bsock_debugging.resource_name_ =
const_cast<char*>("*UserAgent*");
consoleresource_for_bsock_debugging.rcode_ = R_CONSOLE;
consoleresource_for_bsock_debugging.rcode_str_ = "R_CONSOLE";
own_resource = &consoleresource_for_bsock_debugging;
name = "*UserAgent*";
ASSERT(director_resource->password_.encoding == p_encoding_md5);
password = &director_resource->password_;
Expand Down Expand Up @@ -96,6 +86,6 @@ BareosSocket* ConnectToDirector(JobControlRecord& jcr,
return nullptr;
}
return UA_sock;
} // namespace console
}

} /* namespace console */
1 change: 0 additions & 1 deletion core/src/dird/dird.cc
Expand Up @@ -195,7 +195,6 @@ static void usage()
" -f run in foreground (for debugging)\n"
" -g <group> run as group <group>\n"
" -m print kaboom output (for debugging)\n"
// " -n <file> switch network debugging on\n"
" -r <job> run <job> now\n"
" -s no signals (for debugging)\n"
" -t test - read configuration and exit\n"
Expand Down
10 changes: 0 additions & 10 deletions core/src/dird/dird_conf.cc
Expand Up @@ -3711,16 +3711,6 @@ static void ConfigReadyCallback(ConfigurationParser& my_config)
{
CreateAndAddUserAgentConsoleResource(my_config);

std::map<int, std::string> map{
{R_DIRECTOR, "R_DIRECTOR"}, {R_CLIENT, "R_CLIENT"},
{R_JOBDEFS, "R_JOBDEFS"}, {R_JOB, "R_JOB"},
{R_STORAGE, "R_STORAGE"}, {R_CATALOG, "R_CATALOG"},
{R_SCHEDULE, "R_SCHEDULE"}, {R_FILESET, "R_FILESET"},
{R_POOL, "R_POOL"}, {R_MSGS, "R_MSGS"},
{R_COUNTER, "R_COUNTER"}, {R_PROFILE, "R_PROFILE"},
{R_CONSOLE, "R_CONSOLE"}, {R_DEVICE, "R_DEVICE"}};
my_config.InitializeQualifiedResourceNameTypeConverter(map);

ResetAllClientConnectionHandshakeModes(my_config);
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/lib/backtrace.cc
Expand Up @@ -59,21 +59,21 @@ std::vector<BacktraceInfo> Backtrace(int skip, int amount)
Dl_info info;
if (dladdr(callstack[i], &info)) {
int status;
char* demangled = nullptr;
demangled = abi::__cxa_demangle(info.dli_sname, nullptr, 0, &status);
char* demangled =
abi::__cxa_demangle(info.dli_sname, nullptr, 0, &status);
const char* name;
if (status == 0) {
name = demangled ? demangled : "(no demangeled name)";
} else {
name = info.dli_sname ? info.dli_sname : "(no dli_sname)";
}
trace_buf.emplace_back(i, name);
free(demangled);
if (demangled) { free(demangled); }
} else {
trace_buf.emplace_back(i, "unknown");
}
}
free(symbols);
if (symbols) { free(symbols); }
if (nFrames == nMaxFrames) {
trace_buf.emplace_back(nMaxFrames + 1, "[truncated]");
}
Expand Down
25 changes: 11 additions & 14 deletions core/src/lib/bnet_network_dump_private.cc
Expand Up @@ -111,7 +111,7 @@ std::string BnetDumpPrivate::CreateFormatStringForNetworkMessage(

bool BnetDumpPrivate::IsExcludedRcode(const BStringList& l) const
{
if (l.size() > 1) {
if (l.size() > 0) {
const std::string& probe = l[0];
if (exclude_rcodes_.find(probe) != exclude_rcodes_.end()) { return true; }
}
Expand All @@ -123,10 +123,7 @@ bool BnetDumpPrivate::SuppressMessageIfRcodeIsInExcludeList() const
BStringList own_name(own_qualified_name_, "::");
BStringList destination_name(destination_qualified_name_, "::");

if (IsExcludedRcode(own_name) || IsExcludedRcode(destination_name)) {
return true;
}
return false;
return IsExcludedRcode(own_name) || IsExcludedRcode(destination_name);
}

void BnetDumpPrivate::CreateAndWriteMessageToBuffer(const char* ptr, int nbytes)
Expand Down Expand Up @@ -169,25 +166,25 @@ void BnetDumpPrivate::DumpToFile(const char* ptr, int nbytes)
{
if (SuppressMessageIfRcodeIsInExcludeList()) { return; }

if (state == State::kRunNormal) {
if (state_ == State::kRunNormal) {
CreateAndWriteMessageToBuffer(ptr, nbytes);
CreateAndWriteStacktraceToBuffer();
output_file_ << output_buffer_;
output_file_.flush();

} else if (state == State::kWaitForDestinationName) {
} else if (state_ == State::kWaitForDestinationName) {
return;
}
}

void BnetDumpPrivate::SaveAndSendMessageIfNoDestinationDefined(const char* ptr,
int nbytes)
{
if (state != State::kWaitForDestinationName) { return; }
if (state_ != State::kWaitForDestinationName) { return; }

if (destination_qualified_name_.empty()) {
std::size_t amount = nbytes;
amount = amount > max_data_dump_bytes_ ? max_data_dump_bytes_ : amount;
amount = std::min(amount, max_data_dump_bytes_);

std::vector<char> temp_data;
std::copy(ptr, ptr + amount, std::back_inserter(temp_data));
Expand All @@ -199,10 +196,10 @@ void BnetDumpPrivate::SaveAndSendMessageIfNoDestinationDefined(const char* ptr,
}

} else { // !empty() -> send all buffered messages
state = State::kRunNormal;
std::vector<std::vector<char>> temp =
std::move(temporary_buffer_for_initial_messages_);
for (const std::vector<char>& v : temp) { DumpToFile(v.data(), v.size()); }

state_ = State::kRunNormal;
for (auto& v : temporary_buffer_for_initial_messages_) {
DumpToFile(v.data(), v.size());
}
temporary_buffer_for_initial_messages_.clear();
} // destination_qualified_name_.empty()
}
2 changes: 1 addition & 1 deletion core/src/lib/bnet_network_dump_private.h
Expand Up @@ -74,7 +74,7 @@ class BnetDumpPrivate {
kWaitForDestinationName,
kRunNormal
};
State state = State::kWaitForDestinationName;
State state_ = State::kWaitForDestinationName;
};

#endif // BAREOS_LIB_BNET_NETWORK_DUMP_PRIVATE_H_
2 changes: 1 addition & 1 deletion core/src/lib/bsock_tcp.cc
Expand Up @@ -1053,7 +1053,7 @@ int32_t BareosSocketTCP::write_nbytes(char* ptr, int32_t nbytes)
return nbytes;
}

if (bnet_dump_) { bnet_dump_->DumpMessageAndStacktraceToFile(ptr, nbytes); }
if (IsBnetDumpEnabled()) { bnet_dump_->DumpMessageAndStacktraceToFile(ptr, nbytes); }

#ifdef HAVE_TLS
if (tls_conn) { return (tls_conn->TlsBsockWriten(this, ptr, nbytes)); }
Expand Down
4 changes: 0 additions & 4 deletions core/src/lib/util.cc
Expand Up @@ -27,15 +27,11 @@

#include "include/bareos.h"
#include "include/jcr.h"
#include "include/make_unique.h"
#include "lib/bsock.h"
#include "lib/edit.h"
#include "lib/ascii_control_characters.h"
#include "lib/bstringlist.h"
#include "lib/qualified_resource_name_type_converter.h"
#include "include/version_numbers.h"
#include "lib/parse_conf.h"
#include "lib/qualified_resource_name_type_converter.h"

#include <algorithm>

Expand Down
2 changes: 0 additions & 2 deletions core/src/stored/socket_server.cc
Expand Up @@ -37,9 +37,7 @@
#include "stored/sd_cmds.h"
#include "lib/bnet_server_tcp.h"
#include "lib/bsock.h"
#include "lib/parse_conf.h"
#include "lib/try_tls_handshake_as_a_server.h"
#include "lib/util.h"

namespace storagedaemon {

Expand Down

0 comments on commit 45f654b

Please sign in to comment.