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