-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move SysctlUtil from eden to edencommon
Summary: To support better telemetry and logging in watchman we want to use Eden's components. Lets migrate and detangle the needed pieces. This change moves SysctlUtil from eden to edencommon. Reviewed By: genevievehelsel Differential Revision: D54471684 fbshipit-source-id: df6d0716dfe371d8c7fc1fe80079649b85b50e6b
- Loading branch information
1 parent
c0a65c5
commit cfe8628
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "eden/common/utils/SysctlUtil.h" | ||
|
||
#ifdef __APPLE__ | ||
|
||
#include <sys/sysctl.h> // @manual | ||
#include <sys/types.h> | ||
|
||
#include <folly/Exception.h> | ||
|
||
std::string getSysCtlByName(const char* name, size_t size) { | ||
if (size == 0) { | ||
return std::string{}; | ||
} | ||
std::string buffer(size, 0); | ||
size_t returnedSize = size - 1; | ||
auto ret = sysctlbyname(name, &buffer[0], &returnedSize, nullptr, 0); | ||
if (ret != 0) { | ||
folly::throwSystemError("failed to retrieve sysctl ", name); | ||
} | ||
buffer.resize(returnedSize); | ||
return buffer; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <string> | ||
|
||
#ifdef __APPLE__ | ||
// Fetches the value of a sysctl by name. | ||
// The result is assumed to be a string. | ||
std::string getSysCtlByName(const char* name, size_t size); | ||
#endif |