2014-08-05 23:13:55 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
2014-10-27 16:34:13 +00:00
|
|
|
#include "osquery/flags.h"
|
2014-09-09 22:35:34 +00:00
|
|
|
|
2014-08-05 23:13:55 +00:00
|
|
|
#include <gflags/gflags.h>
|
|
|
|
#include <glog/logging.h>
|
|
|
|
|
2014-10-27 16:34:13 +00:00
|
|
|
#include "osquery/core.h"
|
2014-10-27 01:39:03 +00:00
|
|
|
#include "osquery/database.h"
|
2014-08-05 23:13:55 +00:00
|
|
|
#include "osquery/registry.h"
|
|
|
|
|
2014-08-15 07:25:30 +00:00
|
|
|
namespace osquery {
|
2014-08-05 23:13:55 +00:00
|
|
|
|
2014-09-02 00:13:04 +00:00
|
|
|
const std::string kDefaultLogDir = "/var/log/osquery/";
|
2014-10-27 16:34:13 +00:00
|
|
|
const std::string kDescription = "your operating system as a high-performance "
|
|
|
|
"relational database";
|
|
|
|
const std::string kEpilog = "osquery project page <http://osquery.io>.";
|
2014-09-02 00:13:04 +00:00
|
|
|
|
2014-10-27 16:34:13 +00:00
|
|
|
static const char* basename(const char* filename) {
|
|
|
|
const char* sep = strrchr(filename, '/');
|
|
|
|
return sep ? sep + 1 : filename;
|
2014-09-09 22:35:34 +00:00
|
|
|
}
|
|
|
|
|
2014-10-27 16:34:13 +00:00
|
|
|
void initOsquery(int argc, char *argv[]) {
|
|
|
|
if (argc > 1 && (std::string(argv[1]) == "--help" ||
|
|
|
|
std::string(argv[1]) == "-h")) {
|
|
|
|
// Parse help options before gflags. Only display osquery-related options.
|
|
|
|
fprintf(stdout, "osquery " VERSION ", %s\n", kDescription.c_str());
|
|
|
|
fprintf(stdout, "%s: [OPTION]...\n\n", basename(argv[0]));
|
|
|
|
fprintf(stdout, "The following options control the osquery "
|
|
|
|
"daemon and shell.\n\n");
|
|
|
|
|
|
|
|
auto flags = Flag::get().flags();
|
|
|
|
for (auto& flag : flags) {
|
|
|
|
fprintf(stdout, " --%s, --%s=VALUE\n %s (default: %s)\n",
|
|
|
|
flag.first.c_str(), flag.first.c_str(), flag.second.second.c_str(),
|
|
|
|
flag.second.first.c_str());
|
2014-09-09 22:35:34 +00:00
|
|
|
}
|
2014-10-27 16:34:13 +00:00
|
|
|
fprintf(stdout, "\n%s\n", kEpilog.c_str());
|
2014-09-09 22:35:34 +00:00
|
|
|
|
2014-10-27 16:34:13 +00:00
|
|
|
::exit(0);
|
2014-09-09 22:35:34 +00:00
|
|
|
}
|
|
|
|
|
2014-09-02 00:13:04 +00:00
|
|
|
FLAGS_alsologtostderr = true;
|
|
|
|
FLAGS_logbufsecs = 0; // flush the log buffer immediately
|
|
|
|
FLAGS_stop_logging_if_full_disk = true;
|
|
|
|
FLAGS_max_log_size = 1024; // max size for individual log file is 1GB
|
2014-09-25 17:17:45 +00:00
|
|
|
if (access(kDefaultLogDir.c_str(), W_OK) == 0) {
|
|
|
|
FLAGS_log_dir = kDefaultLogDir;
|
|
|
|
}
|
2014-10-27 01:39:03 +00:00
|
|
|
|
2014-09-09 23:10:48 +00:00
|
|
|
google::InitGoogleLogging(argv[0]);
|
2014-08-05 23:13:55 +00:00
|
|
|
osquery::InitRegistry::get().run();
|
2014-10-27 01:39:03 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
DBHandle::getInstance();
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
LOG(ERROR) << "osquery failed to start: " << e.what();
|
|
|
|
::exit(1);
|
|
|
|
}
|
2014-10-27 16:34:13 +00:00
|
|
|
|
|
|
|
// Let gflags parse the non-help options/flags.
|
|
|
|
google::ParseCommandLineNonHelpFlags(&argc, &argv, true);
|
2014-08-05 23:13:55 +00:00
|
|
|
}
|
2014-08-15 07:25:30 +00:00
|
|
|
}
|