mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Fixed bad and wrong code #3553
This commit is contained in:
parent
1aa89ed63a
commit
2daab83a23
@ -1,7 +1,7 @@
|
||||
#include "hasLinuxCapability.h"
|
||||
|
||||
#if defined(__linux__)
|
||||
|
||||
#include "hasLinuxCapability.h"
|
||||
|
||||
#include <syscall.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/capability.h>
|
||||
@ -11,15 +11,13 @@
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int NETLINK_ERROR;
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
bool hasLinuxCapabilityImpl(decltype(CAP_NET_ADMIN) cap)
|
||||
static __user_cap_data_struct getCapabilities()
|
||||
{
|
||||
/// See man getcap.
|
||||
__user_cap_header_struct request{};
|
||||
@ -32,18 +30,15 @@ namespace
|
||||
if (0 != syscall(SYS_capget, &request, &response))
|
||||
throwFromErrno("Cannot do 'capget' syscall", ErrorCodes::NETLINK_ERROR);
|
||||
|
||||
if (!((1 << cap) & response.effective))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
bool hasLinuxCapability(decltype(CAP_NET_ADMIN) cap)
|
||||
bool hasLinuxCapability(int cap)
|
||||
{
|
||||
static bool res = hasLinuxCapabilityImpl(cap);
|
||||
return res;
|
||||
static __user_cap_data_struct capabilities = getCapabilities();
|
||||
return (1 << cap) & capabilities.effective;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -4,7 +4,10 @@
|
||||
|
||||
namespace DB
|
||||
{
|
||||
bool hasLinuxCapability(decltype(CAP_NET_ADMIN) cap);
|
||||
|
||||
/// Check that the current process has Linux capability. Examples: CAP_IPC_LOCK, CAP_NET_ADMIN.
|
||||
bool hasLinuxCapability(int cap);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user