Skip to content

Commit

Permalink
Move SysctlUtil from eden to edencommon
Browse files Browse the repository at this point in the history
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
jdelliot authored and facebook-github-bot committed Mar 4, 2024
1 parent c0a65c5 commit cfe8628
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
30 changes: 30 additions & 0 deletions eden/common/utils/SysctlUtil.cpp
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
14 changes: 14 additions & 0 deletions eden/common/utils/SysctlUtil.h
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

0 comments on commit cfe8628

Please sign in to comment.