/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under both the Apache 2.0 license (found in the * LICENSE file in the root directory of this source tree) and the GPLv2 (found * in the COPYING file in the root directory of this source tree). * You may select, at your option, one of the above-listed licenses. */ #include #include #include #include #include #include #include #include #include #include #include namespace osquery { DECLARE_uint64(alarm_timeout); int platformGetUid() { return ::getuid(); } bool isLauncherProcessDead(PlatformProcess& launcher) { if (!launcher.isValid()) { return true; } return (::getppid() != launcher.nativeHandle()); } ModuleHandle platformModuleOpen(const std::string& path) { return ::dlopen(path.c_str(), RTLD_NOW | RTLD_LOCAL); } void* platformModuleGetSymbol(ModuleHandle module, const std::string& symbol) { return ::dlsym(module, symbol.c_str()); } std::string platformModuleGetError() { return ::dlerror(); } bool platformModuleClose(ModuleHandle module) { return (::dlclose(module) == 0); } void setToBackgroundPriority() { setpriority(PRIO_PGRP, 0, 10); } // Helper function to determine if thread is running with admin privilege. bool isUserAdmin() { return getuid() == 0; } int platformGetPid() { return static_cast(getpid()); } int platformGetTid() { return std::hash()(std::this_thread::get_id()); } void platformMainThreadExit(int excode) { exit(excode); } }