Skip to content

Commit

Permalink
Convert relative smartctl-nc path to absolute before running it.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashaduri committed Jan 15, 2022
1 parent 0183626 commit 235fba8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/applib/async_command_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ bool AsyncCommandExecutor::execute()
std::vector<std::string> envp = Glib::ArrayHandler<std::string>::array_to_vector(child_env.release(),
Glib::OWNERSHIP_DEEP);

// Set the current directory to application directory so that the default executable (which is simply "smartctl-nc")
// can be found even if CWD is something different.
// Set the current directory to application directory so CWD does not interfere with finding binaries.
auto current_path = hz::fs::current_path();
bool path_changed = false;
if (auto app_dir = hz::fs_get_application_dir(); !app_dir.empty()) {
Expand Down
25 changes: 17 additions & 8 deletions src/applib/smartctl_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ License: GNU General Public License v3.0 only
#include "hz/win32_tools.h"
#include "rconfig/rconfig.h"
#include "app_pcrecpp.h"

#include "hz/fs.h"



Expand All @@ -24,16 +24,17 @@ hz::fs::path get_smartctl_binary()
auto smartctl_binary = hz::fs::u8path(rconfig::get_data<std::string>("system/smartctl_binary"));

#ifdef _WIN32
// look in smartmontools installation directory.
// Look in smartmontools installation directory.
hz::fs::path system_binary;
do {
bool use_smt = rconfig::get_data<bool>("system/win32_search_smartctl_in_smartmontools");
if (!use_smt)
break;

std::string smt_regpath = rconfig::get_data<std::string>("system/win32_smartmontools_regpath");
std::string smt_regpath_wow = rconfig::get_data<std::string>("system/win32_smartmontools_regpath_wow"); // same as above, but with WOW6432Node
std::string smt_regkey = rconfig::get_data<std::string>("system/win32_smartmontools_regkey");
std::string smt_smartctl = rconfig::get_data<std::string>("system/win32_smartmontools_smartctl_binary");
auto smt_regpath = rconfig::get_data<std::string>("system/win32_smartmontools_regpath");
auto smt_regpath_wow = rconfig::get_data<std::string>("system/win32_smartmontools_regpath_wow"); // same as above, but with WOW6432Node
auto smt_regkey = rconfig::get_data<std::string>("system/win32_smartmontools_regkey");
auto smt_smartctl = rconfig::get_data<std::string>("system/win32_smartmontools_smartctl_binary");

if ((smt_regpath.empty() && smt_regpath_wow.empty()) || smt_regkey.empty() || smt_smartctl.empty())
break;
Expand All @@ -57,10 +58,18 @@ hz::fs::path get_smartctl_binary()
if (!hz::fs::exists(p) || !hz::fs::is_regular_file(p))
break;

smartctl_binary = p;

system_binary = p;
} while (false);

if (!system_binary.empty()) {
smartctl_binary = system_binary;

} else if (smartctl_binary.is_relative()) {
// If smartctl path is relative, and it's Windows, and the package seems to contain smartctl, use our own binary.
if (auto app_dir = hz::fs_get_application_dir(); !app_dir.empty() && hz::fs::exists(app_dir / smartctl_binary)) {
smartctl_binary = app_dir / smartctl_binary;
}
}
#endif

return smartctl_binary;
Expand Down

0 comments on commit 235fba8

Please sign in to comment.