mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 17:48:21 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/supervisor'
* origin/topic/jsiwek/supervisor: (44 commits) Add note that Supervisor script APIs are unstable until 4.0 Move command-line arg parsing functions to Options.{h,cc} Add btests for supervisor stem/leaf process revival Move supervisor control events into SupervisorControl namespace Fix supervisor "destroy" call on nodes not currently alive Move supervisor source files into supervisor/ Address supervisor code re-factoring feedback from Robin Convert supervisor internals to rapidjson Add Supervisor documentation Add supervisor btests Improve logging of supervised node errors Fix supervised node inheritence of command-line script paths Improve normalize_path() util function Use a timer to check for death of supervised node's parent Improve supervisor checks for parent process termination Improve handling of premature supervisor stem exit Improve supervisor signal handler safety Remove unused supervisor config options Cleanup minor Supervisor TODOs Improve supervisor debug logging ...
This commit is contained in:
commit
6bcd583836
79 changed files with 4239 additions and 548 deletions
98
src/util.cc
98
src/util.cc
|
@ -1231,7 +1231,7 @@ string bro_prefixes()
|
|||
{
|
||||
string rval;
|
||||
|
||||
for ( const auto& prefix : prefixes )
|
||||
for ( const auto& prefix : zeek_script_prefixes )
|
||||
{
|
||||
if ( ! rval.empty() )
|
||||
rval.append(":");
|
||||
|
@ -1459,17 +1459,22 @@ TEST_CASE("util tokenize_string")
|
|||
}
|
||||
|
||||
vector<string>* tokenize_string(string input, const string& delim,
|
||||
vector<string>* rval)
|
||||
vector<string>* rval, int limit)
|
||||
{
|
||||
if ( ! rval )
|
||||
rval = new vector<string>();
|
||||
|
||||
size_t n;
|
||||
auto found = 0;
|
||||
|
||||
while ( (n = input.find(delim)) != string::npos )
|
||||
{
|
||||
++found;
|
||||
rval->push_back(input.substr(0, n));
|
||||
input.erase(0, n + 1);
|
||||
|
||||
if ( limit && found == limit )
|
||||
break;
|
||||
}
|
||||
|
||||
rval->push_back(input);
|
||||
|
@ -1482,6 +1487,25 @@ TEST_CASE("util normalize_path")
|
|||
CHECK(normalize_path("/1/./2/3") == "/1/2/3");
|
||||
CHECK(normalize_path("/1/2/../3") == "/1/3");
|
||||
CHECK(normalize_path("1/2/3/") == "1/2/3");
|
||||
CHECK(normalize_path("1/2//3///") == "1/2/3");
|
||||
CHECK(normalize_path("~/zeek/testing") == "~/zeek/testing");
|
||||
CHECK(normalize_path("~jon/zeek/testing") == "~jon/zeek/testing");
|
||||
CHECK(normalize_path("~jon/./zeek/testing") == "~jon/zeek/testing");
|
||||
CHECK(normalize_path("~/zeek/testing/../././.") == "~/zeek");
|
||||
CHECK(normalize_path("./zeek") == "./zeek");
|
||||
CHECK(normalize_path("../zeek") == "../zeek");
|
||||
CHECK(normalize_path("../zeek/testing/..") == "../zeek");
|
||||
CHECK(normalize_path("./zeek/..") == ".");
|
||||
CHECK(normalize_path("./zeek/../..") == "..");
|
||||
CHECK(normalize_path("./zeek/../../..") == "../..");
|
||||
CHECK(normalize_path("./..") == "..");
|
||||
CHECK(normalize_path("../..") == "../..");
|
||||
CHECK(normalize_path("/..") == "/..");
|
||||
CHECK(normalize_path("~/..") == "~/..");
|
||||
CHECK(normalize_path("/../..") == "/../..");
|
||||
CHECK(normalize_path("~/../..") == "~/../..");
|
||||
CHECK(normalize_path("zeek/..") == "");
|
||||
CHECK(normalize_path("zeek/../..") == "..");
|
||||
}
|
||||
|
||||
string normalize_path(const string& path)
|
||||
|
@ -1503,10 +1527,30 @@ string normalize_path(const string& path)
|
|||
|
||||
if ( *it == "." && it != components.begin() )
|
||||
final_components.pop_back();
|
||||
else if ( *it == ".." && final_components[0] != ".." )
|
||||
else if ( *it == ".." )
|
||||
{
|
||||
final_components.pop_back();
|
||||
final_components.pop_back();
|
||||
auto cur_idx = final_components.size() - 1;
|
||||
|
||||
if ( cur_idx != 0 )
|
||||
{
|
||||
auto last_idx = cur_idx - 1;
|
||||
auto& last_component = final_components[last_idx];
|
||||
|
||||
if ( last_component == "/" || last_component == "~" ||
|
||||
last_component == ".." )
|
||||
continue;
|
||||
|
||||
if ( last_component == "." )
|
||||
{
|
||||
last_component = "..";
|
||||
final_components.pop_back();
|
||||
}
|
||||
else
|
||||
{
|
||||
final_components.pop_back();
|
||||
final_components.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1764,7 +1808,7 @@ void terminate_processing()
|
|||
}
|
||||
|
||||
extern const char* proc_status_file;
|
||||
void _set_processing_status(const char* status)
|
||||
void set_processing_status(const char* status, const char* reason)
|
||||
{
|
||||
if ( ! proc_status_file )
|
||||
return;
|
||||
|
@ -1791,20 +1835,27 @@ void _set_processing_status(const char* status)
|
|||
return;
|
||||
}
|
||||
|
||||
int len = strlen(status);
|
||||
while ( len )
|
||||
auto write_str = [](int fd, const char* s)
|
||||
{
|
||||
int n = write(fd, status, len);
|
||||
int len = strlen(s);
|
||||
while ( len )
|
||||
{
|
||||
int n = write(fd, s, len);
|
||||
|
||||
if ( n < 0 && errno != EINTR && errno != EAGAIN )
|
||||
// Ignore errors, as they're too difficult to
|
||||
// safely report here.
|
||||
break;
|
||||
if ( n < 0 && errno != EINTR && errno != EAGAIN )
|
||||
// Ignore errors, as they're too difficult to
|
||||
// safely report here.
|
||||
break;
|
||||
|
||||
status += n;
|
||||
len -= n;
|
||||
}
|
||||
s += n;
|
||||
len -= n;
|
||||
}
|
||||
};
|
||||
|
||||
write_str(fd, status);
|
||||
write_str(fd, " [");
|
||||
write_str(fd, reason);
|
||||
write_str(fd, "]\n");
|
||||
safe_close(fd);
|
||||
|
||||
errno = old_errno;
|
||||
|
@ -2314,3 +2365,18 @@ string json_escape_utf8(const string& val)
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
void zeek::set_thread_name(const char* name, pthread_t tid)
|
||||
{
|
||||
#ifdef HAVE_LINUX
|
||||
prctl(PR_SET_NAME, name, 0, 0, 0);
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
pthread_setname_np(name);
|
||||
#endif
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
pthread_set_name_np(tid, name);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue