未验证 提交 8dbdb977 编写于 作者: 许云通 提交者: Gitee

[revert]

Signed-off-by: N许云通 <scorpion_xyt@outlook.com>
上级 f072744b
......@@ -17,7 +17,7 @@
#ifdef __cplusplus
extern "C" {
#endif
// void RegisterFdHoldWatcher(int sock);
void RegisterFdHoldWatcher(int sock);
#ifdef __cplusplus
}
#endif
......
......@@ -166,18 +166,18 @@ void ProcessFdHoldEvent(const WatcherHandle taskHandle, int fd, uint32_t *events
*events = Event_Read;
}
// void RegisterFdHoldWatcher(int sock)
// {
// if (sock < 0) {
// INIT_LOGE("Invalid fd holder socket");
// return;
// }
// WatcherHandle watcher = NULL;
// LE_WatchInfo info = {};
// info.fd = sock;
// info.flags = 0; // WATCHER_ONCE;
// info.events = Event_Read;
// info.processEvent = ProcessFdHoldEvent;
// LE_StartWatcher(LE_GetDefaultLoop(), &watcher, &info, NULL);
// }
void RegisterFdHoldWatcher(int sock)
{
if (sock < 0) {
INIT_LOGE("Invalid fd holder socket");
return;
}
WatcherHandle watcher = NULL;
LE_WatchInfo info = {};
info.fd = sock;
info.flags = 0; // WATCHER_ONCE;
info.events = Event_Read;
info.processEvent = ProcessFdHoldEvent;
LE_StartWatcher(LE_GetDefaultLoop(), &watcher, &info, NULL);
}
......@@ -46,50 +46,50 @@
#include "fd_holder_internal.h"
#include "bootstage.h"
// static int FdHolderSockInit(void)
// {
// int sock = -1;
// int on = 1;
// int fdHolderBufferSize = FD_HOLDER_BUFFER_SIZE; // 4KiB
// sock = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
// if (sock < 0) {
// INIT_LOGE("Failed to create fd holder socket, err = %d", errno);
// return -1;
// }
// setsockopt(sock, SOL_SOCKET, SO_RCVBUFFORCE, &fdHolderBufferSize, sizeof(fdHolderBufferSize));
// setsockopt(sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
// if (access(INIT_HOLDER_SOCKET_PATH, F_OK) == 0) {
// INIT_LOGI("%s exist, remove it", INIT_HOLDER_SOCKET_PATH);
// unlink(INIT_HOLDER_SOCKET_PATH);
// }
// struct sockaddr_un addr;
// addr.sun_family = AF_UNIX;
// if (strncpy_s(addr.sun_path, sizeof(addr.sun_path),
// INIT_HOLDER_SOCKET_PATH, strlen(INIT_HOLDER_SOCKET_PATH)) != 0) {
// INIT_LOGE("Failed to copy fd hoder socket path");
// close(sock);
// return -1;
// }
// socklen_t len = (socklen_t)(offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path) + 1);
// if (bind(sock, (struct sockaddr *)&addr, len) < 0) {
// INIT_LOGE("Failed to binder fd folder socket %d", errno);
// close(sock);
// return -1;
// }
// // Owned by root
// if (lchown(addr.sun_path, 0, 0)) {
// INIT_LOGW("Failed to change owner of fd holder socket, err = %d", errno);
// }
// mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
// if (fchmodat(AT_FDCWD, addr.sun_path, mode, AT_SYMLINK_NOFOLLOW)) {
// INIT_LOGW("Failed to change mode of fd holder socket, err = %d", errno);
// }
// INIT_LOGI("Init fd holder socket done");
// return sock;
// }
static int FdHolderSockInit(void)
{
int sock = -1;
int on = 1;
int fdHolderBufferSize = FD_HOLDER_BUFFER_SIZE; // 4KiB
sock = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
if (sock < 0) {
INIT_LOGE("Failed to create fd holder socket, err = %d", errno);
return -1;
}
setsockopt(sock, SOL_SOCKET, SO_RCVBUFFORCE, &fdHolderBufferSize, sizeof(fdHolderBufferSize));
setsockopt(sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
if (access(INIT_HOLDER_SOCKET_PATH, F_OK) == 0) {
INIT_LOGI("%s exist, remove it", INIT_HOLDER_SOCKET_PATH);
unlink(INIT_HOLDER_SOCKET_PATH);
}
struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
if (strncpy_s(addr.sun_path, sizeof(addr.sun_path),
INIT_HOLDER_SOCKET_PATH, strlen(INIT_HOLDER_SOCKET_PATH)) != 0) {
INIT_LOGE("Failed to copy fd hoder socket path");
close(sock);
return -1;
}
socklen_t len = (socklen_t)(offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path) + 1);
if (bind(sock, (struct sockaddr *)&addr, len) < 0) {
INIT_LOGE("Failed to binder fd folder socket %d", errno);
close(sock);
return -1;
}
// Owned by root
if (lchown(addr.sun_path, 0, 0)) {
INIT_LOGW("Failed to change owner of fd holder socket, err = %d", errno);
}
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
if (fchmodat(AT_FDCWD, addr.sun_path, mode, AT_SYMLINK_NOFOLLOW)) {
INIT_LOGW("Failed to change mode of fd holder socket, err = %d", errno);
}
INIT_LOGI("Init fd holder socket done");
return sock;
}
void SystemInit(void)
{
......@@ -101,10 +101,10 @@ void SystemInit(void)
// umask call always succeeds and return the previous mask value which is not needed here
(void)umask(DEFAULT_UMASK_INIT);
MakeDirRecursive("/dev/unix/socket", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
// int sock = FdHolderSockInit();
// if (sock >= 0) {
// RegisterFdHoldWatcher(sock);
// }
int sock = FdHolderSockInit();
if (sock >= 0) {
RegisterFdHoldWatcher(sock);
}
InitControlFd();
}
......
......@@ -117,16 +117,16 @@ static void TestProcessTimer(const TimerHandle taskHandle, void *context)
count++;
}
// HWTEST_F(InitUnitTest, TestFdHoldService, TestSize.Level1)
// {
// RegisterFdHoldWatcher(-1);
// TimerHandle timer = nullptr;
// int ret = LE_CreateTimer(LE_GetDefaultLoop(), &timer, TestProcessTimer, nullptr);
// EXPECT_EQ(ret, 0);
// ret = LE_StartTimer(LE_GetDefaultLoop(), timer, 500, 2);
// EXPECT_EQ(ret, 0);
// SystemRun();
// }
HWTEST_F(InitUnitTest, TestFdHoldService, TestSize.Level1)
{
RegisterFdHoldWatcher(-1);
TimerHandle timer = nullptr;
int ret = LE_CreateTimer(LE_GetDefaultLoop(), &timer, TestProcessTimer, nullptr);
EXPECT_EQ(ret, 0);
ret = LE_StartTimer(LE_GetDefaultLoop(), timer, 500, 2);
EXPECT_EQ(ret, 0);
SystemRun();
}
HWTEST_F(InitUnitTest, TestInitLog, TestSize.Level1)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册