MCPcopy Create free account
hub / github.com/ByConity/ByConity / main

Method main

programs/keeper/Keeper.cpp:314–525  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312}
313
314int Keeper::main(const std::vector<std::string> & /*args*/)
315{
316 Poco::Logger * log = &logger();
317
318 UseSSL use_ssl;
319
320 MainThreadStatus::getInstance();
321
322#if !defined(NDEBUG) || !defined(__OPTIMIZE__)
323 LOG_WARNING(log, "Keeper was built in debug mode. It will work slowly.");
324#endif
325
326#if defined(SANITIZER)
327 LOG_WARNING(log, "Keeper was built with sanitizer. It will work slowly.");
328#endif
329
330 auto shared_context = Context::createShared();
331 global_context = Context::createGlobal(shared_context.get());
332
333 global_context->makeGlobalContext();
334 global_context->setApplicationType(Context::ApplicationType::KEEPER);
335
336 if (!config().has("keeper_server"))
337 throw Exception(ErrorCodes::NO_ELEMENTS_IN_CONFIG, "Keeper configuration (<keeper_server> section) not found in config");
338
339
340 std::string path;
341
342 if (config().has("keeper_server.storage_path"))
343 path = config().getString("keeper_server.storage_path");
344 else if (config().has("keeper_server.log_storage_path"))
345 path = config().getString("keeper_server.log_storage_path");
346 else if (config().has("keeper_server.snapshot_storage_path"))
347 path = config().getString("keeper_server.snapshot_storage_path");
348 else
349 path = std::filesystem::path{KEEPER_DEFAULT_PATH};
350
351
352 /// Check that the process user id matches the owner of the data.
353 const auto effective_user_id = geteuid();
354 struct stat statbuf;
355 if (stat(path.c_str(), &statbuf) == 0 && effective_user_id != statbuf.st_uid)
356 {
357 const auto effective_user = getUserName(effective_user_id);
358 const auto data_owner = getUserName(statbuf.st_uid);
359 std::string message = "Effective user of the process (" + effective_user +
360 ") does not match the owner of the data (" + data_owner + ").";
361 if (effective_user_id == 0)
362 {
363 message += " Run under 'sudo -u " + data_owner + "'.";
364 throw Exception(message, ErrorCodes::MISMATCHING_USERS_FOR_PROCESS_AND_DATA);
365 }
366 else
367 {
368 LOG_WARNING(log, message);
369 }
370 }
371

Callers

nothing calls this directly

Calls 15

loadFunction · 0.85
socketBindListenFunction · 0.85
makeGlobalContextMethod · 0.80
setApplicationTypeMethod · 0.80
setDisableCacheFlagMethod · 0.80
statClass · 0.70
getUserNameFunction · 0.70
waitServersToFinishFunction · 0.70

Tested by

no test coverage detected