mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Fix supervised node inheritence of command-line script paths
They're now converting to absolute paths in the argument parsing phase such that if a supervised node switches working directory, it can still load the referenced script.
This commit is contained in:
parent
38cd56a3db
commit
8a145ee1a2
1 changed files with 52 additions and 1 deletions
53
src/main.cc
53
src/main.cc
|
@ -681,6 +681,57 @@ static zeek_options parse_cmdline(int argc, char** argv)
|
|||
rval.scripts_to_load.emplace_back(zargs[optind++]);
|
||||
}
|
||||
|
||||
auto canonify_script_path = [](std::string* path)
|
||||
{
|
||||
if ( path->empty() )
|
||||
return;
|
||||
|
||||
*path = normalize_path(*path);
|
||||
|
||||
if ( (*path)[0] == '/' || (*path)[0] == '~' )
|
||||
// Absolute path
|
||||
return;
|
||||
|
||||
if ( (*path)[0] != '.' )
|
||||
{
|
||||
// Look up file in ZEEKPATH
|
||||
auto res = find_script_file(*path, bro_path());
|
||||
|
||||
if ( res.empty() )
|
||||
{
|
||||
fprintf(stderr, "failed to locate script: %s\n", path->data());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
*path = res;
|
||||
|
||||
if ( (*path)[0] == '/' || (*path)[0] == '~' )
|
||||
// Now an absolute path
|
||||
return;
|
||||
}
|
||||
|
||||
// Need to translate relative path to absolute.
|
||||
char cwd[PATH_MAX];
|
||||
|
||||
if ( ! getcwd(cwd, sizeof(cwd)) )
|
||||
{
|
||||
fprintf(stderr, "failed to get current directory: %s\n",
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
*path = std::string(cwd) + "/" + *path;
|
||||
};
|
||||
|
||||
if ( rval.supervisor_mode )
|
||||
{
|
||||
// Translate any relative paths supplied to supervisor into absolute
|
||||
// paths for use by supervised nodes since they have the option to
|
||||
// operate out of a different working directory.
|
||||
for ( auto& s : rval.scripts_to_load )
|
||||
canonify_script_path(&s);
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
@ -900,7 +951,7 @@ static std::string get_exe_path(const std::string& invocation)
|
|||
if ( invocation.empty() )
|
||||
return "";
|
||||
|
||||
if ( invocation[0] == '/' )
|
||||
if ( invocation[0] == '/' || invocation[0] == '~' )
|
||||
// Absolute path
|
||||
return invocation;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue