Skip to content

Commit

Permalink
Replace Status(0) calls with Status::success() to appease Lint (osque…
Browse files Browse the repository at this point in the history
…ry#5487)

Summary:
Pull Request resolved: osquery#5487

I got tired of Lint telling me to update the calls to the Status class, so I wrote some codemods to update the vast majority of them:

  $ cd ~/fbsource
  $ codemod -d xplat/osquery/oss/osquery --extensions cpp,h "return Status\(0\, \".*\"\);" "return Status::success();"

**Blindly accepted all changes**.

FWIW, I tried to do something similar with the failure return values, but the unit tests were failing afterward.

Reviewed By: guliashvili

Differential Revision: D14278739

fbshipit-source-id: b023f6e969be697eeb67d66ea3ad10d16c69ff0c
  • Loading branch information
Jesse Kornblum authored and facebook-github-bot committed Mar 1, 2019
1 parent e65551d commit ecbc65c
Show file tree
Hide file tree
Showing 80 changed files with 189 additions and 189 deletions.
4 changes: 2 additions & 2 deletions osquery/carver/carver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Status Carver::carve(const boost::filesystem::path& path) {
}
}

return Status(0, "Ok");
return Status::success();
};

Status Carver::postCarve(const boost::filesystem::path& path) {
Expand Down Expand Up @@ -305,7 +305,7 @@ Status Carver::postCarve(const boost::filesystem::path& path) {
}

updateCarveValue(carveGuid_, "status", "SUCCESS");
return Status(0, "Ok");
return Status::success();
};

Status carvePaths(const std::set<std::string>& paths) {
Expand Down
4 changes: 2 additions & 2 deletions osquery/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ Status Config::update(const ConfigMap& config) {
backupConfig(config);
}

return Status(0, "OK");
return Status::success();
}

void Config::purge() {
Expand Down Expand Up @@ -1010,7 +1010,7 @@ Status Config::genHash(std::string& hash) const {
new_hash.update(buffer.data(), buffer.size());
hash = new_hash.digest();

return Status(0, "OK");
return Status::success();
}

std::string Config::getHash(const std::string& source) const {
Expand Down
2 changes: 1 addition & 1 deletion osquery/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class Config : private boost::noncopyable {
* public:
* virtual Status genConfig(std::map<std::string, std::string>& config) {
* config["my_source"] = "{}";
* return Status(0, "OK");
* return Status::success();
* }
* };
*
Expand Down
6 changes: 3 additions & 3 deletions osquery/core/flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Status Flag::getDefaultValue(const std::string& name, std::string& value) {
}

value = info.default_value;
return Status(0, "OK");
return Status::success();
}

bool Flag::isDefault(const std::string& name) {
Expand Down Expand Up @@ -117,12 +117,12 @@ std::string Flag::getDescription(const std::string& name) {
Status Flag::updateValue(const std::string& name, const std::string& value) {
if (instance().flags_.count(name) > 0) {
flags::SetCommandLineOption(name.c_str(), value.c_str());
return Status(0, "OK");
return Status::success();
} else if (instance().aliases_.count(name) > 0) {
// Updating a flag by an alias name.
auto& real_name = instance().aliases_.at(name).description;
flags::SetCommandLineOption(real_name.c_str(), value.c_str());
return Status(0, "OK");
return Status::success();
} else if (name.find("custom_") == 0) {
instance().custom_[name] = value;
}
Expand Down
4 changes: 2 additions & 2 deletions osquery/core/plugins/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Plugin : private boost::noncopyable {
public:
/// The plugin may perform some initialization, not required.
virtual Status setUp() {
return Status(0, "Not used");
return Status::success();
}

/// The plugin may perform some tear down, release, not required.
Expand Down Expand Up @@ -97,7 +97,7 @@ class Plugin : private boost::noncopyable {
const PluginResponse& info) {
(void)name;
(void)info;
return Status(0, "Not used");
return Status::success();
}

/// Allow a specialized plugin type to act when an external plugin is removed.
Expand Down
2 changes: 1 addition & 1 deletion osquery/core/plugins/sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SQLPlugin : public Plugin {
* managed, tables are enumerated and attached during initialization.
*/
virtual Status attach(const std::string& /*name*/) {
return Status(0, "Not used");
return Status::success();
}

/// Tables may be detached by name.
Expand Down
6 changes: 3 additions & 3 deletions osquery/core/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Status Query::getPreviousQueryResults(QueryDataSet& results) const {
if (!status.ok()) {
return status;
}
return Status(0, "OK");
return Status::success();
}

std::vector<std::string> Query::getStoredQueryNames() {
Expand Down Expand Up @@ -162,7 +162,7 @@ Status Query::addNewResults(QueryData current_qd,
return status;
}
}
return Status(0, "OK");
return Status::success();
}


Expand Down Expand Up @@ -267,7 +267,7 @@ Status serializeEvent(const QueryLogItem& item,
}

doc.add("columns", columns_obj, obj);
return Status(0, "OK");
return Status::success();
}

Status serializeQueryLogItemAsEvents(const QueryLogItem& item, JSON& doc) {
Expand Down
8 changes: 4 additions & 4 deletions osquery/core/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Status getEphemeralUUID(std::string& ident) {
if (ident.size() == 0) {
ident = osquery::generateNewUUID();
}
return Status(0, "OK");
return Status::success();
}

Status getHostUUID(std::string& ident) {
Expand All @@ -260,7 +260,7 @@ Status getSpecifiedUUID(std::string& ident) {
return Status(1, "No specified identifier for host");
}
ident = FLAGS_specified_identifier;
return Status(0, "OK");
return Status::success();
}

std::string getHostIdentifier() {
Expand Down Expand Up @@ -297,7 +297,7 @@ Status checkStalePid(const std::string& content) {
try {
pid = boost::lexical_cast<int>(content);
} catch (const boost::bad_lexical_cast& /* e */) {
return Status(0, "Could not parse pid from existing pidfile");
return Status::success();
}

PlatformProcess target(pid);
Expand Down Expand Up @@ -330,7 +330,7 @@ Status checkStalePid(const std::string& content) {
VLOG(1) << "Found stale process for osqueryd (" << content << ")";
}

return Status(0, "OK");
return Status::success();
}

Status createPidFile() {
Expand Down
2 changes: 1 addition & 1 deletion osquery/core/tables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Status TablePlugin::call(const PluginRequest& request,
return Status(1, "Unknown table plugin action: " + action);
}

return Status(0, "OK");
return Status::success();
}

std::string TablePlugin::columnDefinition(bool is_extension) const {
Expand Down
2 changes: 1 addition & 1 deletion osquery/database/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Status DatabasePlugin::scan(const std::string& domain,
std::vector<std::string>& results,
const std::string& prefix,
size_t max) const {
return Status(0, "Not used");
return Status::success();
}

Status DatabasePlugin::call(const PluginRequest& request,
Expand Down
2 changes: 1 addition & 1 deletion osquery/database/plugins/ephemeral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Status EphemeralDatabasePlugin::putBatch(const std::string& domain,
setValue(domain, key, value);
}

return Status(0, "OK");
return Status::success();
}

void EphemeralDatabasePlugin::dumpDatabase() const {
Expand Down
8 changes: 4 additions & 4 deletions osquery/database/plugins/rocksdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ Status RocksDBDatabasePlugin::put(const std::string& domain,
Status RocksDBDatabasePlugin::putBatch(const std::string& domain,
const DatabaseStringValueList& data) {
if (read_only_) {
return Status(0, "Database in readonly mode");
return Status::success();
}

auto cfh = getHandleForColumnFamily(domain);
Expand Down Expand Up @@ -323,7 +323,7 @@ void RocksDBDatabasePlugin::dumpDatabase() const {}
Status RocksDBDatabasePlugin::remove(const std::string& domain,
const std::string& key) {
if (read_only_) {
return Status(0, "Database in readonly mode");
return Status::success();
}

auto cfh = getHandleForColumnFamily(domain);
Expand All @@ -345,7 +345,7 @@ Status RocksDBDatabasePlugin::removeRange(const std::string& domain,
const std::string& low,
const std::string& high) {
if (read_only_) {
return Status(0, "Database in readonly mode");
return Status::success();
}

auto cfh = getHandleForColumnFamily(domain);
Expand Down Expand Up @@ -397,6 +397,6 @@ Status RocksDBDatabasePlugin::scan(const std::string& domain,
}
}
delete it;
return Status(0, "OK");
return Status::success();
}
} // namespace osquery
10 changes: 5 additions & 5 deletions osquery/database/plugins/sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Status SQLiteDatabasePlugin::put(const std::string& domain,
Status SQLiteDatabasePlugin::putBatch(const std::string& domain,
const DatabaseStringValueList& data) {
if (read_only_) {
return Status(0, "Database in readonly mode");
return Status::success();
}

// Prepare the query, adding placeholders for all the rows we have in `data`
Expand Down Expand Up @@ -235,13 +235,13 @@ Status SQLiteDatabasePlugin::putBatch(const std::string& domain,
tryVacuum(db_);
}

return Status(0, "OK");
return Status::success();
}

Status SQLiteDatabasePlugin::remove(const std::string& domain,
const std::string& key) {
if (read_only_) {
return Status(0, "Database in readonly mode");
return Status::success();
}

sqlite3_stmt* stmt = nullptr;
Expand All @@ -267,7 +267,7 @@ Status SQLiteDatabasePlugin::removeRange(const std::string& domain,
const std::string& low,
const std::string& high) {
if (read_only_) {
return Status(0, "Database in readonly mode");
return Status::success();
}

sqlite3_stmt* stmt = nullptr;
Expand Down Expand Up @@ -310,6 +310,6 @@ Status SQLiteDatabasePlugin::scan(const std::string& domain,
results.push_back(std::move(r["key"]));
}

return Status(0, "OK");
return Status::success();
}
} // namespace osquery
2 changes: 1 addition & 1 deletion osquery/dispatcher/dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Status Dispatcher::addService(InternalRunnableRef service) {
self.service_threads_.push_back(std::move(thread));
self.services_.push_back(std::move(service));
}
return Status(0, "OK");
return Status::success();
}

void Dispatcher::removeService(const InternalRunnable* service) {
Expand Down
2 changes: 1 addition & 1 deletion osquery/dispatcher/distributed_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void DistributedRunner::start() {
Status startDistributed() {
if (!FLAGS_disable_distributed) {
Dispatcher::addService(std::make_shared<DistributedRunner>());
return Status(0, "OK");
return Status::success();
} else {
return Status(1, "Distributed query service not enabled.");
}
Expand Down
6 changes: 3 additions & 3 deletions osquery/distributed/distributed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Status DistributedPlugin::call(const PluginRequest& request,
std::string queries;
getQueries(queries);
response.push_back({{"results", queries}});
return Status(0, "OK");
return Status::success();
} else if (action == "writeResults") {
if (request.count("results") == 0) {
return Status(1, "Missing results field");
Expand Down Expand Up @@ -75,7 +75,7 @@ Status Distributed::pullUpdates() {
return acceptWork(response[0]["results"]);
}

return Status(0, "OK");
return Status::success();
}

size_t Distributed::getPendingQueryCount() {
Expand Down Expand Up @@ -135,7 +135,7 @@ Status Distributed::runQueries() {

Status Distributed::flushCompleted() {
if (getCompletedCount() == 0) {
return Status(0, "OK");
return Status::success();
}

auto distributed_plugin = RegistryFactory::get().getActive("distributed");
Expand Down
2 changes: 1 addition & 1 deletion osquery/events/benchmarks/events_benchmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class BenchmarkEventSubscriber
}

Status Callback(const ECRef& ec, const SCRef& sc) {
return Status(0, "OK");
return Status::success();
}

void benchmarkInit() {
Expand Down
2 changes: 1 addition & 1 deletion osquery/events/darwin/diskarbitration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void DiskArbitrationEventPublisher::restart() {
Status DiskArbitrationEventPublisher::run() {
restart();
CFRunLoopRun();
return Status(0, "OK");
return Status::success();
}

void DiskArbitrationEventPublisher::stop() {
Expand Down
2 changes: 1 addition & 1 deletion osquery/events/darwin/fsevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ Status FSEventsEventPublisher::run() {

// Start the run loop, it may be removed with a tearDown.
CFRunLoopRun();
return Status(0, "OK");
return Status::success();
}

void FSEventsEventPublisher::Callback(
Expand Down
2 changes: 1 addition & 1 deletion osquery/events/darwin/iokit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Status IOKitEventPublisher::run() {

// Start the run loop, it may be removed with a tearDown.
CFRunLoopRun();
return Status(0, "OK");
return Status::success();
}

bool IOKitEventPublisher::shouldFire(const IOKitSubscriptionContextRef& sc,
Expand Down
2 changes: 1 addition & 1 deletion osquery/events/darwin/scnetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,6 @@ Status SCNetworkEventPublisher::run() {

// Start the run loop, it may be removed with a tearDown.
CFRunLoopRun();
return Status(0, "OK");
return Status::success();
}
};
Loading

0 comments on commit ecbc65c

Please sign in to comment.