未验证 提交 a68ecdc0 编写于 作者: O openharmony_ci 提交者: Gitee

!1084 optimize ueventd service

Merge pull request !1084 from cheng_jinsong/permanentUeventd
......@@ -4,6 +4,7 @@ system:x:1000:
radio:x:1001:
bluetooth:x:1002:
graphics:x:1003:
ueventd:x:1004:root
file_manager:x:1006:
log:x:1007:
user_data_rw:x:1008:
......
......@@ -4,6 +4,7 @@ system:x:1000:1000:::/bin/false
radio:x:1001:1001:::/bin/false
bluetooth:x:1002:1002:::/bin/false
graphics:x:1003:1003:::/bin/false
ueventd:x:1004:1004:::/bin/false
file_manager:x:1006:1006:::/bin/false
log:x:1007:1007:::/bin/false
user_data_rw:x:1008:1008:::/bin/false
......
......@@ -2,6 +2,8 @@
"services" : [{
"name" : "ueventd",
"path" : ["/system/bin/ueventd"],
"uid" : "ueventd",
"gid" : ["ueventd"],
"socket" : [{
"name" : "ueventd",
"family" : "AF_NETLINK",
......@@ -17,6 +19,7 @@
"SOCK_NONBLOCK"
]
}],
"caps" : ["DAC_OVERRIDE", "MKNOD", "CHOWN", "FOWNER"],
"critical" : [ 0, 15, 5],
"ondemand" : true,
"sandbox" : 0,
......
......@@ -89,11 +89,11 @@ static inline void AdjustDeviceNodePermissions(const char *deviceNode, uid_t uid
return;
}
if (chown(deviceNode, uid, gid) != 0) {
INIT_LOGW("Failed to change \" %s \" owner", deviceNode);
INIT_LOGW("Failed to change \" %s \" owner, errno %d", deviceNode, errno);
}
if (chmod(deviceNode, mode) != 0) {
INIT_LOGW("Failed to change \" %s \" mode", deviceNode);
INIT_LOGW("Failed to change \" %s \" mode, errno %d", deviceNode, errno);
}
}
......
......@@ -15,6 +15,7 @@
#include <limits.h>
#include <poll.h>
#include <stdbool.h>
#include "ueventd.h"
#include "ueventd_read_cfg.h"
#include "ueventd_socket.h"
......@@ -22,16 +23,17 @@
#include "init_log.h"
#include "init_socket.h"
static void PollUeventdSocketTimeout(int ueventSockFd)
static void PollUeventdSocketTimeout(int ueventSockFd, bool ondemand)
{
struct pollfd pfd = {};
pfd.events = POLLIN;
pfd.fd = ueventSockFd;
int timeout = ondemand ? UEVENTD_POLL_TIME : -1;
int ret = -1;
while (1) {
pfd.revents = 0;
ret = poll(&pfd, 1, UEVENTD_POLL_TIME);
ret = poll(&pfd, 1, timeout);
if (ret == 0) {
INIT_LOGI("poll ueventd socket timeout, ueventd exit");
return;
......@@ -54,10 +56,12 @@ int main(int argc, char **argv)
while (ueventdConfigs[i] != NULL) {
ParseUeventdConfigFile(ueventdConfigs[i++]);
}
bool ondemand = true;
int ueventSockFd = GetControlSocket("ueventd");
if (ueventSockFd < 0) {
INIT_LOGW("Failed to get uevent socket, try to create");
ueventSockFd = UeventdSocketInit();
ondemand = false;
}
if (ueventSockFd < 0) {
INIT_LOGE("Failed to create uevent socket!");
......@@ -76,6 +80,6 @@ int main(int argc, char **argv)
INIT_LOGI("ueventd start to process uevent message");
ProcessUevent(ueventSockFd, NULL, 0); // Not require boot devices
}
PollUeventdSocketTimeout(ueventSockFd);
PollUeventdSocketTimeout(ueventSockFd, ondemand);
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册