提交 ea639585 编写于 作者: C cheng_jinsong

fix console service issue

Signed-off-by: Ncheng_jinsong <chengjinsong2@huawei.com>
上级 11a902ec
......@@ -309,11 +309,7 @@ static int InitServicePropertys(Service *service)
CreateServiceFile(service->fileCfg);
if ((service->attribute & SERVICE_ATTR_CONSOLE)) {
if (strcmp(service->name, "console") != 0 || !IsOnDemandService(service)) {
OpenConsole();
} else {
setsid();
}
OpenConsole();
}
PublishHoldFds(service);
......
......@@ -881,7 +881,9 @@ static void ProcessConsoleEvent(const WatcherHandle handler, int fd, uint32_t *e
INIT_LOGE("Process console event with invalid arguments");
return;
}
// Since we've got event from console device
// the fd related to '/dev/console' does not need anymore, close it.
close(fd);
if (strcmp(service->name, "console") != 0) {
INIT_LOGE("Process console event with invalid service %s, only console service should do this", service->name);
return;
......@@ -892,19 +894,14 @@ static void ProcessConsoleEvent(const WatcherHandle handler, int fd, uint32_t *e
unsigned int len = MAX_BUFFER_LEN;
if (SystemReadParam("const.debuggable", value, &len) != 0) {
INIT_LOGE("Failed to read parameter \'const.debuggable\', prevent console service starting");
CloseStdio();
return;
}
int isDebug = StringToInt(value, 0);
if (isDebug != 1) {
INIT_LOGI("Non-debuggable system, prevent console service starting");
CloseStdio();
return;
}
ioctl(fd, TIOCSCTTY, 0);
RedirectStdio(fd);
close(fd);
if (ServiceStart(service) != SERVICE_SUCCESS) {
INIT_LOGE("Start console service failed");
}
......@@ -942,11 +939,14 @@ int WatchConsoleDevice(Service *service)
if (errno == ENOENT) {
INIT_LOGW("/dev/console is not exist, wait for it...");
WaitForFile("/dev/console", WAIT_MAX_SECOND);
fd = open("/dev/console", O_RDWR);
if (fd < 0) {
INIT_LOGW("Failed to open /dev/console after try 1 time");
return -1;
}
} else {
INIT_LOGE("Failed to open /dev/console, err = %d", errno);
return -1;
}
fd = open("/dev/console", O_RDWR);
if (fd < 0) {
INIT_LOGW("Failed to open /dev/console after try 1 time, err = %d", errno);
return -1;
}
}
......@@ -1005,8 +1005,6 @@ void ParseAllServices(const cJSON *fileRoot)
if ((strcmp(service->name, "console") == 0) && IsOnDemandService(service)) {
if (WatchConsoleDevice(service) < 0) {
INIT_LOGW("Failed to watch \'/dev/console\' device");
INIT_LOGW("Remove service \' %s \' ondemand attribute", service->name);
UnMarkServiceAsOndemand(service);
}
}
#ifndef OHOS_LITE
......@@ -1178,4 +1176,4 @@ int GetKillServiceSig(const char *name)
return SIGTERM;
}
return SIGKILL;
}
\ No newline at end of file
}
......@@ -136,8 +136,7 @@ typedef struct {
static const DYNAMIC_DEVICE_NODE dynamicDevices[] = {
{ DEV_NODE_PATH_PREFIX"tty", S_IFCHR | DEFAULT_RW_MODE },
{ DEV_NODE_PATH_PREFIX"binder", S_IFCHR | DEFAULT_RW_MODE },
{ DEV_NODE_PATH_PREFIX"console", S_IFCHR | DEFAULT_RW_MODE },
{ DEV_NODE_PATH_PREFIX"tty", S_IFCHR | DEFAULT_RW_MODE }
{ DEV_NODE_PATH_PREFIX"console", S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP }
};
static void HandleRequiredDynamicDeviceNodes(const struct Uevent *uevent)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册