osquery-1/osquery/main/daemon.cpp

41 lines
1001 B
C++
Raw Normal View History

/*
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
2014-07-31 00:35:19 +00:00
#include <boost/thread.hpp>
#include <osquery/core.h>
#include "osquery/dispatcher/scheduler.h"
2014-07-31 00:35:19 +00:00
const std::string kWatcherWorkerName = "osqueryd: worker";
2014-08-30 11:06:21 +00:00
int main(int argc, char* argv[]) {
2015-03-03 23:03:14 +00:00
osquery::Initializer runner(argc, argv, osquery::OSQUERY_TOOL_DAEMON);
2014-07-31 00:35:19 +00:00
2015-03-03 23:03:14 +00:00
if (!runner.isWorker()) {
runner.initDaemon();
}
// When a watchdog is used, the current daemon will fork/exec into a worker.
// In either case the watcher may start optionally loaded extensions.
runner.initWorkerWatcher(kWatcherWorkerName);
2015-03-03 23:03:14 +00:00
// Start osquery work.
runner.start();
2014-07-31 00:35:19 +00:00
// Begin the schedule runloop.
osquery::startScheduler();
2014-07-31 00:35:19 +00:00
// Finally shutdown.
2015-03-03 23:03:14 +00:00
runner.shutdown();
2014-07-31 00:35:19 +00:00
return 0;
}