osquery-1/osquery/killswitch/killswitch_refreshable_plugin.cpp
Jesse Kornblum c7355b19aa Update osquery licensing wording (#5452)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5452

As suggested in another diff, this diff updates the language we use to describe the osquery licensing terms. We are changing all instances of

//This source code is licensed as defined on the LICENSE file found in the root directory of this source tree.//

to

//This source code is licensed in accordance with the terms specified in the LICENSE file found in the root directory of this source tree.//

We accomplish this with a codemod:

  $ codemod -md xplat/osquery/oss --extensions cpp,h,in,py,sh,mm,ps1 "(.\s+)This source code is licensed as defined on the LICENSE file found in the(.*)root directory of this source tree\." "\1This source code is licensed in accordance with the terms specified in\2the LICENSE file found in the root directory of this source tree."

Reviewed By: fmanco

Differential Revision: D14131290

fbshipit-source-id: 52c90da342263e2a80f5a678ecd760c19cf7513e
2019-02-19 10:59:48 -08:00

70 lines
1.9 KiB
C++

/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed in accordance with the terms specified in
* the LICENSE file found in the root directory of this source tree.
*/
#include <chrono>
#include <osquery/dispatcher.h>
#include <osquery/flags.h>
#include <osquery/killswitch.h>
#include <osquery/killswitch/killswitch_refreshable_plugin.h>
namespace osquery {
FLAG(uint32,
killswitch_refresh_rate,
10,
"Refresh rate of killswitch in seconds");
namespace {
class KillswitchRefresher : public InternalRunnable {
public:
explicit KillswitchRefresher(std::chrono::seconds update_interval)
: InternalRunnable("KillswitchRefreshRunner"),
update_interval_(update_interval) {}
/// A simple wait/interruptible lock.
void start() override {
while (!interrupted()) {
pause(std::chrono::milliseconds(update_interval_));
osquery::Killswitch::get().refresh();
}
}
private:
const std::chrono::seconds update_interval_;
};
} // namespace
Status KillswitchRefreshablePlugin::setUp() {
if (FLAGS_killswitch_refresh_rate > 0) {
Dispatcher::addService(std::make_shared<KillswitchRefresher>(
std::chrono::seconds(FLAGS_killswitch_refresh_rate)));
}
return Status::success();
}
Status KillswitchRefreshablePlugin::call(const PluginRequest& request,
PluginResponse& response) {
auto action = request.find(Killswitch::action_);
if (action == request.end()) {
return Status::failure("Config plugins require an action");
}
if (action->second == Killswitch::refresh_) {
auto result = refresh();
if (result) {
return Status::success();
} else {
return Status::failure(result.getError().getMessage());
}
} else {
return KillswitchPlugin::call(request, response);
}
}
} // namespace osquery