Use base::Commandline instead of gflags (removes -fno-strict-aliasing).
Small CL that does a little refactoring of command lines to use
base::CommandLine. I also cleaned up buffet_client parsing args to better
use base::CommandLine rather than parsing argv.
BUG=chromium:356745
TEST=Built it
Change-Id: I2b5eb9ebc8b41e3df92ddbce9ad4fe97f51362c2
Reviewed-on: https://chromium-review.googlesource.com/193939
Reviewed-by: Chris Sosa <sosa@chromium.org>
Tested-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Chris Sosa <sosa@chromium.org>
diff --git a/buffet/main.cc b/buffet/main.cc
index 79843ab..37a9031 100644
--- a/buffet/main.cc
+++ b/buffet/main.cc
@@ -12,15 +12,23 @@
#include <base/message_loop/message_loop.h>
#include <base/strings/string_util.h>
#include <base/strings/stringprintf.h>
-#include <gflags/gflags.h>
+#include <sysexits.h>
#include "buffet/dbus_manager.h"
#include "buffet/manager.h"
-DEFINE_string(logsroot, "/var/log", "Root directory for buffet logs.");
-
namespace {
+static const char kLogRoot[] = "logroot";
+static const char kHelp[] = "help";
+static const char kDefaultLogRoot[] = "/var/log";
+
+// The help message shown if help flag is passed to the program.
+static const char kHelpMessage[] = "\n"
+ "Available Switches: \n"
+ " --logroot=/path/to/logroot\n"
+ " Specifies parent directory to put buffet logs in.\n";
+
// Returns |utime| as a string
std::string GetTimeAsString(time_t utime) {
struct tm tm;
@@ -40,10 +48,10 @@
}
}
-// Creates new log file based on timestamp in |logs_root|/buffet.
-std::string SetupLogFile(const std::string& logs_root) {
- const auto log_symlink = logs_root + "/buffet.log";
- const auto logs_dir = logs_root + "/buffet";
+// Creates new log file based on timestamp in |log_root|/buffet.
+std::string SetupLogFile(const std::string& log_root) {
+ const auto log_symlink = log_root + "/buffet.log";
+ const auto logs_dir = log_root + "/buffet";
const auto log_path =
base::StringPrintf("%s/buffet.%s",
logs_dir.c_str(),
@@ -54,8 +62,8 @@
}
// Sets up logging for buffet.
-void SetupLogging(const std::string& logs_root) {
- const auto log_file = SetupLogFile(logs_root);
+void SetupLogging(const std::string& log_root) {
+ const auto log_file = SetupLogFile(log_root);
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_ALL;
settings.log_file = log_file.c_str();
@@ -69,10 +77,19 @@
int main(int argc, char* argv[]) {
// Parse the args and check for extra args.
CommandLine::Init(argc, argv);
- google::ParseCommandLineFlags(&argc, &argv, true);
- CHECK_EQ(argc, 1) << "Unexpected arguments. Try --help";
+ CommandLine* cl = CommandLine::ForCurrentProcess();
- SetupLogging(FLAGS_logsroot);
+ if (cl->HasSwitch(kHelp)) {
+ LOG(INFO) << kHelpMessage;
+ return EX_USAGE;
+ }
+
+ std::string log_root = std::string(kDefaultLogRoot);
+ if (cl->HasSwitch(kLogRoot)) {
+ log_root = cl->GetSwitchValueASCII(kLogRoot);
+ }
+
+ SetupLogging(log_root);
base::AtExitManager at_exit_manager;
base::MessageLoopForIO message_loop;
@@ -87,5 +104,5 @@
}
dbus_manager.Finalize();
- return 0;
+ return EX_OK;
}